| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 | <title>Deadlock detection using timers</title> |
| 7 | <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> |
| 8 | <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> |
| 9 | <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="lock.html" title="Chapter 16. The Locking Subsystem" /> |
| 11 | <link rel="prev" href="lock_dead.html" title="Deadlock detection" /> |
| 12 | <link rel="next" href="lock_deaddbg.html" title="Deadlock debugging" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Deadlock detection using timers</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="lock_dead.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 16. |
| 26 | The Locking Subsystem |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="lock_deaddbg.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="lock_timeout"></a>Deadlock detection using timers</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>Lock and transaction timeouts may be used in place of, or in addition |
| 42 | to, regular deadlock detection. If lock timeouts are set, lock requests |
| 43 | will return <a class="link" href="program_errorret.html#program_errorret.DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> from a lock call when it is |
| 44 | detected that the lock's timeout has expired, that is, the lock request |
| 45 | has blocked, waiting, longer than the specified timeout. If transaction |
| 46 | timeouts are set, lock requests will return <a class="link" href="program_errorret.html#program_errorret.DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> |
| 47 | from a lock call when it has been detected that the transaction has been |
| 48 | active longer than the specified timeout.</p> |
| 49 | <p>If lock or transaction timeouts have been set, database operations will |
| 50 | return <a class="link" href="program_errorret.html#program_errorret.DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> when the lock timeout has expired or the |
| 51 | transaction has been active longer than the specified timeout. |
| 52 | Applications wanting to distinguish between true deadlock and timeout |
| 53 | can use the <a href="../api_reference/C/envset_flags.html" class="olink">DB_ENV->set_flags()</a> configuration flag, which causes |
| 54 | database operations to instead return <a class="link" href="program_errorret.html#program_errorret.DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> in the |
| 55 | case of timeout.</p> |
| 56 | <p>As lock and transaction timeouts are only checked when lock requests |
| 57 | first block or when deadlock detection is performed, the accuracy of |
| 58 | the timeout depends on how often deadlock detection is performed. More |
| 59 | specifically, transactions will continue to run after their timeout has |
| 60 | expired if they do not block on a lock request after that time. |
| 61 | A separate deadlock detection thread (or process) should always |
| 62 | be used if the application depends on timeouts; otherwise, if |
| 63 | there are no new blocked lock requests a pending timeout will |
| 64 | never trigger.</p> |
| 65 | <p>If the database environment deadlock detector has been configured with |
| 66 | the <a href="../api_reference/C/lockdetect.html#detect_DB_LOCK_EXPIRE" class="olink">DB_LOCK_EXPIRE</a> option, timeouts are the only mechanism by |
| 67 | which deadlocks will be broken. If the deadlock detector has been |
| 68 | configured with a different option, then regular deadlock detection will |
| 69 | be performed, and in addition, if timeouts have also been specified, |
| 70 | lock requests and transactions will time out as well.</p> |
| 71 | <p>Lock and transaction timeouts may be specified on a database environment |
| 72 | wide basis using the <a href="../api_reference/C/envset_timeout.html" class="olink">DB_ENV->set_timeout()</a> method. Lock timeouts may be |
| 73 | specified on a per-lock request basis using the <a href="../api_reference/C/lockvec.html" class="olink">DB_ENV->lock_vec()</a> method. Lock |
| 74 | and transaction timeouts may be specified on a per-transaction basis |
| 75 | using the <a href="../api_reference/C/txnset_timeout.html" class="olink">DB_TXN->set_timeout()</a> method. Per-lock and per-transaction |
| 76 | timeouts supersede environment wide timeouts.</p> |
| 77 | <p>For example, consider that the environment wide transaction timeout has |
| 78 | been set to 20ms, the environment wide lock timeout has been set to |
| 79 | 10ms, a transaction has been created in this environment and its timeout |
| 80 | value set to 8ms, and a specific lock request has been made on behalf |
| 81 | of this transaction where the lock timeout was set to 4ms. By default, |
| 82 | transactions in this environment will be timed out if they block waiting |
| 83 | for a lock after 20ms. The specific transaction described will be timed |
| 84 | out if it blocks waiting for a lock after 8ms. By default, any lock |
| 85 | request in this system will be timed out if it blocks longer than 10ms, |
| 86 | and the specific lock described will be timed out if it blocks longer |
| 87 | than 4ms.</p> |
| 88 | </div> |
| 89 | <div class="navfooter"> |
| 90 | <hr /> |
| 91 | <table width="100%" summary="Navigation footer"> |
| 92 | <tr> |
| 93 | <td width="40%" align="left"><a accesskey="p" href="lock_dead.html">Prev</a> </td> |
| 94 | <td width="20%" align="center"> |
| 95 | <a accesskey="u" href="lock.html">Up</a> |
| 96 | </td> |
| 97 | <td width="40%" align="right"> <a accesskey="n" href="lock_deaddbg.html">Next</a></td> |
| 98 | </tr> |
| 99 | <tr> |
| 100 | <td width="40%" align="left" valign="top">Deadlock detection </td> |
| 101 | <td width="20%" align="center"> |
| 102 | <a accesskey="h" href="index.html">Home</a> |
| 103 | </td> |
| 104 | <td width="40%" align="right" valign="top"> Deadlock debugging</td> |
| 105 | </tr> |
| 106 | </table> |
| 107 | </div> |
| 108 | </body> |
| 109 | </html> |