public abstract class Snapshot extends Object implements AutoCloseable
User-provided state machines which implement the Snapshottable interface
transparently write snapshots to and read snapshots from files on disk. Each time a snapshot is taken of
the state machine state, the snapshot will be written to a single file represented by this interface.
Snapshots are backed by a Buffer dictated by the parent
StorageLevel configuration. Snapshots for file-based storage
levels like DISK and
MAPPED will be stored in a RandomAccessFile
backed buffer, and MEMORY snapshots will
be stored in an on-heap buffer.
Snapshots are read and written by a SnapshotReader and SnapshotWriter respectively.
To create a reader or writer, use the reader() and writer() methods.
Snapshot snapshot = snapshotStore.snapshot(1);
try (SnapshotWriter writer = snapshot.writer()) {
writer.writeString("Hello world!");
}
snapshot.complete();
A SnapshotReader is not allowed to be created until a SnapshotWriter has
completed writing the snapshot file and the snapshot has been marked complete.
This allows snapshots to effectively be written and closed but not completed until other conditions
are met. Prior to the completion of a snapshot, a failure and recovery of the parent SnapshotStore
will not recover an incomplete snapshot. Once a snapshot is complete, the snapshot becomes immutable,
can be recovered after a failure, and can be read by multiple readers concurrently.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the snapshot.
|
Snapshot |
complete()
Completes writing the snapshot to persist it and make it available for reads.
|
void |
delete()
Deletes the snapshot.
|
abstract long |
index()
Returns the snapshot index.
|
abstract SnapshotReader |
reader()
Returns a new snapshot reader.
|
abstract long |
timestamp()
Returns the snapshot timestamp.
|
abstract SnapshotWriter |
writer()
Returns a new snapshot writer.
|
public abstract long index()
The snapshot index is the index of the state machine at the point at which the snapshot was written.
public abstract long timestamp()
The timestamp is the logical state machine time at the index at which the snapshot
was written.
public abstract SnapshotWriter writer()
Only a single SnapshotWriter per Snapshot can be created. The single writer
must write the snapshot in full and complete() the snapshot to persist it to disk
and make it available for reads.
IllegalStateException - if a writer was already created or the snapshot is completepublic abstract SnapshotReader reader()
A SnapshotReader can only be created for a snapshot that has been fully written and
completed. Multiple concurrent readers can be created for the same snapshot
since completed snapshots are immutable.
IllegalStateException - if the snapshot is not completepublic Snapshot complete()
Snapshot writers must call this method to persist a snapshot to disk. Prior to completing a
snapshot, failure and recovery of the parent SnapshotStore will not result in recovery
of this snapshot. Additionally, no readers can be created until the snapshot
has been completed.
public void close()
close in interface AutoCloseablepublic void delete()
Copyright © 2013–2016. All rights reserved.