Class RaftStorage
RaftLog factory.
This class provides a factory for RaftLog objects. Storage objects are
immutable and can be created only via the RaftStorage.Builder. To create a new
Storage.Builder, use the static builder() factory method:
Storage storage = Storage.builder()
.withDirectory(new File("logs"))
.withStorageLevel(StorageLevel.DISK)
.build();
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic RaftStorage.Builderbuilder()Returns a new storage builder.Returns the storage directory.Returns thePersistedSnapshotStore.booleanAttempts to acquire a lock on the storage directory.openLog(MetaStore metaStore, ThreadContextFactory threadFactory) Opens a newRaftLog, recovering the log from disk if it exists.Opens a newMetaStore, recovering metadata from disk if it exists.intThe ID of the partition associated with this storage.prefix()Returns the storage filename prefix.toString()
-
Method Details
-
builder
Returns a new storage builder.- Returns:
- A new storage builder.
-
prefix
Returns the storage filename prefix.- Returns:
- The storage filename prefix.
-
lock
Attempts to acquire a lock on the storage directory.- Parameters:
id- the ID with which to lock the directory- Returns:
- indicates whether the lock was successfully acquired
-
openMetaStore
Opens a newMetaStore, recovering metadata from disk if it exists.The meta store will be loaded from disk, or if missing, a new meta store will be created.
- Returns:
- The metastore.
-
getPersistedSnapshotStore
Returns thePersistedSnapshotStore.- Returns:
- The snapshot store.
-
openLog
Opens a newRaftLog, recovering the log from disk if it exists.When a log is opened, the log will attempt to load segments from the storage
directory()according to the provided logname. If segments for the given log name are present on disk, segments will be loaded and indexes will be rebuilt from disk. If no segments are found, an empty log will be created.When log files are loaded from disk, the file names are expected to be based on the provided log
name.- Returns:
- The opened log.
-
toString
-
directory
Returns the storage directory.The storage directory is the directory to which all
RaftLogs write files. Segment files for multiple logs may be stored in the storage directory, and files for each log instance will be identified by thenameprovided when the log is.invalid reference
opened- Returns:
- The storage directory.
-
partitionId
public int partitionId()The ID of the partition associated with this storage.
-