Class RaftStorage.Builder

java.lang.Object
io.atomix.raft.storage.RaftStorage.Builder
All Implemented Interfaces:
Builder<RaftStorage>
Enclosing class:
RaftStorage

public static final class RaftStorage.Builder extends Object implements Builder<RaftStorage>
Builds a RaftStorage configuration.

The storage builder provides simplifies building more complex RaftStorage configurations. To create a storage builder, use the RaftStorage.builder() factory method. Set properties of the configured Storage object with the various with* methods. Once the storage has been configured, call build() to build the object.


 Storage storage = Storage.builder()
   .withDirectory(new File("logs"))
   .withPersistenceLevel(PersistenceLevel.DISK)
   .build();

 
  • Method Details

    • withPrefix

      public RaftStorage.Builder withPrefix(String prefix)
      Sets the storage prefix.
      Parameters:
      prefix - The storage prefix.
      Returns:
      The storage builder.
    • withDirectory

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

      The log will write segment files into the provided directory. If multiple RaftStorage objects are located on the same machine, they write logs to different directories.

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

      public RaftStorage.Builder 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 RaftStorage.Builder withFreeDiskSpace(long freeDiskSpace)
      Sets the percentage of free disk space that must be preserved before log compaction is forced.
      Parameters:
      freeDiskSpace - the free disk percentage
      Returns:
      the Raft log builder
    • withFlushExplicitly

      public RaftStorage.Builder withFlushExplicitly(boolean flushExplicitly)
      Sets whether to flush logs to disk to guarantee correctness. If true, followers will flush on every append, and the leader will flush on commit.
      Parameters:
      flushExplicitly - whether to flush buffers to disk
      Returns:
      the storage builder.
    • withSnapshotStore

      public RaftStorage.Builder withSnapshotStore(ReceivableSnapshotStore persistedSnapshotStore)
      Sets the snapshot store to use for remote snapshot installation.
      Parameters:
      persistedSnapshotStore - the snapshot store for this Raft
      Returns:
      the storage builder
    • withJournalIndexDensity

      public RaftStorage.Builder withJournalIndexDensity(int journalIndexDensity)
    • build

      public RaftStorage build()
      Builds the RaftStorage object.
      Specified by:
      build in interface Builder<RaftStorage>
      Returns:
      The built storage configuration.