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

invalid reference
#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
    • withFlusherFactory

      public RaftStorage.Builder withFlusherFactory(RaftLogFlusher.Factory flusherFactory)
      Sets the RaftLogFlusher.Factory to create a new flushing strategy for the RaftLog when
      invalid reference
      #openLog(MetaStore, ThreadContext)
      is called.
      Parameters:
      flusherFactory - factory to create the flushing strategy for the RaftLog
      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)
    • withPreallocateSegmentFiles

      public RaftStorage.Builder 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 RaftStorage.Builder withPartitionId(int partitionId)
      The ID of the partition on which this storage resides.
      Parameters:
      partitionId - the storage's partition ID
      Returns:
      this builder for chaining
    • build

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