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 will be stored in a disk
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 openReader() and openWriter() 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.
|
boolean |
equals(Object object) |
int |
hashCode() |
long |
index()
Returns the snapshot index.
|
abstract boolean |
isPersisted()
Returns whether the snapshot is persisted.
|
abstract SnapshotReader |
openReader()
Opens a new snapshot reader.
|
abstract SnapshotWriter |
openWriter()
Opens a new snapshot writer.
|
Snapshot |
persist()
Persists the snapshot to disk if necessary.
|
ServiceId |
serviceId()
Returns the identifier of the state machine to which the snapshot belongs.
|
abstract String |
serviceName()
Returns the service name.
|
io.atomix.time.WallClockTimestamp |
timestamp()
Returns the snapshot timestamp.
|
public abstract String serviceName()
public ServiceId serviceId()
public long index()
The snapshot index is the index of the state machine at the point at which the snapshot was written.
public io.atomix.time.WallClockTimestamp timestamp()
The timestamp is the wall clock time at the index() at which the snapshot was taken.
public abstract SnapshotWriter openWriter()
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 openReader()
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 Snapshot persist()
If the snapshot store is backed by disk, the snapshot will be persisted.
public abstract boolean isPersisted()
public void close()
close in interface AutoCloseablepublic void delete()
Copyright © 2013–2017. All rights reserved.