@InterfaceAudience.Public @InterfaceStability.Unstable public class KuduTransaction extends Object implements AutoCloseable
Once created using KuduClient.newTransaction()
or
deserialize(byte[], org.apache.kudu.client.AsyncKuduClient)
methods, an instance of this class
can be used to commit or rollback the underlying multi-row transaction. To
issue write operations as a part of the transaction, use the
newKuduSession()
or
newAsyncKuduSession()
methods to create a new
transactional session and apply write operations using it.
The KuduTransaction
implements AutoCloseable
and should be
used with try-with-resource code construct. Once an object of this class
is constructed, it starts sending automatic keep-alive heartbeat messages
to keep the underlying transaction open. Once the object goes out of scope
and close()
is automatically called by the Java
runtime (or the method is called explicitly), the heartbeating stops and the
transaction is automatically aborted by the system after not receiving
heartbeat messages for a few keep-alive intervals.
Modifier and Type | Method and Description |
---|---|
void |
close()
Stop keepalive heartbeating, if any was in progress for this transaction
handle.
|
void |
commit()
Commit the multi-row distributed transaction represented by this handle.
|
static KuduTransaction |
deserialize(byte[] buf,
AsyncKuduClient client)
Re-create KuduTransaction object given its serialized representation.
|
boolean |
isCommitComplete()
Check whether the commit phase for a transaction is complete.
|
AsyncKuduSession |
newAsyncKuduSession()
Create a new
AsyncKuduSession based on this transaction. |
KuduSession |
newKuduSession()
Create a new
KuduSession based on this transaction. |
void |
rollback()
Rollback the multi-row distributed transaction represented by this object.
|
byte[] |
serialize()
A shortcut for the
serialize(SerializationOptions)
method invoked with default-constructed KuduTransaction.SerializationOptions . |
byte[] |
serialize(org.apache.kudu.client.KuduTransaction.SerializationOptions options)
Export information on the underlying transaction in a serialized form.
|
void |
startCommit()
Start committing the multi-row distributed transaction represented by
this handle.
|
public AsyncKuduSession newAsyncKuduSession()
AsyncKuduSession
based on this transaction.
All write operations using the result session will be performed in the context of this transaction.
AsyncKuduSession
instancepublic KuduSession newKuduSession()
KuduSession
based on this transaction.
All write operations using the result session will be performed in the context of this transaction.
KuduSession
instancepublic void commit() throws KuduException
This method starts committing the transaction and awaits for the commit phase to finalize.
KuduException
- if something went wrongpublic void startCommit() throws KuduException
This method only starts committing the transaction, not awaiting for the
commit phase to finalize. Use isCommitComplete()
to check whether the transaction is committed.
KuduException
- if something went wrong upon starting to commitpublic boolean isCommitComplete() throws KuduException
true
if transaction has finalized, otherwise false
NonRecoverableException
- with Status.Aborted()
if transaction has been or is being abortedNonRecoverableException
- with Status.IllegalState()
if transaction is still open (i.e. commit() hasn't been called yet)NonRecoverableException
- with Status.NotSupported()
if transaction is in unexpected state (non-compatible backend?)KuduException
- if an error happens while querying the system about
the state of the transactionpublic void rollback() throws KuduException
This method initiates rolling back the transaction and returns right after that. The system takes care of the rest. Once the control returns and no exception is thrown, a client have a guarantee that all write operations issued in the context of this transaction cannot be seen seen outside.
KuduException
- if something went wrongpublic byte[] serialize(org.apache.kudu.client.KuduTransaction.SerializationOptions options) throws IOException
This method transforms this handle into its serialized representation.
The serialized information on a Kudu transaction can be passed among
different Kudu clients running at multiple nodes, so those separate
Kudu clients can perform operations to be a part of the same distributed
transaction. The resulting string is referred as "transaction token" and
it can be deserialized into a transaction handle (i.e. an object of this
class) via the deserialize(byte[], org.apache.kudu.client.AsyncKuduClient)
method.
This method doesn't perform any RPC under the hood.
The representation of the data in the serialized form (i.e. the format of a Kudu transaction token) is an implementation detail, not a part of the public API and can be changed without notice.
IOException
- if serialization failspublic byte[] serialize() throws IOException
serialize(SerializationOptions)
method invoked with default-constructed KuduTransaction.SerializationOptions
.IOException
public static KuduTransaction deserialize(byte[] buf, AsyncKuduClient client) throws IOException
This method doesn't perform any RPC under the hood. The newly created
object automatically does or does not send keep-alive messages depending
on the KuduTransaction.SerializationOptions.isKeepaliveEnabled()
setting when
the original KuduTransaction
object was serialized using
serialize(org.apache.kudu.client.KuduTransaction.SerializationOptions)
method.
client
- Client instance to bound the result object tobuf
- serialized representation of a KuduTransaction
objectIOException
- if deserialization failspublic void close()
This method is called automatically when the object goes out of scope
as prescribed for AutoCloseable
.
This method doesn't throw according to the recommendations for
AutoCloseable.close()
. In case of an error, this method just logs
the corresponding error message.
close
in interface AutoCloseable