|
The Berkeley DB Concurrent Data Store product has a different set of conventions for locking. It provides multiple reader/single writer semantics, but not per-page locking or transaction recoverability. As such, it does its locking entirely at the interface to the access methods.
The object it locks is the file, identified by its unique file number. The locking matrix is not one of the two standard lock modes, instead, we use a four-lock set, consisting of:
The IWRITE lock is used for cursors that will be used for updating (IWRITE locks are implicitly obtained for write operations through the Berkeley DB handles, e.g., DB->put, DB->del). While the cursor is reading, the IWRITE lock is held, but as soon as the cursor is about to modify the database, the IWRITE is upgraded to a WRITE lock. This upgrade blocks until all readers have exited the database. Because only one IWRITE lock is allowed at any one time, no two cursors can ever try to upgrade to a WRITE lock at the same time, and therefore deadlocks are prevented, which is essential as Berkeley DB Concurrent Data Store does not include deadlock detection and recovery.
Applications that need to lock compatibly with Berkeley DB Concurrent Data Store must obey the following rules: