Uploaded image for project: 'controller'
  1. controller
  2. CONTROLLER-2094

Do not use FileChannel.position() in FileChannelJournalSegmentReader

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: High High
    • 7.0.12, 8.0.5, 9.0.1
    • None
    • clustering

      FileChannelJournalSegmentReader is using FileChannel methods in rather sub-optimal ways, such as:

              long position = channel.position() + memory.position();
              channel.position(position);
              memory.clear();
              channel.read(memory);
              channel.position(position);
              memory.flip();
      

      While memory.position() is HeapByteBuffer's local field, not shared with anyone else, channel.position() is kernel-side status tied to the channel and hence shared between all users of that channel.

      That is problematic for three reasons:

      • each call to get or set the position ends up being a system call
      • every call needs to be made with FileChannel.positionLock held
      • it might be shared resource, hence we set it explicitly before each read – because it may have been set by a different reader, or the writer

      All of this dance is done because we do not take advantage of FileChannel API: it offers a read(ByteBuffer, long) method, where the second argument is the desired start position.

      Reorganize the code to use that method and maintain the position in a field (IF we really need that).

      This will cut down on system calls, as each read will be a single syscall, remove the locking overhead (except on Windows) and, in future, allow us to share a single FileChannel.

            rovarga Robert Varga
            rovarga Robert Varga
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: