Interface LogStorage


public interface LogStorage
Storage abstraction for the log stream API. The storage is expected to store the given blocks of data atomically (i.e. a block is fully written or not at all), in the order in which they were appended.

The main access pattern is via the LogStorageReader, and is expected to be sequential. The reader should support seek as efficiently as possible, but random access is not the common case.

The lifecycle of the storage is expected to be independent of the log stream, and the storage is simply passed along to the stream.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    An append listener can be added to an append call to be notified of different events that can occur during the append operation.
    static interface 
    Consumers of LogStorage can use this listener to get notified when new records are committed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Register a commit listener
    void
    append(long lowestPosition, long highestPosition, BufferWriter bufferWriter, LogStorage.AppendListener listener)
    Writes a block containing one or multiple log entries in the storage and returns the address at which the block has been written.
    default void
    append(long lowestPosition, long highestPosition, ByteBuffer blockBuffer, LogStorage.AppendListener listener)
    Writes a block containing one or multiple log entries in the storage and returns the address at which the block has been written.
    Creates a new reader initialized at the given address.
    void
    Remove a commit listener
  • Method Details

    • newReader

      LogStorageReader newReader()
      Creates a new reader initialized at the given address.
      Returns:
      a new stateful storage reader
    • append

      void append(long lowestPosition, long highestPosition, BufferWriter bufferWriter, LogStorage.AppendListener listener)
      Writes a block containing one or multiple log entries in the storage and returns the address at which the block has been written.

      Storage implementations must guarantee eventually atomicity. When this method completes, either all the bytes must be written or none at all.

      The caller of this method must guarantee that the provided block contains unfragmented log entries.

      Parameters:
      lowestPosition - the lowest record position of all records in the block buffer
      highestPosition - the highest record position of all records in the block buffer
      bufferWriter - the buffer containing a block of log entries to be written into storage
    • append

      default void append(long lowestPosition, long highestPosition, ByteBuffer blockBuffer, LogStorage.AppendListener listener)
      Writes a block containing one or multiple log entries in the storage and returns the address at which the block has been written.

      Storage implementations must guarantee eventually atomicity. When this method completes, either all the bytes must be written or none at all.

      The caller of this method must guarantee that the provided block contains unfragmented log entries.

      Parameters:
      lowestPosition - the lowest record position of all records in the block buffer
      highestPosition - the highest record position of all records in the block buffer
      blockBuffer - the buffer containing a block of log entries to be written into storage
    • addCommitListener

      void addCommitListener(LogStorage.CommitListener listener)
      Register a commit listener
      Parameters:
      listener - the listener which will be notified when a new record is committed.
    • removeCommitListener

      void removeCommitListener(LogStorage.CommitListener listener)
      Remove a commit listener
      Parameters:
      listener - the listener to remove