1<!--$Id: timeout.so,v 1.9 2005/12/02 17:27:49 alanb Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB Reference Guide: Deadlock detection using timers</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<a name="2"><!--meow--></a><a name="3"><!--meow--></a>
12<table width="100%"><tr valign=top>
13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Locking Subsystem</dl></b></td>
14<td align=right><a href="../lock/dead.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../lock/deaddbg.html"><img src="../../images/next.gif" alt="Next"></a>
15</td></tr></table>
16<p align=center><b>Deadlock detection using timers</b></p>
17<p>Lock and transaction timeouts may be used in place of, or in addition
18to, regular deadlock detection.  If lock timeouts are set, lock requests
19will return <a href="../../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> from a lock call when it is
20detected that the lock's timeout has expired, that is, the lock request
21has blocked, waiting, longer than the specified timeout.  If transaction
22timeouts are set, lock requests will return <a href="../../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a>
23from a lock call when it has been detected that the transaction has been
24active longer than the specified timeout.</p>
25<p>If lock or transaction timeouts have been set, database operations will
26return <a href="../../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> when the lock timeout has expired or the
27transaction has been active longer than the specified timeout.
28Applications wanting to distinguish between true deadlock and timeout
29can use the <a href="../../api_c/env_set_flags.html#DB_TIME_NOTGRANTED">DB_TIME_NOTGRANTED</a> configuration flag, which causes
30database operations to instead return <a href="../../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> in the
31case of timeout.</p>
32<p>As lock and transaction timeouts are only checked when lock requests
33first block or when deadlock detection is performed, the accuracy of
34the timeout depends on how often deadlock detection is performed.  More
35specifically, transactions will continue to run after their timeout has
36expired if they do not block on a lock request after that time.
37A separate deadlock detection thread (or process) should always
38be used if the application depends on timeouts; otherwise, if
39there are no new blocked lock requests a pending timeout will
40never trigger.</p>
41<p>If the database environment deadlock detector has been configured with
42the <a href="../../api_c/env_set_lk_detect.html#DB_LOCK_EXPIRE">DB_LOCK_EXPIRE</a> option, timeouts are the only mechanism by
43which deadlocks will be broken.  If the deadlock detector has been
44configured with a different option, then regular deadlock detection will
45be performed, and in addition, if timeouts have also been specified,
46lock requests and transactions will time out as well.</p>
47<p>Lock and transaction timeouts may be specified on a database environment
48wide basis using the <a href="../../api_c/env_set_timeout.html">DB_ENV-&gt;set_timeout</a> method.  Lock timeouts may be
49specified on a per-lock request basis using the <a href="../../api_c/lock_vec.html">DB_ENV-&gt;lock_vec</a> method.  Lock
50and transaction timeouts may be specified on a per-transaction basis
51using the <a href="../../api_c/txn_set_timeout.html">DB_TXN-&gt;set_timeout</a> method.  Per-lock and per-transaction
52timeouts supersede environment wide timeouts.</p>
53<p>For example, consider that the environment wide transaction timeout has
54been set to 20ms, the environment wide lock timeout has been set to
5510ms, a transaction has been created in this environment and its timeout
56value set to 8ms, and a specific lock request has been made on behalf
57of this transaction where the lock timeout was set to 4ms.  By default,
58transactions in this environment will be timed out if they block waiting
59for a lock after 20ms.  The specific transaction described will be timed
60out if it blocks waiting for a lock after 8ms.  By default, any lock
61request in this system will be timed out if it blocks longer than 10ms,
62and the specific lock described will be timed out if it blocks longer
63than 4ms.</p>
64<table width="100%"><tr><td><br></td><td align=right><a href="../lock/dead.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../lock/deaddbg.html"><img src="../../images/next.gif" alt="Next"></a>
65</td></tr></table>
66<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
67</body>
68</html>
69