TurboDB Engine Documentation
Table Locks
See also
Previous  Top  Next


TurboDB Engine works with two kinds of locks on its database tables:

A write lock prevents other applications from writing to the table. Write locks are used to guarantee a consistent database table during a sequence of read operations, e.g. while an index is created. More than one application can acquire a write lock on a database table at the same time.

A total lock prevents other applications from any access to the table. Total locks are needed for multiple write operations to a table, e.g. altering the table structure. Only one application at a time can acquire a total lock on the table.

A table can be opened in exclusive mode as well. This mode opens the underlying database file in the exclusive file mode which prevents any other application from opening it. Opening a table in exclusive mode has a similar result to a total lock, but there are some differences:
·Total locks are managed by TurboDB, whereas exclusive mode is manage by the file system.  
·Total locks can be acquired while the database table is already open. Exclusive mode can only be set before opening the table.  

Lock Files
Because TurboDB Engine is a file-based database engine, it must manage its locks via a lock file. The lock file for a table has the same name as the table itself but the extension is "net". The lock files contains a list of all applications that access the database table and manages the different locks on that table.

When an application wants to write to the database table, it must first look into the lock file to determine, if it is allowed to do so. If it is, it registers itself with the lock file for write access, performs the writing and than unregisters again. The lock file is created by the first application that accesses the table and deleted when the last application finishes access. Therefore a database table has no lock file as long as it is unused.

Note: If an application crashes or is killed while it has locked the table or a record of the table, it cannot remove the lock and the lock persists. This is especially the case while debugging an application that uses TurboDB Engine, because resetting it while it has acquired a lock has the same effect. If you see a lock file of an unused database table, you can simply erase it to clear all locks. The same is true if you keep getting error messages saying the table is locked by another user while you know that there is no other user.