| 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>Handling failure in Transactional Data Store applications</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="transapp.html" title="Chapter 11. Berkeley DB Transactional Data Store Applications" /> |
| 11 | <link rel="prev" href="transapp_term.html" title="Terminology" /> |
| 12 | <link rel="next" href="transapp_app.html" title="Architecting Transactional Data Store applications" /> |
| 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">Handling failure in Transactional Data Store applications</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="transapp_term.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 11. |
| 26 | Berkeley DB Transactional Data Store Applications |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="transapp_app.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="transapp_fail"></a>Handling failure in Transactional Data Store applications</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p> |
| 42 | When building Transactional Data Store applications, there are design |
| 43 | issues to consider whenever a thread of control with open Berkeley DB |
| 44 | handles fails for any reason (where a thread of control may be either a |
| 45 | true thread or a process). |
| 46 | </p> |
| 47 | <p> |
| 48 | The first case is handling system failure: if the system fails, the |
| 49 | database environment and the databases may be left in a corrupted |
| 50 | state. In this case, recovery must be performed on the database |
| 51 | environment before any further action is taken, in order to: |
| 52 | </p> |
| 53 | <div class="itemizedlist"> |
| 54 | <ul type="disc"> |
| 55 | <li>recover the database environment resources,</li> |
| 56 | <li>release any locks or mutexes that may have been held to avoid starvation |
| 57 | as the remaining threads of control convoy behind the held locks, and</li> |
| 58 | <li>resolve any partially completed operations that may have left a database |
| 59 | in an inconsistent or corrupted state.</li> |
| 60 | </ul> |
| 61 | </div> |
| 62 | <p> |
| 63 | For details on performing recovery, see the |
| 64 | <a class="xref" href="transapp_recovery.html" title="Recovery procedures">Recovery procedures</a>. |
| 65 | </p> |
| 66 | <p> |
| 67 | The second case is handling the failure of a thread of control. There |
| 68 | are resources maintained in database environments that may be left |
| 69 | locked or corrupted if a thread of control exits unexpectedly. These |
| 70 | resources include data structure mutexes, logical database locks and |
| 71 | unresolved transactions (that is, transactions which were never aborted |
| 72 | or committed). While Transactional Data Store applications can treat |
| 73 | the failure of a thread of control in the same way as they do a system |
| 74 | failure, they have an alternative choice, the <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a> method. |
| 75 | </p> |
| 76 | <p> |
| 77 | The <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a> will return |
| 78 | <a class="link" href="program_errorret.html#program_errorret.DB_RUNRECOVERY">DB_RUNRECOVERY</a> |
| 79 | if the database |
| 80 | environment is unusable as a result of the thread of control failure. |
| 81 | (If a data structure mutex or a database write lock is left held by |
| 82 | thread of control failure, the application should not continue to use |
| 83 | the database environment, as subsequent use of the environment is |
| 84 | likely to result in threads of control convoying behind the held |
| 85 | locks.) The <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a> call will release any database read locks |
| 86 | that have been left held by the exit of a thread of control, and abort |
| 87 | any unresolved transactions. In this case, the application can |
| 88 | continue to use the database environment. |
| 89 | </p> |
| 90 | <p> |
| 91 | A Transactional Data Store application recovering from a thread of |
| 92 | control failure should call <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a>, and, if it returns success, |
| 93 | the application can continue. If <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a> returns |
| 94 | <a class="link" href="program_errorret.html#program_errorret.DB_RUNRECOVERY">DB_RUNRECOVERY</a>, |
| 95 | the application should proceed as described for |
| 96 | the case of system failure. |
| 97 | </p> |
| 98 | <p> |
| 99 | It greatly simplifies matters that recovery may be performed regardless |
| 100 | of whether recovery needs to be performed; that is, it is not an error |
| 101 | to recover a database environment for which recovery is not strictly |
| 102 | necessary. For this reason, applications should not try to determine |
| 103 | if the database environment was active when the application or system |
| 104 | failed. Instead, applications should run recovery any time the |
| 105 | <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a> method returns |
| 106 | <a class="link" href="program_errorret.html#program_errorret.DB_RUNRECOVERY">DB_RUNRECOVERY</a>, |
| 107 | or, if the application is |
| 108 | not calling the <a href="../api_reference/C/envfailchk.html" class="olink">DB_ENV->failchk()</a> method, any time any thread of control |
| 109 | accessing the database environment fails, as well as any time the |
| 110 | system reboots. |
| 111 | </p> |
| 112 | </div> |
| 113 | <div class="navfooter"> |
| 114 | <hr /> |
| 115 | <table width="100%" summary="Navigation footer"> |
| 116 | <tr> |
| 117 | <td width="40%" align="left"><a accesskey="p" href="transapp_term.html">Prev</a> </td> |
| 118 | <td width="20%" align="center"> |
| 119 | <a accesskey="u" href="transapp.html">Up</a> |
| 120 | </td> |
| 121 | <td width="40%" align="right"> <a accesskey="n" href="transapp_app.html">Next</a></td> |
| 122 | </tr> |
| 123 | <tr> |
| 124 | <td width="40%" align="left" valign="top">Terminology </td> |
| 125 | <td width="20%" align="center"> |
| 126 | <a accesskey="h" href="index.html">Home</a> |
| 127 | </td> |
| 128 | <td width="40%" align="right" valign="top"> Architecting Transactional Data Store applications</td> |
| 129 | </tr> |
| 130 | </table> |
| 131 | </div> |
| 132 | </body> |
| 133 | </html> |