Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

Deleting records

To delete a record, you need to perform the following actions:

  1. Read the record from disk and set up a record handle that points at that record by calling one of the ctdbFirstRecord(), ctdbLastRecord(), ctdbNextRecord(), ctdbPrevRecord(), ctdbSeekRecord(), ctdbFindRecord(), or ctdbFindTarget() functions.
  2. Lock the record before reading it using the session-wide locking mechanism (ctdbLock()), or manually lock the record after reading it by calling ctdbLockRecord().
  3. Delete the record by calling ctdbDeleteRecord().

/* read and then lock the first record */

ctdbFirstRecord(hRecord);

ctdbLockRecord (hRecord, CTLOCK_WRITE);


/* delete the record */

if (ctdbDeleteRecord(hRecord) != CTDBRET_OK)

printf("Delete record failed\n");

Note that using this manual locking scheme is not the safest approach, because a manual record lock cannot be applied until after the record is read from disk. This means there is a window of opportunity for the record to be modified or deleted by another thread before the record is manually locked by this thread. Fortunately, the c-treeDB API API provides a safer locking mechanism than manually locking individual records: session-wide record locking. This locking mechanism automatically locks records as they are read from disk, thereby removing the window of opportunity, resulting in improved data security. Session-wide record locking is discussed further in Data Integrity.

TOCIndex