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.withFlusherFactory(RaftLogFlusher.Factory flusherFactory) Sets theRaftLogFlusher.Factoryto create a new flushing strategy for theRaftLogwhen#openLog(MetaStore, ThreadContext)is called.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.withPartitionId(int partitionId) The ID of the partition on which this storage resides.withPreallocateSegmentFiles(boolean preallocateSegmentFiles) Sets whether segment files are pre-allocated at creation.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
-
withFlusherFactory
Sets theRaftLogFlusher.Factoryto create a new flushing strategy for theRaftLogwhen#openLog(MetaStore, ThreadContext)is called.- Parameters:
flusherFactory- factory to create the flushing strategy for theRaftLog- 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
-
withPreallocateSegmentFiles
Sets whether segment files are pre-allocated at creation. If true, segment files are pre-allocated to the maximum segment size (seewithMaxSegmentSize(int)}) at creation before any writes happen.- Parameters:
preallocateSegmentFiles- true to preallocate files, false otherwise- Returns:
- this builder for chaining
-
withPartitionId
The ID of the partition on which this storage resides.- Parameters:
partitionId- the storage's partition ID- Returns:
- this builder for chaining
-
build
Builds theRaftStorageobject.- Specified by:
buildin interfaceBuilder<RaftStorage>- Returns:
- The built storage configuration.
-