public static class Storage.Builder extends Object implements Builder<Storage>
Storage configuration.
The storage builder provides simplifies building more complex Storage configurations. To
create a storage builder, use the Storage.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();
| Modifier and Type | Method and Description |
|---|---|
Storage |
build()
Builds the
Storage object. |
Storage.Builder |
withCompactionThreads(int compactionThreads)
Sets the number of log compaction threads, returning the builder for method chaining.
|
Storage.Builder |
withCompactionThreshold(double threshold)
Sets the percentage of entries in the segment that must be released before a segment can be compacted,
returning the builder for method chaining.
|
Storage.Builder |
withDirectory(File directory)
Sets the log directory, returning the builder for method chaining.
|
Storage.Builder |
withDirectory(String directory)
Sets the log directory, returning the builder for method chaining.
|
Storage.Builder |
withEntryBufferSize(int entryBufferSize)
Sets the entry buffer size.
|
Storage.Builder |
withFlushOnCommit()
Enables flushing buffers to disk when entries are committed to a segment, returning the builder
for method chaining.
|
Storage.Builder |
withFlushOnCommit(boolean flushOnCommit)
Sets whether to flush buffers to disk when entries are committed to a segment, returning the builder
for method chaining.
|
Storage.Builder |
withMajorCompactionInterval(Duration interval)
Sets the major compaction interval, returning the builder for method chaining.
|
Storage.Builder |
withMaxEntriesPerSegment(int maxEntriesPerSegment)
Sets the maximum number of allows entries per segment, returning the builder for method chaining.
|
Storage.Builder |
withMaxSegmentSize(int maxSegmentSize)
Sets the maximum segment size in bytes, returning the builder for method chaining.
|
Storage.Builder |
withMinorCompactionInterval(Duration interval)
Sets the minor compaction interval, returning the builder for method chaining.
|
Storage.Builder |
withRetainStaleSnapshots()
Enables retaining stale snapshots on disk, returning the builder for method chaining.
|
Storage.Builder |
withRetainStaleSnapshots(boolean retainStaleSnapshots)
Sets whether to retain stale snapshots on disk, returning the builder for method chaining.
|
Storage.Builder |
withStorageLevel(StorageLevel storageLevel)
Sets the log storage level, returning the builder for method chaining.
|
public Storage.Builder withStorageLevel(StorageLevel storageLevel)
The storage level indicates how individual entries
should be persisted in the log.
storageLevel - The log storage level.public Storage.Builder withDirectory(String directory)
The log will write segment files into the provided directory. If multiple Storage objects are located
on the same machine, they write logs to different directories.
directory - The log directory.NullPointerException - If the directory is nullpublic Storage.Builder withDirectory(File directory)
The log will write segment files into the provided directory. If multiple Storage objects are located
on the same machine, they write logs to different directories.
directory - The log directory.NullPointerException - If the directory is nullpublic Storage.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 Storage.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 Storage.Builder withEntryBufferSize(int entryBufferSize)
The entry buffer size dictates the number of entries to hold in memory at the tail of the log. Increasing the buffer size increases the number of entries that will be held in memory and thus implies greater memory consumption, but server performance may be improved due to reduced disk access.
entryBufferSize - The entry buffer size.IllegalArgumentException - if the buffer size is not positivepublic Storage.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 Storage.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 Storage.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 Storage.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 Storage.Builder withCompactionThreads(int compactionThreads)
The compaction thread count dictates the parallelism with which the log
Compactor can rewrite segments of the log. By default,
the log uses Runtime.getRuntime().availableProcessors() / 2 compaction threads.
compactionThreads - The number of log compaction threads.IllegalArgumentException - if compactionThreads is not positivepublic Storage.Builder withMinorCompactionInterval(Duration interval)
The minor compaction interval dictates the interval at which the
MinorCompactionManager should evaluate Segments
in the log for minor compaction. It is recommended that the minor compaction interval be at least an order
of magnitude smaller than the major compaction interval.
interval - The minor compaction interval.NullPointerException - if the interval is nullMinorCompactionManager,
MinorCompactionTaskpublic Storage.Builder withMajorCompactionInterval(Duration interval)
The major compaction interval dictates the interval at which the
MajorCompactionManager should evaluate Segments
in the log for major compaction. Because of the performance costs of major compaction, it is recommended that
the major compaction interval be at least an order of magnitude greater than the minor compaction interval.
interval - The major compaction interval.NullPointerException - if the interval is nullMajorCompactionManager,
MajorCompactionTaskpublic Storage.Builder withCompactionThreshold(double threshold)
The compaction threshold is used during minor compaction
to determine the set of segments to compact. By default, the compaction threshold is 0.5. Increasing the
compaction threshold will increase the number of entries that
must be released from the segment before compaction and thus decrease the likelihood that a segment will be compacted.
Conversely, decreasing the compaction threshold will increase the frequency of compaction at the cost of unnecessary
I/O.
threshold - The segment compact threshold.IllegalArgumentException - if the threashold is not positiveMinorCompactionManagerCopyright © 2013–2016. All rights reserved.