Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

ctdbCommit

Commit a transaction.

Declaration

CTDBRET ctdbCommit(CTHANDLE Handle)

  • Handle [in] the session handle. Any handle will work, but you save a tiny bit of CPU by using the session handle.

Description

ctdbCommit() commits a transaction initiated with ctdbBegin() and releases all locks — both session-wide record locks (automatically acquired as a result of calling ctdbLock() and then reading a record from a table file), and manually-locked records (acquired by calling ctdbLockRecord() on an individual record).

Locks acquired both inside and outside the transaction are released. This function also disables (turns off) session-wide record locking. Note that these lock-related behaviors can be changed from the default by calling ctdbSetKeepLock().

Returns

ctdbCommit() returns CTDBRET_OK if successful, or the c-tree error code on failure. Common causes of commit errors are calling ctdbCommit() twice in a row, or calling ctdbCommit() without calling ctdbBegin() first to start a transaction. Note that if ctdbCommit() fails (and there is an open transaction), then the transaction can be rolled back to a previous set point, if any were saved, by calling ctdbRestoreSavePoint(); or the transaction can be aborted (rolled back to the beginning) by calling ctdbAbort(). Extreme circumstances, like the failure of computer hardware, can cause calls to ctdbCommit() and ctdbAbort() to fail. In situations like this, a common approach is to log an error and exit.

Example


ctdbBegin(pSession);

if (ctdbCreateTable(tHandle1,"table1",CTCREATE_NORMAL) == CTDBRET_OK)

ctdbCommit(pSession);

else

ctdbAbort(pSession);


See also

ctdbAbort(), ctdbBegin(), ctdbClearSavePoint(), ctdbRestoreSavePoint(), ctdbSetSingleSavePoint()

TOCIndex