~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/docs/ref/program/errorret.html

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--$Id: errorret.so,v 10.41 2001/05/15 17:08:38 bostic Exp $-->
 
2
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
 
3
<!--All rights reserved.-->
 
4
<html>
 
5
<head>
 
6
<title>Berkeley DB Reference Guide: Error returns to applications</title>
 
7
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
 
8
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,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>
 
12
<table width="100%"><tr valign=top>
 
13
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Programmer Notes</dl></h3></td>
 
14
<td align=right><a href="../../ref/program/appsignals.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/program/environ.html"><img src="../../images/next.gif" alt="Next"></a>
 
15
</td></tr></table>
 
16
<p>
 
17
<h1 align=center>Error returns to applications</h1>
 
18
<p>Except for the historic <a href="../../api_c/dbm.html">dbm</a>, <a href="../../api_c/dbm.html">ndbm</a>, and <a href="../../api_c/hsearch.html">hsearch</a>
 
19
interfaces, Berkeley DB does not use the global variable <b>errno</b> to
 
20
return error values.  The return values for all Berkeley DB functions are
 
21
grouped into the following three categories:
 
22
<p><dl compact>
 
23
<p><dt>0<dd>A return value of 0 indicates that the operation was successful.
 
24
<p><dt>&gt; 0<dd>A return value that is greater than 0 indicates that there was a system
 
25
error.  The <b>errno</b> value returned by the system is returned by
 
26
the function; for example, when a Berkeley DB function is unable to allocate
 
27
memory, the return value from the function will be ENOMEM.
 
28
<p><dt>&lt; 0<dd>A return value that is less than 0 indicates a condition that was not
 
29
a system failure, but was not an unqualified success, either.  For
 
30
example, a routine to retrieve a key/data pair from the database may
 
31
return DB_NOTFOUND when the key/data pair does not appear in
 
32
the database; as opposed to the value of 0, which would be returned if
 
33
the key/data pair were found in the database.
 
34
<p><a name="3"><!--meow--></a>
 
35
All values returned by Berkeley DB functions are less than 0 in order to avoid
 
36
conflict with possible values of <b>errno</b>.  Specifically, Berkeley DB
 
37
reserves all values from -30,800 to -30,999 to itself as possible error
 
38
values.  There are a few Berkeley DB interfaces where it is possible for an
 
39
application function to be called by a Berkeley DB function and subsequently
 
40
fail with an application-specific return.  Such failure returns will be
 
41
passed back to the function that originally called a Berkeley DB interface.
 
42
To avoid ambiguity about the cause of the error, error values separate
 
43
from the Berkeley DB error name space should be used.
 
44
</dl>
 
45
<p>Although possible error returns are specified by each individual function's
 
46
manual page, there are a few error returns that deserve general mention:
 
47
<h3><a name="DB_NOTFOUND">DB_NOTFOUND</a> and <a name="DB_KEYEMPTY">DB_KEYEMPTY</a></h3>
 
48
<p>There are two special return values that are similar in meaning and that
 
49
are returned in similar situations, and therefore might be confused:
 
50
DB_NOTFOUND and DB_KEYEMPTY.
 
51
<p>The DB_NOTFOUND error return indicates that the requested key/data
 
52
pair did not exist in the database or that start-of- or end-of-file has
 
53
been reached by a cursor.
 
54
<p>The DB_KEYEMPTY error return indicates that the requested
 
55
key/data pair logically exists but was never explicitly created by the
 
56
application (the Recno and Queue access methods will automatically
 
57
create key/data pairs under some circumstances; see <a href="../../api_c/db_open.html">DB-&gt;open</a>
 
58
for more information), or that the requested key/data pair was deleted
 
59
and never re-created.  In addition, the Queue access method will return
 
60
DB_KEYEMPTY for records that were created as part of a
 
61
transaction that was later aborted and never re-created.
 
62
<h3><a name="DB_KEYEXIST">DB_KEYEXIST</a></h3>
 
63
<p>The DB_KEYEXIST error return indicates the <a href="../../api_c/db_put.html#DB_NOOVERWRITE">DB_NOOVERWRITE</a>
 
64
option was specified to the <a href="../../api_c/db_put.html">DB-&gt;put</a> function and the key already exists
 
65
in the database.
 
66
<h3><a name="DB_INCOMPLETE">DB_INCOMPLETE</a></h3>
 
67
<p>When a database cannot be flushed to disk by <a href="../../api_c/db_close.html">DB-&gt;close</a> or
 
68
<a href="../../api_c/db_sync.html">DB-&gt;sync</a>, or by the underlying Memory Pool subsystem methods,
 
69
<a href="../../api_c/memp_fsync.html">memp_fsync</a> and <a href="../../api_c/memp_sync.html">memp_sync</a>, DB_INCOMPLETE may be
 
70
returned to the application.
 
71
<p>In the case of <a href="../../api_c/db_close.html">DB-&gt;close</a> and <a href="../../api_c/db_sync.html">DB-&gt;sync</a>, the only reason
 
72
for a return of DB_INCOMPLETE is if another thread of control
 
73
was writing pages in the underlying database file at the same time as
 
74
the <a href="../../api_c/db_close.html">DB-&gt;close</a> or <a href="../../api_c/db_sync.html">DB-&gt;sync</a> call was made. For this
 
75
reason, a return of DB_INCOMPLETE can normally be ignored; or,
 
76
in cases where it is a possible return value, <a href="../../api_c/db_sync.html">DB-&gt;sync</a> should
 
77
probably never have been called, or the <a href="../../api_c/db_close.html#DB_NOSYNC">DB_NOSYNC</a> option should
 
78
have been specified to <a href="../../api_c/db_close.html">DB-&gt;close</a>.
 
79
<p>In the case of <a href="../../api_c/memp_fsync.html">memp_fsync</a> or <a href="../../api_c/memp_sync.html">memp_sync</a> (or other Berkeley DB
 
80
interfaces that call those functions, <a href="../../api_c/txn_checkpoint.html">txn_checkpoint</a> for
 
81
example), a return of DB_INCOMPLETE indicates that the database
 
82
environment is under heavy load and the checkpoint was unable to
 
83
complete because there were pages that could not be written at this
 
84
time.  This is not a fatal error, and the call should be retried.
 
85
<a name="4"><!--meow--></a>
 
86
<h3><a name="DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a></h3>
 
87
<p>When multiple threads of control are modifying the database, there is
 
88
normally the potential for deadlock. In Berkeley DB, deadlock is signified by
 
89
an error return from the Berkeley DB function of the value
 
90
DB_LOCK_DEADLOCK.  Whenever a Berkeley DB function returns
 
91
DB_LOCK_DEADLOCK, the enclosing transaction should be aborted.
 
92
<p>Any Berkeley DB function that attempts to acquire locks can potentially return
 
93
DB_LOCK_DEADLOCK.  Practically speaking, the safest way to deal
 
94
with applications that can deadlock is to handle a
 
95
DB_LOCK_DEADLOCK return from any Berkeley DB access method call.
 
96
<h3><a name="DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a></h3>
 
97
<p>When multiple threads of control are modifying the database, there is
 
98
normally the potential for deadlock.  In order to avoid deadlock,
 
99
applications may specify -- on a per-transaction basis -- that if a lock
 
100
is unavailable, the Berkeley DB operation should return immediately instead
 
101
of waiting on the lock.  The error return in this case will be
 
102
DB_LOCK_NOTGRANTED.  Whenever a Berkeley DB function returns
 
103
DB_LOCK_NOTGRANTED, the enclosing transaction should be
 
104
aborted.
 
105
<h3><a name="DB_RUNRECOVERY">DB_RUNRECOVERY</a></h3>
 
106
<p>There exists a class of errors that Berkeley DB considers fatal to an entire
 
107
Berkeley DB environment.  An example of this type of error is a corrupted
 
108
database or a log write failure because the disk is out of free space.
 
109
The only way to recover from these failures is to have all threads of
 
110
control exit the Berkeley DB environment, run recovery of the environment, and
 
111
re-enter Berkeley DB. (It is not strictly necessary that the processes exit,
 
112
although that is the only way to recover system resources, such as file
 
113
descriptors and memory, allocated by Berkeley DB.)
 
114
<p>When this type of error is encountered, the error value
 
115
DB_RUNRECOVERY is returned. This error can be returned by any
 
116
Berkeley DB interface.  Once DB_RUNRECOVERY is returned by any
 
117
interface, it will be returned from all subsequent Berkeley DB calls made by
 
118
any threads of control participating in the environment.
 
119
<p>Optionally, applications may also specify a fatal-error callback function
 
120
using the <a href="../../api_c/env_set_paniccall.html">DB_ENV-&gt;set_paniccall</a> function.  This callback function will be
 
121
called with two arguments: a reference to the DB_ENV structure
 
122
associated with the environment and the <b>errno</b> value
 
123
associated with the underlying error that caused the problem.
 
124
<p>Applications can handle such fatal errors in one of two ways: by checking
 
125
for DB_RUNRECOVERY as part of their normal Berkeley DB error return
 
126
checking, similarly to DB_LOCK_DEADLOCK or any other error, or
 
127
by simply exiting the application when the callback function is called
 
128
in applications that have no cleanup processing of their own.
 
129
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/program/appsignals.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/program/environ.html"><img src="../../images/next.gif" alt="Next"></a>
 
130
</td></tr></table>
 
131
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
 
132
</body>
 
133
</html>