Clean up initial FileChannel writer reset's read
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / FileChannelJournalSegmentWriter.java
index 025e1a841b1fe7bd3ee211b0adbc73f43b3801bd..d40d42ade50b2445fd21f39e283432163f745f8c 100644 (file)
@@ -77,18 +77,14 @@ class FileChannelJournalSegmentWriter<E> implements JournalWriter<E> {
     // Clear the buffer indexes.
     try {
       channel.position(JournalSegmentDescriptor.BYTES);
-      memory.clear().flip();
 
       // Record the current buffer position.
       long position = channel.position();
 
-      // Read more bytes from the segment if necessary.
-      if (memory.remaining() < maxEntrySize) {
-        memory.clear();
-        channel.read(memory);
-        channel.position(position);
-        memory.flip();
-      }
+      // Clear memory buffer and read fist chunk
+      memory.clear();
+      channel.read(memory, position);
+      memory.flip();
 
       // Read the entry length.
       memory.mark();