Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

Table Open Modes

c-treeDB API File
Open Mode

c-treeDB API .NET
File Open Mode




Use this mode if no other open modes apply.



Open only the data table. Used to rebuild a table that may or may not be missing indexes.

  • Caution: Updates made to a data file with this file mode will not have any necessary updates reflected in the associated index files.



This mode opens the table and the associated index as exclusive. If this mode is used, only one user can open a table at a time. If an application already has the file(s) open in any mode, no other application can open the table as CTOPEN_EXCLUSIVE. Once an application opens a table as CTOPEN_EXCLUSIVE, no other application can open it. Reads and writes are cached for the files opened with this file mode since there are no integrity issues with only one process in the file.



Many operating systems and/or C compiler run-time libraries limit the number of files that can be opened at one time. A permanent file open causes the table and index files to be opened and stay open until the program executes a file close. A non-permanent file open causes the table data and index files to be opened, but allows them to be transparently closed and reopened to allow other data and index files to be used. When it is necessary for a data and index file to be temporarily closed, FairCom DB selects the least recently used file. This file remains closed until it is used, at which time it will be automatically reopened. Non-permanent mode is the default and should be used unless you have a special circumstance. This strategy causes FairCom DB to use all available file descriptors.



This mode opens tables with corrupted indexes, or in certain cases, tables with corrupted data.

Corrupt indexes: With c-treeDB API this mode is usually used in conjunction with the ctdbAlterTable() function to perform a rebuild: open the table with CTOPEN_CORRUPT mode then call ctdbAlterTable() with the CTDB_ALTER_INDEX action to force the rebuild of all indexes of the table.

You can also call ctdbAlterTable() with the (CTDB_ALTER_INDEX | CTDB_ALTER_PURGEDUP) actions to purge any duplicate records that may cause the index rebuild to fail.

Corrupt table: If a table becomes corrupt, the table may be opened with CTOPEN_CORRUPT mode and then ctdbAlterTable() is invoked with the CTDB_ALL_FULL action to try to recover the table. Note that this is a last-ditch effort that could cause data loss. Please contact FairCom before you do this.



Tables opened with this mode require a record lock before a record can be updated. If a lock is not obtained, the error code DADV_ERR is returned.



Tables opened with this mode require a record lock as records are read. Obtain at least a read lock on a record before it can be read, otherwise the function will return error code DADV_ERR.



Opens the table in READONLY mode and does not allow any modifications to the table structure or data records.



Enables ctdbCloseTable() to explicitly call ctdbUnLockTable().

Note: c-treeDB API .NET users can find the open modes listed in the OPEN_MODE enum.