Kudu C++ client API
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
kudu::client::KuduTransaction Class Reference

#include <client.h>

Inheritance diagram for kudu::client::KuduTransaction:

Classes

class  SerializationOptions
 

Public Member Functions

Status CreateSession (sp::shared_ptr< KuduSession > *session) WARN_UNUSED_RESULT
 
Status Commit () WARN_UNUSED_RESULT
 
Status StartCommit () WARN_UNUSED_RESULT
 
Status IsCommitComplete (bool *is_complete, Status *completion_status) WARN_UNUSED_RESULT
 
Status Rollback () WARN_UNUSED_RESULT
 
Status Serialize (std::string *serialized_txn, const SerializationOptions &options=SerializationOptions()) const WARN_UNUSED_RESULT
 

Static Public Member Functions

static Status Deserialize (const sp::shared_ptr< KuduClient > &client, const std::string &serialized_txn, sp::shared_ptr< KuduTransaction > *txn) WARN_UNUSED_RESULT
 

Detailed Description

A class representing a multi-row transaction in Kudu. Once created using KuduClient::BeginTransaction() or KuduTransaction::Deserialize method, KuduTransaction instance can be used to commit or rollback the underlying multi-row transaction and create a transactional session.

Note
The KuduTransaction should be kept in scope to maintain automatic keep-alive heartbeating for the corresponding transaction. Once this object goes out of scope, the heartbeating stops and the transaction may automatically be aborted soon if no other clients do the heartbeating.
There isn't any automation to rollback or commit the underlying transaction upon destruction of an instance of this class.
Warning
The set of methods in this class, their behavior, and signatures are experimental and may change or disappear in future. The class itself is experimental and may change its lineage, API status, or disappear in future.

Member Function Documentation

◆ Commit()

Status kudu::client::KuduTransaction::Commit ( )

Commit the transaction.

This method automatically flushes all transactional sessions created off this transaction handle via KuduTransaction::CreateSession(), initiates committing the transaction, and then waits for the commit phase to finalize. The flushing of all the derivative transactional sessions helps avoiding unintentional data loss when those sessions are not flushed explicitly before committing. No new operations should be pushed into the derivative transactional sessions created off this handle once the method has been called.

Returns
Returns Status::OK() if all the stages of the transaction's commit sequence were successful, i.e. the status of various pre-commit work, the status of starting the commit phase, the status of the commit phase itself once it's completed. Returns non-OK status of the very first failed stage of the transaction's commit sequence.

◆ CreateSession()

Status kudu::client::KuduTransaction::CreateSession ( sp::shared_ptr< KuduSession > *  session)

Create a new KuduSession with "transactional" semantics.

Every write operation performed in the context of the newly created "transactional" session becomes a part of the corresponding multi-row transaction represented by an instance of this class. Multiple sessions can be created in the context of the same multi-row distributed transaction by the same or different Kudu clients residing on a single or multiple nodes.

Parameters
[out]sessionThe result session object.
Returns
Operation result status.

◆ Deserialize()

static Status kudu::client::KuduTransaction::Deserialize ( const sp::shared_ptr< KuduClient > &  client,
const std::string &  serialized_txn,
sp::shared_ptr< KuduTransaction > *  txn 
)
static

Re-create KuduTransaction object given its serialized representation.

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::enable_keepalive() setting when the original KuduTransaction object was serialized using KuduTransaction::Serialize().

Parameters
[in]clientClient instance to bound the result object to.
[in]serialized_txnString containing serialized representation of KuduTransaction object.
[out]txnThe result KuduTransaction object, wrapped into a smart pointer.
Returns
Operation result status.

◆ IsCommitComplete()

Status kudu::client::KuduTransaction::IsCommitComplete ( bool *  is_complete,
Status completion_status 
)

Whether the commit has completed i.e. no longer in progress of finalizing.

This method checks for the transaction's commit status, setting the is_complete out parameter to true and the completion_status parameter to the finalization status of the commit process, assuming the method returning Status::OK(). The happy case is when the method returns Status::OK(), is_complete is set to true and completion_status is set to Status::OK() – that means the transaction has successfully finalized its commit phase.

Parameters
[out]is_completeWhether the process of finalizing the commit of the transaction has ended, including both success and failure outcomes. In other words, the value of this out parameter indicates whether the finalization of the transaction's commit phase is no longer in progress: it already succeeded or failed by the time of processing the request. This parameter is assigned a meaningful value iff the method returns Status::OK().
[out]completion_statusThe status of finalization of the transaction's commit phase:
  • Status::OK() if the commit phase successfully finalized
  • non-OK status if the commit phase failed to finalize This parameter is assigned a meaningful value iff the method returns Status::OK().
Returns
The result status of querying the transaction's commit status. Both is_complete and completion_status are set iff the method returns Status::OK().

◆ Rollback()

Status kudu::client::KuduTransaction::Rollback ( )

Rollback/abort the transaction.

Returns
Operation result status.

◆ Serialize()

Status kudu::client::KuduTransaction::Serialize ( std::string *  serialized_txn,
const SerializationOptions options = SerializationOptions() 
) const

Export the information on this transaction in a serialized form.

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 can be deserialized into a transaction handle (i.e. an object of the KuduTransaction class) via the KuduTransaction::Deserialize() method.

This method doesn't perform any RPC under the hood. The behavior of this method is controlled by SerializationOptions set for this transaction handle.

Note
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.
Parameters
[out]serialized_txnResult string to output the serialized transaction information.
[in]optionsOptions to use when serializing the handle (optional). If omitted, the default serialization parameters are used – the same as it would be for a default-constructed instance of SerializationOptions used for this parameter.
Returns
Operation result status.

◆ StartCommit()

Status kudu::client::KuduTransaction::StartCommit ( )

Start committing this transaction, but don't wait for the commit phase to finalize.

This method initiates the commit phase for this transaction, not waiting for the commit phase to finalize. It requires all the transactional sessions created off this handle via KuduTransaction::CreateSession() to be flushed already. No new operations should be pushed into the derivative transactional sessions created off this handle once the method has been called. To check for the transaction's commit status, use the KuduTransaction::IsCommitComplete() method.

Returns
Status of starting the commit phase for this transaction if all the transactional sessions created off this handle are flushed, otherwise returns Status::IllegalState().

The documentation for this class was generated from the following file: