private int appendToEntry(int foundRecordId,
                            @NotNull K key,
                            @NotNull KnownSizeRecordWriter valueAppender) throws IOException {
    int valueAdditionalSize = valueAppender.recordSize();
    int maxPayloadSupported = keyValuesStorage.maxPayloadSupported();
    if (valueAdditionalSize > maxPayloadSupported) {
      throw new IOException(
        "[" + key + "].recordSize(=" + valueAdditionalSize + ") > max supported payload size(=" + maxPayloadSupported + ")");
    }

    if (foundRecordId == DurableIntToMultiIntMap.NO_VALUE) {
      KnownSizeRecordWriter headerAndKeyWriter = entryExternalizer.writerForEntryHeader(key);
      int headerAndKeySize = headerAndKeyWriter.recordSize();
      int totalRecordSize = headerAndKeySize + valueAdditionalSize;
      return keyValuesStorage.writeToRecord(
        foundRecordId,
        buffer -> {
          buffer.position(0).limit(headerAndKeySize);

          headerAndKeyWriter.write(buffer);

          buffer.position(headerAndKeySize).limit(totalRecordSize);

          valueAppender.write(buffer);

          buffer.position(totalRecordSize).limit(totalRecordSize);
          return buffer;
        },
        /*expectedRecordSizeHint: */ totalRecordSize
      );
    }
    else {
      return keyValuesStorage.writeToRecord(
        foundRecordId,
        buffer -> {
          ByteBuffer toWrite;
          int currentRecordSize = buffer.limit();
          int newRecordSize = currentRecordSize + valueAdditionalSize;
          if (newRecordSize > buffer.capacity()) {
            toWrite = ByteBuffer.allocate(newRecordSize)
              .order(buffer.order());
            toWrite.put(buffer);
          }
          else {
            toWrite = buffer;
          }
          toWrite.position(currentRecordSize)
            .limit(newRecordSize);

          valueAppender.write(toWrite);

          toWrite.position(newRecordSize)
            .limit(newRecordSize);
          return toWrite;
        },
        /*expectedRecordSizeHint: */ -1,
        /*leaveRedirect: */ false
      );
    }
  }
private int appendToEntry(int foundRecordId,
                            @NotNull K key,
                            @NotNull KnownSizeRecordWriter valueAppender)