Reduce position changes during read 68/110568/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Mar 2024 14:29:56 +0000 (15:29 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 11 Mar 2024 12:51:11 +0000 (12:51 +0000)
Rather than using a read() which updates the position, requiring us to
set the position again, set it only once and use read with offset --
eliminating one syscall.

JIRA: CONTROLLER-2095
Change-Id: I478ba1cbb1f5737a751b43cb6ed0d018e49e6485
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/FileChannelJournalSegmentWriter.java

index d40d42ade50b2445fd21f39e283432163f745f8c..62e0002a38b7321019bbb77c1842e7420feae779 100644 (file)
@@ -118,10 +118,9 @@ class FileChannelJournalSegmentWriter<E> implements JournalWriter<E> {
 
         // Read more bytes from the segment if necessary.
         if (memory.remaining() < maxEntrySize) {
-          channel.position(position);
           memory.clear();
-          channel.read(memory);
           channel.position(position);
+          channel.read(memory, position);
           memory.flip();
         }