Class RaftStorage

java.lang.Object
io.atomix.raft.storage.RaftStorage

public final class RaftStorage extends Object
Immutable log configuration and 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

invalid reference
#builder()
factory method:

 Storage storage = Storage.builder()
   .withDirectory(new File("logs"))
   .withStorageLevel(StorageLevel.DISK)
   .build();

 
See Also:
  • Method Details

    • builder

      public static RaftStorage.Builder builder(io.micrometer.core.instrument.MeterRegistry meterRegistry)
      Returns a new storage builder.
      Returns:
      A new storage builder.
    • prefix

      public String prefix()
      Returns the storage filename prefix.
      Returns:
      The storage filename prefix.
    • lock

      public boolean lock(String id)
      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

      public MetaStore openMetaStore()
      Opens a new MetaStore, 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

      public ReceivableSnapshotStore getPersistedSnapshotStore()
      Returns:
      The snapshot store.
    • openLog

      public RaftLog openLog(MetaStore metaStore, ThreadContextFactory threadFactory)
      Opens a new RaftLog, 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 log name. 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

      public String toString()
      Overrides:
      toString in class Object
    • directory

      public File 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 the name provided when the log is

      invalid reference
      opened
      .
      Returns:
      The storage directory.
    • partitionId

      public int partitionId()
      The ID of the partition associated with this storage.