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

« back to all changes in this revision

Viewing changes to db/docs/ref/arch/bigpic.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: bigpic.so,v 8.29 2001/05/23 21:03:31 bostic Exp $-->
 
2
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
 
3
<!--All rights reserved.-->
 
4
<html>
 
5
<head>
 
6
<title>Berkeley DB Reference Guide: The big picture</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
<table width="100%"><tr valign=top>
 
12
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Architecture</dl></h3></td>
 
13
<td align=right><a href="../../ref/am_misc/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/arch/progmodel.html"><img src="../../images/next.gif" alt="Next"></a>
 
14
</td></tr></table>
 
15
<p>
 
16
<h1 align=center>The big picture</h1>
 
17
<p>The previous chapters in this Reference Guide have described
 
18
applications that use the Berkeley DB access methods for fast data storage
 
19
and retrieval.  The applications described in the following chapters
 
20
are similar in nature to the access method applications, but they are
 
21
also threaded and/or recoverable in the face of application or system
 
22
failure.
 
23
<p>Application code that uses only the Berkeley DB access methods might appear
 
24
as follows:
 
25
<p><blockquote><pre>switch (ret = dbp-&gt;put(dbp, NULL, &key, &data, 0)) {
 
26
case 0:
 
27
        printf("db: %s: key stored.\n", (char *)key.data);
 
28
        break;
 
29
default:
 
30
        dbp-&gt;err(dbp, ret, "dbp-&gt;put");
 
31
        exit (1);
 
32
}</pre></blockquote>
 
33
<p>The underlying Berkeley DB architecture that supports this is
 
34
<p align=center><img src="smallpic.gif" alt="small">
 
35
<p>As you can see from this diagram, the application makes calls into the
 
36
access methods, and the access methods use the underlying shared memory
 
37
buffer cache to hold recently used file pages in main memory.
 
38
<p>When applications require recoverability, their calls to the Access
 
39
Methods must be wrapped in calls to the transaction subsystem.  The
 
40
application must inform Berkeley DB where to begin and end transactions, and
 
41
must be prepared for the possibility that an operation may fail at any
 
42
particular time, causing the transaction to abort.
 
43
<p>An example of transaction-protected code might appear as follows:
 
44
<p><blockquote><pre>for (fail = 0;;) {
 
45
        /* Begin the transaction. */
 
46
        if ((ret = txn_begin(dbenv, NULL, &tid, 0)) != 0) {
 
47
                dbenv-&gt;err(dbenv, ret, "txn_begin");
 
48
                exit (1);
 
49
        }
 
50
<p>
 
51
        /* Store the key. */
 
52
        switch (ret = dbp-&gt;put(dbp, tid, &key, &data, 0)) {
 
53
        case 0:
 
54
                /* Success: commit the change. */
 
55
                printf("db: %s: key stored.\n", (char *)key.data);
 
56
                if ((ret = txn_commit(tid, 0)) != 0) {
 
57
                        dbenv-&gt;err(dbenv, ret, "txn_commit");
 
58
                        exit (1);
 
59
                }
 
60
                return (0);
 
61
        case DB_LOCK_DEADLOCK:
 
62
        default:
 
63
                /* Failure: retry the operation. */
 
64
                if ((t_ret = txn_abort(tid)) != 0) {
 
65
                        dbenv-&gt;err(dbenv, t_ret, "txn_begin");
 
66
                        exit (1);
 
67
                }
 
68
                if (++fail == MAXIMUM_RETRY)
 
69
                        return (ret);
 
70
                continue;
 
71
        }
 
72
}</pre></blockquote>
 
73
<p>In this example, the same operation is being done as before; however,
 
74
it is wrapped in transaction calls.  The transaction is started with
 
75
<a href="../../api_c/txn_begin.html">txn_begin</a> and finished with <a href="../../api_c/txn_commit.html">txn_commit</a>.  If the
 
76
operation fails due to a deadlock, the transaction is aborted using
 
77
<a href="../../api_c/txn_abort.html">txn_abort</a>, after which the operation may be retried.
 
78
<p>There are actually five major subsystems in Berkeley DB, as follows:
 
79
<p><dl compact>
 
80
<p><dt>Access Methods<dd>The access methods subsystem provides general-purpose support for
 
81
creating and accessing database files formatted as Btrees, Hashed files,
 
82
and Fixed- and Variable-length records.  These modules are useful in
 
83
the absence of transactions for applications that need fast formatted
 
84
file support.  See <a href="../../api_c/db_open.html">DB-&gt;open</a> and <a href="../../api_c/db_cursor.html">DB-&gt;cursor</a> for more
 
85
information.  These functions were already discussed in detail in the
 
86
previous chapters.
 
87
<p><dt>Memory Pool<dd>The Memory Pool subsystem is the general-purpose shared memory buffer pool
 
88
used by Berkeley DB.  This is the shared memory cache that allows multiple
 
89
processes and threads within processes to share access to databases.  This
 
90
module is useful outside of the Berkeley DB package for processes that require
 
91
portable, page-oriented, cached, shared file access.
 
92
<p><dt>Transaction<dd>The Transaction subsystem allows a group of database changes to be
 
93
treated as an atomic unit so that either all of the changes are done,
 
94
or none of the changes are done.  The transaction subsystem implements
 
95
the Berkeley DB transaction model.  This module is useful outside of the Berkeley DB
 
96
package for processes that want to transaction-protect their own data
 
97
modifications.
 
98
<p><dt>Locking<dd>The Locking subsystem is the general-purpose lock manager used by Berkeley DB.
 
99
This module is useful outside of the Berkeley DB package for processes that
 
100
require a portable, fast, configurable lock manager.
 
101
<p><dt>Logging<dd>The Logging subsystem is the write-ahead logging used to support the
 
102
Berkeley DB transaction model.  It is largely specific to the Berkeley DB package,
 
103
and unlikely to be useful elsewhere except as a supporting module for
 
104
the Berkeley DB transaction subsystem.
 
105
</dl>
 
106
<p>Here is a more complete picture of the Berkeley DB library:
 
107
<p align=center><img src="bigpic.gif" alt="large">
 
108
<p>In this model, the application makes calls to the access methods and to
 
109
the Transaction subsystem.  The access methods and Transaction subsystems
 
110
in turn make calls into the Memory Pool, Locking and Logging subsystems
 
111
on behalf of the application.
 
112
<p>The underlying subsystems can be used independently by applications.
 
113
For example, the Memory Pool subsystem can be used apart from the rest
 
114
of Berkeley DB by applications simply wanting a shared memory buffer pool, or
 
115
the Locking subsystem may be called directly by applications that are
 
116
doing their own locking outside of Berkeley DB.  However, this usage is not
 
117
common, and most applications will either use only the access methods
 
118
subsystem, or the access methods subsystem wrapped in calls to the Berkeley DB
 
119
transaction interfaces.
 
120
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/am_misc/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/arch/progmodel.html"><img src="../../images/next.gif" alt="Next"></a>
 
121
</td></tr></table>
 
122
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
 
123
</body>
 
124
</html>