public class SnapshotStore extends Object implements AutoCloseable
Storage 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 createSnapshot(long) 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 Copycat
a snapshot may actually only represent a subset of the state machine's state. Indeed, internal Copycat
server state machines use log cleaning and store no state in snapshots. When a snapshot is taken of
the state machine state, only prior entries that contributed to the state stored in the snapshot -
commands marked with the SNAPSHOT
compaction mode - are removed from the log prior to the snapshot.| Constructor and Description |
|---|
SnapshotStore(String name,
Storage storage,
Serializer serializer) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
Snapshot |
createSnapshot(long index)
Creates a new snapshot.
|
Snapshot |
currentSnapshot()
Returns the most recent completed snapshot.
|
Serializer |
serializer()
Returns the snapshot store serializer.
|
Snapshot |
snapshot(long index)
Returns a snapshot by index.
|
Collection<Snapshot> |
snapshots()
Returns a collection of all snapshots stored on disk.
|
String |
toString() |
public SnapshotStore(String name, Storage storage, Serializer serializer)
public Serializer serializer()
public Snapshot currentSnapshot()
The current snapshot is the last Snapshot successfully written and
completed. It represents the most recent snapshot successfully
written to disk and from which the server state can be restored.
public Collection<Snapshot> snapshots()
Snapshots will be loaded from the underlying Storage when the snapshot store is created.
The returned collection of Snapshots will include any stored complete
snapshots. Both stored and new incomplete snapshots will be excluded from this list.
public Snapshot snapshot(long index)
index - The snapshot index.public Snapshot createSnapshot(long index)
index - The snapshot index.public void close()
close in interface AutoCloseableCopyright © 2013–2016. All rights reserved.