| 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>Error returns to 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="program.html" title="Chapter 15. Programmer Notes" /> |
| 11 | <link rel="prev" href="program.html" title="Chapter 15. Programmer Notes" /> |
| 12 | <link rel="next" href="program_environ.html" title="Environment variables" /> |
| 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">Error returns to applications</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="program.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 15. |
| 26 | Programmer Notes |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="program_environ.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="program_errorret"></a>Error returns to applications</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p> |
| 42 | Except for the historic <a href="../api_reference/C/dbm.html" class="olink">dbm</a>, <a href="../api_reference/C/dbm.html" class="olink">ndbm</a> and <a href="../api_reference/C/hsearch.html" class="olink">hsearch</a> interfaces, Berkeley DB |
| 43 | does not use the global variable <code class="literal">errno</code> to return |
| 44 | error values. The return values for all Berkeley DB functions are |
| 45 | grouped into the following three categories: |
| 46 | </p> |
| 47 | <div class="variablelist"> |
| 48 | <dl> |
| 49 | <dt> |
| 50 | <span class="term">0</span> |
| 51 | </dt> |
| 52 | <dd>A return value of 0 indicates that the operation was successful.</dd> |
| 53 | <dt> |
| 54 | <span class="term">> 0</span> |
| 55 | </dt> |
| 56 | <dd>A return value that is greater than 0 indicates that there was a system |
| 57 | error. The <span class="bold"><strong>errno</strong></span> value returned by the system is returned by |
| 58 | the function; for example, when a Berkeley DB function is unable to allocate |
| 59 | memory, the return value from the function will be ENOMEM.</dd> |
| 60 | <dt> |
| 61 | <span class="term">< 0</span> |
| 62 | </dt> |
| 63 | <dd>A return value that is less than 0 indicates a condition that was not |
| 64 | a system failure, but was not an unqualified success, either. For |
| 65 | example, a routine to retrieve a key/data pair from the database may |
| 66 | return DB_NOTFOUND when the key/data pair does not appear in |
| 67 | the database; as opposed to the value of 0, which would be returned if |
| 68 | the key/data pair were found in the database. |
| 69 | <p> |
| 70 | All values returned by Berkeley DB functions are less than 0 in order to avoid |
| 71 | conflict with possible values of <span class="bold"><strong>errno</strong></span>. Specifically, Berkeley DB |
| 72 | reserves all values from -30,800 to -30,999 to itself as possible error |
| 73 | values. There are a few Berkeley DB interfaces where it is possible for an |
| 74 | application function to be called by a Berkeley DB function and subsequently |
| 75 | fail with an application-specific return. Such failure returns will be |
| 76 | passed back to the function that originally called a Berkeley DB interface. |
| 77 | To avoid ambiguity about the cause of the error, error values separate |
| 78 | from the Berkeley DB error name space should be used.</p></dd> |
| 79 | </dl> |
| 80 | </div> |
| 81 | <p> |
| 82 | Although possible error returns are specified by each individual |
| 83 | function's manual page, there are a few error returns that deserve |
| 84 | general mention: |
| 85 | </p> |
| 86 | <p> |
| 87 | <span class="bold"><strong>DB_NOTFOUND and DB_KEYEMPTY</strong></span> |
| 88 | </p> |
| 89 | <p>There are two special return values that are similar in meaning and that |
| 90 | are returned in similar situations, and therefore might be confused: |
| 91 | DB_NOTFOUND and DB_KEYEMPTY.</p> |
| 92 | <p><a id="program_errorret.DB_NOTFOUND"></a>The DB_NOTFOUND error return indicates that the requested key/data |
| 93 | pair did not exist in the database or that start-of- or end-of-file has |
| 94 | been reached by a cursor.</p> |
| 95 | <p><a id="program_errorret.DB_KEYEMPTY"></a>The DB_KEYEMPTY error return indicates that the requested |
| 96 | key/data pair logically exists but was never explicitly created by the |
| 97 | application (the Recno and Queue access methods will automatically |
| 98 | create key/data pairs under some circumstances; see <a href="../api_reference/C/dbopen.html" class="olink">DB->open()</a> |
| 99 | for more information), or that the requested key/data pair was deleted |
| 100 | and never re-created. In addition, the Queue access method will return |
| 101 | DB_KEYEMPTY for records that were created as part of a |
| 102 | transaction that was later aborted and never re-created.</p> |
| 103 | <p> |
| 104 | <span class="bold"><strong>DB_KEYEXIST</strong></span> |
| 105 | </p> |
| 106 | <p><a id="program_errorret.DB_KEYEXIST"></a> |
| 107 | The DB_KEYEXIST error return indicates the <a href="../api_reference/C/dbput.html#put_DB_NOOVERWRITE" class="olink">DB_NOOVERWRITE</a> option was specified |
| 108 | when inserting a key/data pair into the database and the key already |
| 109 | exists in the database, or the <a href="../api_reference/C/dbput.html#put_DB_NODUPDATA" class="olink">DB_NODUPDATA</a> option was specified and the |
| 110 | key/data pair already exists in the data. |
| 111 | </p> |
| 112 | <p> |
| 113 | <span class="bold"><strong>DB_LOCK_DEADLOCK</strong></span> |
| 114 | </p> |
| 115 | <p><a id="program_errorret.DB_LOCK_DEADLOCK"></a> |
| 116 | When multiple threads of control are modifying the database, there is |
| 117 | normally the potential for deadlock. In Berkeley DB, deadlock is |
| 118 | signified by an error return from the Berkeley DB function of the value |
| 119 | DB_LOCK_DEADLOCK. Whenever a Berkeley DB function returns |
| 120 | DB_LOCK_DEADLOCK, the enclosing transaction should be aborted. |
| 121 | </p> |
| 122 | <p> |
| 123 | Any Berkeley DB function that attempts to acquire locks can potentially |
| 124 | return DB_LOCK_DEADLOCK. Practically speaking, the safest way to deal |
| 125 | with applications that can deadlock is to anticipate a DB_LOCK_DEADLOCK |
| 126 | return from any <a href="../api_reference/C/db.html" class="olink">DB</a> or <a href="../api_reference/C/dbc.html" class="olink">DBC</a> handle method call, or any <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> |
| 127 | handle method call that references a database, including the database's |
| 128 | backing physical file. |
| 129 | </p> |
| 130 | <p> |
| 131 | <span class="bold"><strong>DB_LOCK_NOTGRANTED</strong></span> |
| 132 | </p> |
| 133 | <p><a id="program_errorret.DB_LOCK_NOTGRANTED"></a> |
| 134 | If a lock is requested from the <a href="../api_reference/C/lockget.html" class="olink">DB_ENV->lock_get()</a> or <a href="../api_reference/C/lockvec.html" class="olink">DB_ENV->lock_vec()</a> methods with the |
| 135 | <a href="../api_reference/C/lockvec.html#vec_DB_LOCK_NOWAIT" class="olink">DB_LOCK_NOWAIT</a> flag specified, the method will return DB_LOCK_NOTGRANTED if the lock |
| 136 | is not immediately available. |
| 137 | </p> |
| 138 | <p> |
| 139 | If the <a href="../api_reference/C/envset_flags.html#envset_flags_DB_TIME_NOTGRANTED" class="olink">DB_TIME_NOTGRANTED</a> flag is specified to the <a href="../api_reference/C/envset_flags.html" class="olink">DB_ENV->set_flags()</a> method, |
| 140 | database calls timing out based on lock or transaction timeout values |
| 141 | will return DB_LOCK_NOTGRANTED instead of DB_LOCK_DEADLOCK. |
| 142 | </p> |
| 143 | <p> |
| 144 | <span class="bold"><strong>DB_RUNRECOVERY</strong></span> |
| 145 | </p> |
| 146 | <p><a id="program_errorret.DB_RUNRECOVERY"></a> |
| 147 | There exists a class of errors that Berkeley DB considers fatal to an |
| 148 | entire Berkeley DB environment. An example of this type of error is a |
| 149 | corrupted database page. The only way to recover from these failures |
| 150 | is to have all threads of control exit the Berkeley DB environment, run |
| 151 | recovery of the environment, and re-enter Berkeley DB. (It is not |
| 152 | strictly necessary that the processes exit, although that is the only |
| 153 | way to recover system resources, such as file descriptors and memory, |
| 154 | allocated by Berkeley DB.) |
| 155 | </p> |
| 156 | <p> |
| 157 | When this type of error is encountered, the error value DB_RUNRECOVERY |
| 158 | is returned. This error can be returned by any Berkeley DB interface. |
| 159 | Once DB_RUNRECOVERY is returned by any interface, it will be returned |
| 160 | from all subsequent Berkeley DB calls made by any threads of control |
| 161 | participating in the environment. |
| 162 | </p> |
| 163 | <p> |
| 164 | Applications can handle such fatal errors in one of two ways: first, by |
| 165 | checking for DB_RUNRECOVERY as part of their normal Berkeley DB error |
| 166 | return checking, similarly to DB_LOCK_DEADLOCK or any other error. |
| 167 | Alternatively, applications can specify a fatal-error callback function |
| 168 | using the <a href="../api_reference/C/envevent_notify.html" class="olink">DB_ENV->set_event_notify()</a> method. Applications with no cleanup |
| 169 | processing of their own should simply exit from the callback function. |
| 170 | </p> |
| 171 | <p> |
| 172 | <span class="bold"><strong>DB_SECONDARY_BAD</strong></span> |
| 173 | </p> |
| 174 | <p><a id="program_error_ret.DB_SECONDARY_BAD"></a> |
| 175 | The DB_SECONDARY_BAD error is returned if a secondary index has been |
| 176 | corrupted. This may be the result of an application operating on |
| 177 | related databases without first associating them. |
| 178 | </p> |
| 179 | </div> |
| 180 | <div class="navfooter"> |
| 181 | <hr /> |
| 182 | <table width="100%" summary="Navigation footer"> |
| 183 | <tr> |
| 184 | <td width="40%" align="left"><a accesskey="p" href="program.html">Prev</a> </td> |
| 185 | <td width="20%" align="center"> |
| 186 | <a accesskey="u" href="program.html">Up</a> |
| 187 | </td> |
| 188 | <td width="40%" align="right"> <a accesskey="n" href="program_environ.html">Next</a></td> |
| 189 | </tr> |
| 190 | <tr> |
| 191 | <td width="40%" align="left" valign="top">Chapter 15. |
| 192 | Programmer Notes |
| 193 | </td> |
| 194 | <td width="20%" align="center"> |
| 195 | <a accesskey="h" href="index.html">Home</a> |
| 196 | </td> |
| 197 | <td width="40%" align="right" valign="top"> Environment variables</td> |
| 198 | </tr> |
| 199 | </table> |
| 200 | </div> |
| 201 | </body> |
| 202 | </html> |