Class RaftLogBuilder

java.lang.Object
io.atomix.raft.storage.log.RaftLogBuilder
All Implemented Interfaces:
Builder<RaftLog>

public class RaftLogBuilder extends Object implements Builder<RaftLog>
  • Constructor Details

    • RaftLogBuilder

      protected RaftLogBuilder()
  • Method Details

    • withName

      public RaftLogBuilder withName(String name)
      Sets the storage name.
      Parameters:
      name - The storage name.
      Returns:
      The storage builder.
    • withDirectory

      public RaftLogBuilder withDirectory(File directory)
      Sets the log directory, returning the builder for method chaining.

      The log will write segment files into the provided directory.

      Parameters:
      directory - The log directory.
      Returns:
      The storage builder.
      Throws:
      NullPointerException - If the directory is null
    • withMaxSegmentSize

      public RaftLogBuilder withMaxSegmentSize(int maxSegmentSize)
      Sets the maximum segment size in bytes, returning the builder for method chaining.

      The maximum segment size dictates when logs should roll over to new segments. As entries are written to a segment of the log, once the size of the segment surpasses the configured maximum segment size, the log will create a new segment and append new entries to that segment.

      By default, the maximum segment size is 1024 * 1024 * 32.

      Parameters:
      maxSegmentSize - The maximum segment size in bytes.
      Returns:
      The storage builder.
      Throws:
      IllegalArgumentException - If the maxSegmentSize is not positive
    • withFreeDiskSpace

      public RaftLogBuilder withFreeDiskSpace(long freeDiskSpace)
      Sets the minimum free disk space to leave when allocating a new segment
      Parameters:
      freeDiskSpace - free disk space in bytes
      Returns:
      the storage builder
      Throws:
      IllegalArgumentException - if the freeDiskSpace is not positive
    • withFlushExplicitly

      public RaftLogBuilder withFlushExplicitly(boolean flushExplicitly)
      Sets whether or not to flush buffered I/O explicitly at various points, returning the builder for chaining.

      Enabling this ensures that entries are flushed on followers before acknowledging a write, and are flushed on the leader before marking an entry as committed. This guarantees the correctness of various Raft properties.

      Parameters:
      flushExplicitly - whether to flush explicitly or not
      Returns:
      this builder for chaining
    • withJournalIndexDensity

      public RaftLogBuilder withJournalIndexDensity(int journalIndexDensity)
      Sets the index density of the journal.

      When journalIndexDensity is set to n, every n'th record is indexed. So higher this value, longer a seek operation takes. Lower this value more memory is required to store the index mappings.

      Parameters:
      journalIndexDensity - the journal index density
      Returns:
      this builder for chaining
    • withLastWrittenIndex

      public RaftLogBuilder withLastWrittenIndex(long lastWrittenIndex)
    • withPreallocateSegmentFiles

      public RaftLogBuilder withPreallocateSegmentFiles(boolean preallocateSegmentFiles)
      Sets whether segment files are pre-allocated at creation. If true, segment files are pre-allocated to the maximum segment size (see withMaxSegmentSize(int)}) at creation before any writes happen.
      Parameters:
      preallocateSegmentFiles - true to preallocate files, false otherwise
      Returns:
      this builder for chaining
    • build

      public RaftLog build()
      Specified by:
      build in interface Builder<RaftLog>