public interface Commit<T extends Operation> extends AutoCloseable
This class is used by the RaftServer internally to expose committed
commands and queries to the user provided
StateMachine. Operations that are wrapped in a Commit
object are guaranteed to be persisted in the Raft log on a majority of the cluster. The commit object provides metadata
about the committed operation such as the index() at which the operation was written in the log, the
time() at which it was written, and the Session that submitted the
operation.
| Modifier and Type | Method and Description |
|---|---|
void |
clean()
Cleans the commit.
|
void |
close()
Closes the commit.
|
long |
index()
Returns the commit index.
|
T |
operation()
Returns the operation submitted by the user.
|
Session |
session()
Returns the session that submitted the operation.
|
Instant |
time()
Returns the time at which the operation was committed.
|
Class<T> |
type()
Returns the commit type.
|
long index()
This is the index at which the committed Operation was written in the Raft log.
Catalog guarantees that this index will be the same for all instances of the given operation on all nodes in the
cluster.
Note that for Query operations, the returned index may actually represent
the last committed index in the Raft log since queries are not actually written to disk. This, however, does not
break the single index guarantee since queries will only be applied to the leader's StateMachine.
Session session()
The returned Session is representative of the session that submitted the operation
that resulted in this Commit. Note that the session will be provided regardless
of whether the session is currently active in the cluster. However, attempts to Session.publish(Object) to
inactive sessions will fail silently.
Additionally, because clients only connect to one server at any given time, the Session
provided in any given commit to any StateMachine may or may not be capable of
communicating with the client.
Instant time()
The time is representative of the time at which the leader wrote the operation to its log. Because instants are replicated through the Raft consensus algorithm, they are guaranteed to be consistent across all servers and therefore can be used to perform time-dependent operations such as expiring keys or timeouts.
Users should never use System time to control behavior in a state machine and should instead rely
upon Commit times for time-based controls.
Class<T> type()
This is the Class returned by the committed operation's Object.getClass() method.
T operation()
void clean()
When the commit is cleaned, it will be removed from the log and may be removed permanently from disk at some arbitrary point in the future.
void close()
Once the commit is closed, it may be recycled and should no longer be accessed by the closer.
close in interface AutoCloseableCopyright © 2013–2015. All rights reserved.