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">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Reverse BTree Splits</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="Getting Started with Berkeley DB Transaction Processing" />
10 <link rel="up" href="txnconcurrency.html" title="Chapter 4. Concurrency" />
11 <link rel="prev" href="txnnowait.html" title="No Wait on Blocks" />
12 <link rel="next" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">Reverse BTree Splits</th>
24 <td width="20%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 4. Concurrency</th>
26 <td width="20%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
35 <h2 class="title" style="clear: both"><a id="reversesplit"></a>Reverse BTree Splits</h2>
40 If your application is using the Btree access method, and your
41 application is repeatedly deleting then adding records to your
42 database, then you might be able to reduce lock contention by
43 turning off reverse Btree splits.
46 As pages are emptied in a database, DB attempts to
47 delete empty pages in order to keep
48 the database as small as possible and minimize search time.
49 Moreover, when a page in the database fills
50 up, DB, of course, adds additional pages
51 to make room for more data.
54 Adding and deleting pages in the database requires that the
55 writing thread lock the parent page. Consequently, as the
56 number of pages in your database diminishes, your application
57 will see increasingly more lock contention; the maximum level
58 of concurrency in a database of two pages is far smaller than
59 that in a database of 100 pages, because there are fewer pages
63 Therefore, if you prevent the database from being reduced to a
64 minimum number of pages, you can improve your application's
65 concurrency throughput. Note, however, that you should do so
66 only if your application tends to delete and then add the same
67 data. If this is not the case, then preventing reverse Btree
68 splits can harm your database search time.
71 To turn off reverse Btree splits,
74 <code class="literal">DB_REVSPLITOFF</code> flag to the
76 <code class="methodname">Db::set_flags()</code>
84 <pre class="programlisting">#include "db_cxx.h"
90 u_int32_t env_flags = DB_CREATE | // If the environment does not
92 DB_INIT_LOCK | // Initialize locking
93 DB_INIT_LOG | // Initialize locking
94 DB_INIT_MPOOL | // Initialize the cache
95 DB_THREAD | // Free-thread the env handle
96 DB_INIT_TXN; // Initialize transactions
98 u_int32_t db_flags = DB_CREATE | DB_AUTO_COMMIT;
100 const char *file_name = "mydb.db";
102 std::string envHome("/export1/testEnv");
107 myEnv.open(envHome.c_str(), env_flags, 0);
108 dbp = new Db(&myEnv, 0);
110 // Turn off BTree reverse split.
111 dbp=>set_flags(DB_REVSPLITOFF);
113 dbp->open(dbp, // Pointer to the database
115 file_name, // File name
116 NULL, // Logical db name
117 DB_BTREE, // Database type (using btree)
118 db_flags, // Open flags
119 0); // File mode. Using defaults
121 } catch(DbException &e) {
122 std::cerr << "Error opening database and environment: "
123 << file_name << ", " << envHome << std::endl;
124 std::cerr << e.what() << std::endl;
128 dbp->close(dbp, 0);
130 } catch(DbException &e) {
131 std::cerr << "Error closing database and environment: "
132 << file_name << ", " << envHome << std::endl;
133 std::cerr << e.what() << std::endl;
134 return (EXIT_FAILURE);
137 return (EXIT_SUCCESS);
140 <div class="navfooter">
142 <table width="100%" summary="Navigation footer">
144 <td width="40%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td>
145 <td width="20%" align="center">
146 <a accesskey="u" href="txnconcurrency.html">Up</a>
148 <td width="40%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td>
151 <td width="40%" align="left" valign="top">No Wait on Blocks </td>
152 <td width="20%" align="center">
153 <a accesskey="h" href="index.html">Home</a>
155 <td width="40%" align="right" valign="top"> Chapter 5. Managing DB Files</td>