private int updateOrWriteEntry(int foundRecordId,
                                 @NotNull K key,
                                 @Nullable V value) throws IOException {
    KnownSizeRecordWriter entryWriter = entryExternalizer.writerFor(key, value);
    int recordSize = entryWriter.recordSize();
    int maxPayloadSupported = keyValuesStorage.maxPayloadSupported();
    if (recordSize > maxPayloadSupported) {
      throw new IOException("[" + key + "].recordSize(=" + recordSize + ") > max supported payload size(=" + maxPayloadSupported + ")");
    }

    return keyValuesStorage.writeToRecord(
      foundRecordId,
      buffer -> {
        ByteBuffer toWrite;
        if (buffer.capacity() < recordSize) {
          toWrite = ByteBuffer.allocate(recordSize)
            .order(buffer.order());
        }
        else {
          toWrite = buffer;
        }
        toWrite.position(0)
          .limit(recordSize);

        entryWriter.write(toWrite);

        toWrite.position(recordSize)
          .limit(recordSize);
        return toWrite;
      },
      recordSize,
      /*leaveRedirect: */ false
    );
  }
private int updateOrWriteEntry(int foundRecordId,
                                 @NotNull K key,
                                 @Nullable V value)