Class AtomixLogStorageReader

java.lang.Object
io.camunda.zeebe.logstreams.storage.atomix.AtomixLogStorageReader
All Implemented Interfaces:
LogStorageReader, Closeable, AutoCloseable, Iterator<org.agrona.DirectBuffer>

public final class AtomixLogStorageReader extends Object implements LogStorageReader
Implements 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 Details

    • AtomixLogStorageReader

      public AtomixLogStorageReader(RaftLogReader reader)
  • Method Details

    • seek

      public void seek(long position)
      Description copied from interface: LogStorageReader
      Positions the reader such that the next call to Iterator.next() would return a block which contains a LoggedEvent with LoggedEvent.getPosition() equal to the given position, or the highest one which is less than the given position.

      If the position is negative, it should seek to the first position.

      If the position is greater than the greatest position stored, it should seek to the last block, such that Iterator.next() would return that block.

      Specified by:
      seek in interface LogStorageReader
      Parameters:
      position - the position to seek to
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface LogStorageReader
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<org.agrona.DirectBuffer>
    • next

      public org.agrona.DirectBuffer next()
      Specified by:
      next in interface Iterator<org.agrona.DirectBuffer>