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(PrimitiveId, 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 |
getSnapshot(io.atomix.primitive.PrimitiveId serviceId,
long index)
Returns the snapshot for the given primitive at the given index.
|
Snapshot |
getSnapshotById(io.atomix.primitive.PrimitiveId 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(io.atomix.primitive.PrimitiveId primitiveId,
String serviceName,
long index,
io.atomix.utils.time.WallClockTimestamp timestamp)
Creates a new snapshot.
|
Snapshot |
newTemporarySnapshot(io.atomix.primitive.PrimitiveId primitiveId,
String serviceName,
long index,
io.atomix.utils.time.WallClockTimestamp timestamp)
Creates a temporary in-memory snapshot.
|
String |
toString() |
public SnapshotStore(RaftStorage storage)
public Snapshot getSnapshot(io.atomix.primitive.PrimitiveId serviceId, long index)
serviceId - the primitive for which to lookup the snapshotindex - the index for which to lookup the snapshotnull if the snapshot doesn't existpublic Snapshot getSnapshotById(io.atomix.primitive.PrimitiveId 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(io.atomix.primitive.PrimitiveId primitiveId, String serviceName, long index, io.atomix.utils.time.WallClockTimestamp timestamp)
primitiveId - The primitive identifier.serviceName - The snapshot service name.index - The snapshot index.timestamp - The snapshot timestamp.public Snapshot newSnapshot(io.atomix.primitive.PrimitiveId primitiveId, String serviceName, long index, io.atomix.utils.time.WallClockTimestamp timestamp)
primitiveId - The primitive identifier.serviceName - The snapshot service name.index - The snapshot index.timestamp - The snapshot timestamp.public void close()
close in interface AutoCloseableCopyright © 2013–2018. All rights reserved.