c-treeDB Transaction Processing is Session-Based!
Help! I received error 71 (TNON_ERR - no active transaction)!
A common error observed by developers using the c-treeDB C or C++ programming API results from the fact that transactions are held session-wide. Usually this results from an attempt to create a nested transaction. While c-tree Plus does not support nested transactions, it does provide powerful savepoint and rollback features.
The general situation occurs as demonstrated in the following c-treeDB C++ pseudo code:
mySession->Begin();
// do some Session operations
myTable->Begin();
//do more Table operations
myTable->Abort();
mySession->Commit();
The result from this example is a TNON_ERR error (71). Why?
Transactions are held session-wide with c-treeDB. Thus, when the Abort is encountered in the table operations, the transaction started in the session is terminated. When the session Commit occurs, you receive error 71, as there is no active transaction at that time.
While all of the c-treeDB transaction processing functions, ctdbBegin , ctdbAbort , ctdbCommit and ctdbIsTransActive , receive a session handle as a parameter, ANY handle will suffice. c-treeDB always knows how to determine the session handle associated with any handle.
The following example demonstrates one solution using savepoints to avoid this situation:
mySession->Begin();
// do some Session operations
myTableSavePoint = myTable->SetSavePoint();
// do some Table operations
// `Abort' the table operations
myTable->RestoreSavePoint(myTableSavePoint)
// other operations
mySession->Commit();
|