@ThreadSafe public class RaftKVTransaction extends Object implements KVTransaction
RaftKVDatabase transaction.| Modifier and Type | Method and Description |
|---|---|
void |
adjustCounter(byte[] key,
long amount) |
void |
commit() |
void |
configChange(String identity,
String address)
Include a cluster configuration change when this transaction is committed.
|
long |
decodeCounter(byte[] bytes) |
byte[] |
encodeCounter(long value) |
protected void |
finalize() |
byte[] |
get(byte[] key) |
KVPair |
getAtLeast(byte[] minKey) |
KVPair |
getAtMost(byte[] maxKey) |
long |
getBaseIndex()
Get the index of the log entry on which this transaction is based.
|
long |
getBaseTerm()
Get the term of the log entry on which this transaction is based.
|
long |
getCommitIndex()
Get the index of the Raft log entry on which this transaction is waiting to be committed (in the Raft sense)
before it can complete.
|
long |
getCommitTerm()
Get the term of the Raft log entry on which this transaction is waiting to be committed (in the Raft sense)
before it can complete.
|
String[] |
getConfigChange()
Get the cluster configuration change associated with this transaction, if any.
|
Consistency |
getConsistency()
Get the consistency level for this transaction.
|
RaftKVDatabase |
getKVDatabase() |
Iterator<KVPair> |
getRange(byte[] minKey,
byte[] maxKey,
boolean reverse) |
TxState |
getState()
Get the state of this transaction.
|
long |
getTxId()
Get the locally unique ID of this transaction.
|
boolean |
isReadOnly()
Determine whether this transaction is configured as read-only.
|
CloseableKVStore |
mutableSnapshot() |
void |
put(byte[] key,
byte[] value) |
void |
remove(byte[] key) |
void |
removeRange(byte[] minKey,
byte[] maxKey) |
void |
rollback() |
void |
setConsistency(Consistency consistency)
Set the consistency level for this transaction.
|
void |
setReadOnly(boolean readOnly)
Set whether this transaction should be read-only.
|
void |
setTimeout(long timeout)
Set the commit timeout for this instance.
|
String |
toString() |
ListenableFuture<Void> |
watchKey(byte[] key) |
public long getTxId()
public TxState getState()
public long getBaseTerm()
public long getBaseIndex()
public long getCommitTerm()
TxState.COMMIT_WAITINGpublic long getCommitIndex()
TxState.COMMIT_WAITINGpublic Consistency getConsistency()
The default consistency level is Consistency.LINEARIZABLE.
public void setConsistency(Consistency consistency)
This setting may be modified freely during a transaction while it is still open;
it only determines the behavior of the transaction after commit() is invoked.
consistency - desired consistency levelIllegalStateException - if consistency is different from the currently configured
consistency but this transaction is no longer open (i.e., in state TxState.EXECUTING)IllegalArgumentException - if consistency is nullpublic boolean isReadOnly()
public void setReadOnly(boolean readOnly)
Read-only transactions support modifications during the transaction, and these modifications will be visible
when read back, but they are discarded on commit().
readOnly - true to discard mutations on commit, false to apply mutations on commitStaleTransactionException - if this transaction is no longer openpublic void configChange(String identity, String address)
The change will have been applied once this transaction is successfully committed.
Raft supports configuration changes that add or remove one node at a time to/from the cluster. If this method is invoked more than once in a single transaction, all but the last invocation are ignored.
Initially, nodes are unconfigured. An unconfigured node becomes configured in one of two ways:
identity equal to this node's identity and a non-null address,
which creates a new cluster and adds this node to it.Therefore, this method must be used to intialize a new cluster.
identity - the identity of the node to add or removeaddress - the network address of the node if adding, or null if removingIllegalStateException - if this method has been invoked previously on this instanceIllegalArgumentException - if identity is nullpublic String[] getConfigChange()
The returned array has length two and contains the identity and address
parameters passed to configChange().
The returned array is a copy; changes have no effect on this instance.
public KVPair getAtLeast(byte[] minKey)
getAtLeast in interface KVStorepublic void removeRange(byte[] minKey,
byte[] maxKey)
removeRange in interface KVStorepublic void adjustCounter(byte[] key,
long amount)
adjustCounter in interface KVStorepublic byte[] encodeCounter(long value)
encodeCounter in interface KVStorepublic long decodeCounter(byte[] bytes)
decodeCounter in interface KVStorepublic RaftKVDatabase getKVDatabase()
getKVDatabase in interface KVTransactionpublic void setTimeout(long timeout)
RaftKVTransactions do not block while the transaction is open; the configured value is used
as a timeout for the commit() operation only. If commit() takes longer than timeout
milliseconds, a RetryTransactionException is thrown.
The default value for all transactions is configured by RaftKVDatabase.setCommitTimeout(int).
setTimeout in interface KVTransactiontimeout - transaction commit timeout in milliseconds, or zero for unlimitedIllegalArgumentException - if timeout is negativeStaleTransactionException - if this transaction is no longer openpublic ListenableFuture<Void> watchKey(byte[] key)
Key watches are supported by RaftKVTransaction.
Raft key watches are compatible with all Consistency levels, in that if a key watch fires due
to a mutation to some key, then a subsequent transaction will see that mutation, no matter what
Consistency level is configured for that transaction.
Listeners registered on the returned ListenableFuture must not perform any long running
or blocking operations.
watchKey in interface KVTransactionkey - StaleTransactionExceptionRetryTransactionExceptionKVDatabaseExceptionUnsupportedOperationExceptionIllegalArgumentExceptionpublic void commit()
commit in interface KVTransactionpublic void rollback()
rollback in interface KVTransactionpublic CloseableKVStore mutableSnapshot()
Mutable snapshots are supported by RaftKVTransaction.
mutableSnapshot in interface KVTransactionUnsupportedOperationExceptionStaleTransactionExceptionRetryTransactionExceptionCopyright © 2016. All rights reserved.