The code here bears marks of 'copy, paste and cudgel to compliance'
programming and is strikingly similar to what MappedJournalSegmentWriter
does -- except it needs to deal with reading as well.
This patch takes the first step towards sanity by eliminating a useless
if() and uses FileChannel.read(ByteBuffer, long) to reduce position
adjustments.
JIRA: CONTROLLER-2095
Change-Id: I528cb14608402a406e20d168a7e8520c9eb66edf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
// 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();