public static class RaftStorage.Builder extends Object implements io.atomix.utils.Builder<RaftStorage>
RaftStorage configuration.
The storage builder provides simplifies building more complex RaftStorage configurations. To
create a storage builder, use the RaftStorage.newBuilder() 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();
| Modifier and Type | Method and Description |
|---|---|
RaftStorage |
build()
Builds the
RaftStorage object. |
RaftStorage.Builder |
withDirectory(File directory)
Sets the log directory, returning the builder for method chaining.
|
RaftStorage.Builder |
withDirectory(String directory)
Sets the log directory, returning the builder for method chaining.
|
RaftStorage.Builder |
withDynamicCompaction()
Enables dynamic log compaction.
|
RaftStorage.Builder |
withDynamicCompaction(boolean dynamicCompaction)
Enables dynamic log compaction.
|
RaftStorage.Builder |
withFlushOnCommit()
Enables flushing buffers to disk when entries are committed to a segment, returning the builder
for method chaining.
|
RaftStorage.Builder |
withFlushOnCommit(boolean flushOnCommit)
Sets whether to flush buffers to disk when entries are committed to a segment, returning the builder
for method chaining.
|
RaftStorage.Builder |
withFreeDiskBuffer(double freeDiskBuffer)
Sets the percentage of free disk space that must be preserved before log compaction is forced.
|
RaftStorage.Builder |
withMaxEntriesPerSegment(int maxEntriesPerSegment)
Sets the maximum number of allows entries per segment, returning the builder for method chaining.
|
RaftStorage.Builder |
withMaxSegmentSize(int maxSegmentSize)
Sets the maximum segment size in bytes, returning the builder for method chaining.
|
RaftStorage.Builder |
withPrefix(String prefix)
Sets the storage prefix.
|
RaftStorage.Builder |
withRetainStaleSnapshots()
Enables retaining stale snapshots on disk, returning the builder for method chaining.
|
RaftStorage.Builder |
withRetainStaleSnapshots(boolean retainStaleSnapshots)
Sets whether to retain stale snapshots on disk, returning the builder for method chaining.
|
RaftStorage.Builder |
withSerializer(io.atomix.serializer.Serializer serializer)
Sets the storage serializer.
|
RaftStorage.Builder |
withStorageLevel(io.atomix.storage.StorageLevel storageLevel)
Sets the log storage level, returning the builder for method chaining.
|
public RaftStorage.Builder withPrefix(String prefix)
prefix - The storage prefix.public RaftStorage.Builder withStorageLevel(io.atomix.storage.StorageLevel storageLevel)
The storage level indicates how individual entries
should be persisted in the log.
storageLevel - The log storage level.public RaftStorage.Builder withDirectory(String directory)
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.
directory - The log directory.NullPointerException - If the directory is nullpublic RaftStorage.Builder withDirectory(File directory)
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.
directory - The log directory.NullPointerException - If the directory is nullpublic RaftStorage.Builder withSerializer(io.atomix.serializer.Serializer serializer)
serializer - The storage serializer.NullPointerException - If the serializer is nullpublic RaftStorage.Builder withMaxSegmentSize(int maxSegmentSize)
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.
maxSegmentSize - The maximum segment size in bytes.IllegalArgumentException - If the maxSegmentSize is not positivepublic RaftStorage.Builder withMaxEntriesPerSegment(int maxEntriesPerSegment)
The maximum entry count dictates when logs should roll over to new segments. As entries are written to a segment of the log, if the entry count in that segment meets the configured maximum entry count, the log will create a new segment and append new entries to that segment.
By default, the maximum entries per segment is 1024 * 1024.
maxEntriesPerSegment - The maximum number of entries allowed per segment.IllegalArgumentException - If the maxEntriesPerSegment not greater than the default max entries per
segmentpublic RaftStorage.Builder withDynamicCompaction()
When dynamic compaction is enabled, logs will be compacted only during periods of low load on the cluster or when the cluster is running out of disk space.
public RaftStorage.Builder withDynamicCompaction(boolean dynamicCompaction)
When dynamic compaction is enabled, logs will be compacted only during periods of low load on the cluster or when the cluster is running out of disk space.
dynamicCompaction - whether to enable dynamic compactionpublic RaftStorage.Builder withFreeDiskBuffer(double freeDiskBuffer)
freeDiskBuffer - the free disk percentagepublic RaftStorage.Builder withFlushOnCommit()
When flush-on-commit is enabled, log entry buffers will be automatically flushed to disk each time an entry is committed in a given segment.
public RaftStorage.Builder withFlushOnCommit(boolean flushOnCommit)
When flush-on-commit is enabled, log entry buffers will be automatically flushed to disk each time an entry is committed in a given segment.
flushOnCommit - Whether to flush buffers to disk when entries are committed to a segment.public RaftStorage.Builder withRetainStaleSnapshots()
As the system state progresses, periodic snapshots of the state machine's state are taken. Once a new snapshot of the state machine is taken, all preceding snapshots no longer contribute to the state of the system and can therefore be removed from disk. By default, snapshots will not be retained once a new snapshot is stored on disk. Enabling snapshot retention will ensure that all snapshots will be saved, e.g. for backup purposes.
public RaftStorage.Builder withRetainStaleSnapshots(boolean retainStaleSnapshots)
As the system state progresses, periodic snapshots of the state machine's state are taken. Once a new snapshot of the state machine is taken, all preceding snapshots no longer contribute to the state of the system and can therefore be removed from disk. By default, snapshots will not be retained once a new snapshot is stored on disk. Enabling snapshot retention will ensure that all snapshots will be saved, e.g. for backup purposes.
retainStaleSnapshots - Whether to retain stale snapshots on disk.public RaftStorage build()
RaftStorage object.build in interface io.atomix.utils.Builder<RaftStorage>Copyright © 2013–2017. All rights reserved.