NdbTransaction Class Reference

#include <NdbTransaction.hpp>

List of all members.


Detailed Description

Represents a transaction.

A transaction (represented by an NdbTransaction object) belongs to an Ndb object and is created using Ndb::startTransaction(). A transaction consists of a list of operations (represented by NdbOperation, NdbScanOperation, NdbIndexOperation, and NdbIndexScanOperation objects). Each operation access exactly one table.

After getting the NdbTransaction object, the first step is to get (allocate) an operation given the table name using one of the methods getNdbOperation(), getNdbScanOperation(), getNdbIndexOperation(), or getNdbIndexScanOperation(). Then the operation is defined. Several operations can be defined on the same NdbTransaction object, they will in that case be executed in parallell. When all operations are defined, the execute() method sends them to the NDB kernel for execution.

The execute() method returns when the NDB kernel has completed execution of all operations defined before the call to execute(). All allocated operations should be properly defined before calling execute().

A call to execute() uses one out of three types of execution:

  1. NdbTransaction::NoCommit Executes operations without committing them.
  2. NdbTransaction::Commit Executes remaining operation and commits the complete transaction
  3. NdbTransaction::Rollback Rollbacks the entire transaction.

execute() is equipped with an extra error handling parameter. There are two alternatives:

  1. NdbTransaction::AbortOnError (default). The transaction is aborted if there are any error during the execution
  2. NdbTransaction::AO_IgnoreError Continue execution of transaction even if operation fails

Meta Information

Error Handling

Public Types

Public Member Functions

Execute Transaction

Member Enumeration Documentation

enum NdbTransaction::AbortOption
 

Commit type of transaction

Enumerator:
AbortOnError  Abort transaction on failed operation.
AO_IgnoreError  Transaction continues on failed operation.

enum NdbTransaction::CommitStatusType
 

The commit status of the transaction.

Enumerator:
NotStarted  Transaction not yet started.
Started  Missing explanation
Committed  Transaction has been committed.
Aborted  Transaction has been aborted.
NeedAbort  Missing explanation

enum NdbTransaction::ExecType
 

Execution type of transaction

Enumerator:
NoCommit  Execute the transaction as far as it has been defined, but do not yet commit it
Commit  Execute and try to commit the transaction.
Rollback  Rollback transaction.


Member Function Documentation

void NdbTransaction::close  ) 
 

Close transaction

Note:
Equivalent to to calling Ndb::closeTransaction()

CommitStatusType NdbTransaction::commitStatus  ) 
 

Get the commit status of the transaction.

Returns:
The commit status of the transaction

int NdbTransaction::execute ExecType  execType,
AbortOption  abortOption = AbortOnError,
int  force = 0
 

Executes transaction.

Parameters:
execType Execution type:
ExecType::NoCommit executes operations without committing them.
ExecType::Commit executes remaining operations and commits the complete transaction.
ExecType::Rollback rollbacks the entire transaction.
abortOption Handling of error while excuting AbortOnError - Abort transaction if an operation fail IgnoreError - Accept failing operations
force When operations should be sent to NDB Kernel. (See Adaptive Send Algorithm.)
  • 0: non-force, adaptive algorithm notices it (default);
  • 1: force send, adaptive algorithm notices it;
  • 2: non-force, adaptive algorithm do not notice the send.
Returns:
0 if successful otherwise -1.

int NdbTransaction::getGCI  ) 
 

Get global checkpoint identity (GCI) of transaction.

Each committed transaction belong to a GCI. The log for the committed transaction is saved on disk when a global checkpoint occurs.

Whether or not the global checkpoint with this GCI has been saved on disk or not cannot be determined by this method.

By comparing the GCI of a transaction with the value last GCI restored in a restarted NDB Cluster one can determine whether the transaction was restored or not.

Note:
Global Checkpoint Identity is undefined for scan transactions (This is because no updates are performed in scan transactions.)
Returns:
GCI of transaction or -1 if GCI is not available. (Note that there has to be an NdbTransaction::execute call with Ndb::Commit for the GCI to be available.)

const NdbError& NdbTransaction::getNdbError  )  const
 

Get error object with information about the latest error.

Returns:
An error object with information about the latest error.

int NdbTransaction::getNdbErrorLine  ) 
 

Get the method number where the latest error occured.

Returns:
Line number where latest error occured.

NdbOperation* NdbTransaction::getNdbErrorOperation  ) 
 

Get the latest NdbOperation which had an error. This method is used on the NdbTransaction object to find the NdbOperation causing an error. To find more information about the actual error, use method NdbOperation::getNdbError() on the returned NdbOperation object.

Returns:
The NdbOperation causing the latest error.

NdbIndexOperation* NdbTransaction::getNdbIndexOperation const NdbDictionary::Index anIndex  ) 
 

Get an operation from NdbIndexOperation idlelist and get the NdbTransaction object that was fetched by startTransaction pointing to this operation.

Parameters:
anIndex An index object (fetched by NdbDictionary::Dictionary::getIndex).
Returns:
Pointer to an NdbIndexOperation object if successful, otherwise NULL

NdbIndexScanOperation* NdbTransaction::getNdbIndexScanOperation const NdbDictionary::Index anIndex  ) 
 

Get an operation from NdbIndexScanOperation idlelist and get the NdbTransaction object which was fetched by startTransaction pointing to this operation.

Parameters:
anIndex An index object (fetched by NdbDictionary::Dictionary::getIndex).
Returns:
pointer to an NdbOperation object if successful, otherwise NULL

NdbOperation* NdbTransaction::getNdbOperation const NdbDictionary::Table aTable  ) 
 

Get an NdbOperation for a table. Note that the operation has to be defined before it is executed.

Note:
All operations within the same transaction need to be initialized with this method.
Parameters:
aTable A table object (fetched by NdbDictionary::Dictionary::getTable)
Returns:
Pointer to an NdbOperation object if successful, otherwise NULL.

NdbScanOperation* NdbTransaction::getNdbScanOperation const NdbDictionary::Table aTable  ) 
 

Get an operation from NdbScanOperation idlelist and get the NdbTransaction object which was fetched by startTransaction pointing to this operation.

Parameters:
aTable A table object (fetched by NdbDictionary::Dictionary::getTable)
Returns:
pointer to an NdbOperation object if successful, otherwise NULL

const NdbOperation* NdbTransaction::getNextCompletedOperation const NdbOperation op  )  const
 

Get completed (i.e. executed) operations of a transaction

This method should only be used after a transaction has been executed.

  • NdbTransaction::getNextCompletedOperation(NULL) returns the first NdbOperation object.
  • NdbTransaction::getNextCompletedOperation(op) returns the NdbOperation object defined after the NdbOperation "op".

This method is typically used to fetch all NdbOperation:s of a transaction to check for errors (use NdbOperation::getNdbError to fetch the NdbError object of an NdbOperation).

Note:
This method should only be used after the transaction has been executed and before the transaction has been closed.
Parameters:
op Operation, NULL means get first operation
Returns:
Operation "after" op

Uint64 NdbTransaction::getTransactionId  ) 
 

Get transaction identity.

Returns:
Transaction id.

int NdbTransaction::refresh  ) 
 

Refresh Update timeout counter of this transaction in the database. If you want to keep the transaction active in the database longer than the transaction abort timeout.

Note:
It's not advised to take a lock on a record and keep it for a extended time since this can impact other transactions.


Documentation generated Mon Nov 28 11:48:20 2005 from mysql source files.
© 2003-2004 MySQL AB