Class AtomixLogStorageReader
- All Implemented Interfaces:
LogStorageReader,Closeable,AutoCloseable,Iterator<org.agrona.DirectBuffer>
LogStorageReader over a RaftLogReader. Each ApplicationEntry
is considered a block (as per the log storage definition).
The implementation does look-ahead by one entry. This is necessary because we usually want to
seek to the entry which contains the given position, and in order to know that it does we need to
read it, and only then return it via the next next() call. It is also safe as we read
only committed entries, which may be compacted but remain valid.
Note that due to the look-ahead, calling hasNext() may result in doing some I/O and
mutating the state of the reader.
The reader currently simply returns the block as is without copying it - this is safe at the
moment because the serialization in the underlying RaftLog
already copies the data from disk. When switching to zero-copy, however, because of the
look-ahead, this reader will have to copy the block. At that point, we may want to look into
doing more than a single-step look-ahead (either here or in the LogStreamReader).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanhasNext()org.agrona.DirectBuffernext()voidseek(long position) Positions the reader such that the next call toIterator.next()would return a block which contains aLoggedEventwithLoggedEvent.getPosition()equal to the givenposition, or the highest one which is less than the givenposition.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
AtomixLogStorageReader
-
-
Method Details
-
seek
public void seek(long position) Description copied from interface:LogStorageReaderPositions the reader such that the next call toIterator.next()would return a block which contains aLoggedEventwithLoggedEvent.getPosition()equal to the givenposition, or the highest one which is less than the givenposition.If the
positionis negative, it should seek to the first position.If the
positionis greater than the greatest position stored, it should seek to the last block, such thatIterator.next()would return that block.- Specified by:
seekin interfaceLogStorageReader- Parameters:
position- the position to seek to
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceLogStorageReader
-
hasNext
public boolean hasNext() -
next
public org.agrona.DirectBuffer next()
-