Previous Topic

Next Topic

Transaction Processing

The c-treeDB API implementation of transaction processing functions closely follows the existing c-tree Plus API definition. The basic difference between the c-treeDB and c-treeACE ISAM transaction processing API is the separation of locking mechanisms from transaction processing. While the c-tree Plus begin transaction API allows for locking modes to be specified, the c-treeDB API separates the locking functions from transaction functions.

The code fragment below shows an example using the c-treeACE ISAM call to process a transaction with locking:

/* start transaction enabling write locks */
TRANBEG(TRNLOG | ENABLE | LK_BLOCK);

... perform some data operations ...

/* commit the transaction and release locks */
TRANEND(FREE);

The c-tree Plus code fragment above starts a transaction by invoking TRANBEG(). The mode ENABLE indicates that every c-treeACE read record operation will lock the record for writing. The mode LK_BLOCK indicates that the thread will block until the lock is acquired.

When using the c-treeDB API, the transaction processing API will not start the record locking mechanism. The code fragment below shows the equivalent example using c-treeDB API:

/* start a transaction */
ctdbBegin(AnyHandle);

/* enable write locks */
ctdbLock(AnyHandle, CTLOCK_WRITE_BLOCK);

... perform some data operations ...

/* release locks */
ctdbUnlock(AnyHandle);

/* commit the transaction */
ctdbCommit(AnyHandle);

ctdbBegin() starts a new transaction. ctdbCommit() terminates a transaction by committing any changes. ctdbAbort() terminates a transaction and aborts any changes done during the transaction. ctdbSetSavePoint() and ctdbSetSingleSavePoint() set a savepoint in the current transaction. Once a save point is set within the current transaction, ctdbRestoreSavePoint() will reverse only changes done in between the set save point and restore the save point, without terminating the transaction.

Please refer to "Data Integrity" for detailed description of c-treeDB API for transaction processing and locking.