public class SnapshotStore extends Object implements AutoCloseable
RaftStorage module.
The server snapshot store is responsible for persisting periodic state machine snapshots according
to the configured storage level. Each server with a snapshottable state machine
persists the state machine state to allow commands to be removed from disk.
When a snapshot store is created, the store will load any
existing snapshots from disk and make them available for reading. Only snapshots that have been
written and completed will be read from disk. Incomplete snapshots are
automatically deleted from disk when the snapshot store is opened.
SnapshotStore snapshots = storage.openSnapshotStore("test");
Snapshot snapshot = snapshots.snapshot(1);
To create a new Snapshot, use the newSnapshot(ServiceId, String, long, WallClockTimestamp) method. Each snapshot must
be created with a unique index which represents the index of the server state machine at
the point at which the snapshot was taken. Snapshot indices are used to sort snapshots loaded from
disk and apply them at the correct point in the state machine.
Snapshot snapshot = snapshots.create(10);
try (SnapshotWriter writer = snapshot.writer()) {
...
}
snapshot.complete();
Snapshots don't necessarily represent the beginning of the log. Typical Raft implementations take a
snapshot of the state machine state and then clear their logs up to that point. However, in Raft
a snapshot may actually only represent a subset of the state machine's state.| Constructor and Description |
|---|
SnapshotStore(RaftStorage storage) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
Snapshot |
getSnapshotById(ServiceId id)
Returns the last snapshot for the given state machine identifier.
|
Collection<Snapshot> |
getSnapshotsByIndex(long index)
Returns the snapshot at the given index.
|
Snapshot |
newSnapshot(ServiceId serviceId,
String serviceName,
long index,
io.atomix.time.WallClockTimestamp timestamp)
Creates a new snapshot.
|
Snapshot |
newTemporarySnapshot(ServiceId serviceId,
String serviceName,
long index,
io.atomix.time.WallClockTimestamp timestamp)
Creates a temporary in-memory snapshot.
|
String |
toString() |
public SnapshotStore(RaftStorage storage)
public Snapshot getSnapshotById(ServiceId id)
id - The state machine identifier for which to return the snapshot.public Collection<Snapshot> getSnapshotsByIndex(long index)
index - The index for which to return the snapshot.public Snapshot newTemporarySnapshot(ServiceId serviceId, String serviceName, long index, io.atomix.time.WallClockTimestamp timestamp)
serviceId - The snapshot identifier.serviceName - The snapshot service name.index - The snapshot index.timestamp - The snapshot timestamp.public Snapshot newSnapshot(ServiceId serviceId, String serviceName, long index, io.atomix.time.WallClockTimestamp timestamp)
serviceId - The snapshot identifier.serviceName - The snapshot service name.index - The snapshot index.timestamp - The snapshot timestamp.public void close()
close in interface AutoCloseableCopyright © 2013–2017. All rights reserved.