Class RaftStorage.Builder
- All Implemented Interfaces:
Builder<RaftStorage>
- Enclosing class:
- RaftStorage
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 Summary
Modifier and TypeMethodDescriptionbuild()Builds theRaftStorageobject.withDirectory(File directory) Sets the log directory, returning the builder for method chaining.withFlushExplicitly(boolean flushExplicitly) Sets whether to flush logs to disk to guarantee correctness.withFreeDiskSpace(long freeDiskSpace) Sets the percentage of free disk space that must be preserved before log compaction is forced.withJournalIndexDensity(int journalIndexDensity) withMaxSegmentSize(int maxSegmentSize) Sets the maximum segment size in bytes, returning the builder for method chaining.withPrefix(String prefix) Sets the storage prefix.withSnapshotStore(ReceivableSnapshotStore persistedSnapshotStore) Sets the snapshot store to use for remote snapshot installation.
-
Method Details
-
withPrefix
Sets the storage prefix.- Parameters:
prefix- The storage prefix.- Returns:
- The storage builder.
-
withDirectory
Sets the log directory, returning the builder for method chaining.The log will write segment files into the provided directory. If multiple
RaftStorageobjects are located on the same machine, they write logs to different directories.- Parameters:
directory- The log directory.- Returns:
- The storage builder.
- Throws:
NullPointerException- If thedirectoryisnull
-
withMaxSegmentSize
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 themaxSegmentSizeis not positive
-
withFreeDiskSpace
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
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
Sets the snapshot store to use for remote snapshot installation.- Parameters:
persistedSnapshotStore- the snapshot store for this Raft- Returns:
- the storage builder
-
withJournalIndexDensity
-
build
Builds theRaftStorageobject.- Specified by:
buildin interfaceBuilder<RaftStorage>- Returns:
- The built storage configuration.
-