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(io.micrometer.core.instrument.MeterRegistry meterRegistry)
  • 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
    • withFlusher

      public RaftLogBuilder withFlusher(RaftLogFlusher flusher)
      Sets the flushing strategy. See implementations of RaftLogFlusher for which to use. Each strategy provides different guarantees to allow for a trade-off between performance and safety.
      Parameters:
      flusher - the flushing strategy, defaults to RaftLogFlusher.DirectFlusher
      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
    • 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
    • withPartitionId

      public RaftLogBuilder withPartitionId(int partitionId)
      The ID of the partition on which this log resides.
      Parameters:
      partitionId - the log's partition ID
      Returns:
      this builder for chaining
    • withMetaStore

      public RaftLogBuilder withMetaStore(JournalMetaStore metaStore)
      Parameters:
      metaStore - A persisted JournalMetaStore that can store lastFlushedIndex.
      Returns:
      this builder for chaining
    • build

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