Berkeley DB Reference Guide:
Locking Subsystem

PrevRefNext

Configuring locking

The DBENV->set_lk_detect function specifies that the deadlock detector should be run whenever a lock blocks. This option provides for rapid detection of deadlocks at the expense of potentially frequent invocations of the deadlock detector. On a fast processor with a highly contentious application, where response time is critical, this is a good choice. An argument to the DBENV->set_lk_detect function indicates which transaction to abort when a deadlock is detected. It can take on any one of the following values:

DB_LOCK_YOUNGEST
Abort the most recently started transaction.
DB_LOCK_OLDEST
Abort the longest lived transaction.
DB_LOCK_RANDOM
Abort whatever transaction the deadlock detector happens to find first.
DB_LOCK_DEFAULT
Use the default policy (currently DB_RANDOM).

In general, DB_LOCK_DEFAULT is probably the correct choice. If an application has long-running transactions, then DB_LOCK_YOUNGEST will guarantee that transactions eventually complete, but it may do so at the expense of a large number of aborts.

The alternative to using the DBENV->set_lk_detect interface is to run the deadlock detector manually, using the Berkeley DB lock_detect interface.

The DBENV->set_lk_conflicts function allows you to specify your own locking conflicts matrix. This is an advanced configuration option, and rarely necessary.

PrevRefNext

Copyright Sleepycat Software