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>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" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Reverse BTree Splits</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 4. Concurrency</th> 23 <td width="20%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="reversesplit"></a>Reverse BTree Splits</h2> 33 </div> 34 </div> 35 </div> 36 <p> 37 If your application is using the Btree access method, and your 38 application is repeatedly deleting then adding records to your 39 database, then you might be able to reduce lock contention by 40 turning off reverse Btree splits. 41 </p> 42 <p> 43 As pages are emptied in a database, DB attempts to 44 delete empty pages in order to keep 45 the database as small as possible and minimize search time. 46 Moreover, when a page in the database fills 47 up, DB, of course, adds additional pages 48 to make room for more data. 49 </p> 50 <p> 51 Adding and deleting pages in the database requires that the 52 writing thread lock the parent page. Consequently, as the 53 number of pages in your database diminishes, your application 54 will see increasingly more lock contention; the maximum level 55 of concurrency in a database of two pages is far smaller than 56 that in a database of 100 pages, because there are fewer pages 57 that can be locked. 58 </p> 59 <p> 60 Therefore, if you prevent the database from being reduced to a 61 minimum number of pages, you can improve your application's 62 concurrency throughput. Note, however, that you should do so 63 only if your application tends to delete and then add the same 64 data. If this is not the case, then preventing reverse Btree 65 splits can harm your database search time. 66 </p> 67 <p> 68 To turn off reverse Btree splits, 69 <span> 70 provide the 71 <code class="literal">DB_REVSPLITOFF</code> flag to the 72 73 <code class="methodname">Db::set_flags()</code> 74 method. 75 </span> 76 77 </p> 78 <p> 79 For example: 80 </p> 81 <pre class="programlisting">#include "db_cxx.h" 82 83... 84 85int main(void) 86{ 87 u_int32_t env_flags = DB_CREATE | // If the environment does not 88 // exist, create it. 89 DB_INIT_LOCK | // Initialize locking 90 DB_INIT_LOG | // Initialize locking 91 DB_INIT_MPOOL | // Initialize the cache 92 DB_THREAD | // Free-thread the env handle 93 DB_INIT_TXN; // Initialize transactions 94 95 u_int32_t db_flags = DB_CREATE | DB_AUTO_COMMIT; 96 Db *dbp = NULL; 97 const char *file_name = "mydb.db"; 98 99 std::string envHome("/export1/testEnv"); 100 DbEnv myEnv(0); 101 102 try { 103 104 myEnv.open(envHome.c_str(), env_flags, 0); 105 dbp = new Db(&myEnv, 0); 106 107 // Turn off BTree reverse split. 108 dbp=>set_flags(DB_REVSPLITOFF); 109 110 dbp->open(dbp, // Pointer to the database 111 NULL, // Txn pointer 112 file_name, // File name 113 NULL, // Logical db name 114 DB_BTREE, // Database type (using btree) 115 db_flags, // Open flags 116 0); // File mode. Using defaults 117 118 } catch(DbException &e) { 119 std::cerr << "Error opening database and environment: " 120 << file_name << ", " << envHome << std::endl; 121 std::cerr << e.what() << std::endl; 122 } 123 124 try { 125 dbp->close(dbp, 0); 126 myEnv.close(0); 127 } catch(DbException &e) { 128 std::cerr << "Error closing database and environment: " 129 << file_name << ", " << envHome << std::endl; 130 std::cerr << e.what() << std::endl; 131 return (EXIT_FAILURE); 132 } 133 134 return (EXIT_SUCCESS); 135} </pre> 136 </div> 137 <div class="navfooter"> 138 <hr /> 139 <table width="100%" summary="Navigation footer"> 140 <tr> 141 <td width="40%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td> 142 <td width="20%" align="center"> 143 <a accesskey="u" href="txnconcurrency.html">Up</a> 144 </td> 145 <td width="40%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td> 146 </tr> 147 <tr> 148 <td width="40%" align="left" valign="top">No Wait on Blocks </td> 149 <td width="20%" align="center"> 150 <a accesskey="h" href="index.html">Home</a> 151 </td> 152 <td width="40%" align="right" valign="top"> Chapter 5. Managing DB Files</td> 153 </tr> 154 </table> 155 </div> 156 </body> 157</html> 158