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.62.4" /> 9 <link rel="home" 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="previous" 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></div> 36 </div> 37 <p> 38 If your application is using the Btree access method, and your 39 application is repeatedly deleting then adding records to your 40 database, then you might be able to reduce lock contention by 41 turning off reverse Btree splits. 42 </p> 43 <p> 44 As pages are emptied in a database, DB attempts to 45 delete empty pages in order to keep 46 the database as small as possible and minimize search time. 47 Moreover, when a page in the database fills 48 up, DB, of course, adds additional pages 49 to make room for more data. 50 </p> 51 <p> 52 Adding and deleting pages in the database requires that the 53 writing thread lock the parent page. Consequently, as the 54 number of pages in your database diminishes, your application 55 will see increasingly more lock contention; the maximum level 56 of concurrency in a database of two pages is far smaller than 57 that in a database of 100 pages, because there are fewer pages 58 that can be locked. 59 </p> 60 <p> 61 Therefore, if you prevent the database from being reduced to a 62 minimum number of pages, you can improve your application's 63 concurrency throughput. Note, however, that you should do so 64 only if your application tends to delete and then add the same 65 data. If this is not the case, then preventing reverse Btree 66 splits can harm your database search time. 67 </p> 68 <p> 69 To turn off reverse Btree splits, 70 71 <span> 72 set 73 <tt class="methodname">DatabaseConfig.setReverseSplitOff()</tt>. 74 to <tt class="literal">true</tt>. 75 </span> 76 </p> 77 <p> 78 For example: 79 </p> 80 <pre class="programlisting">package db.txn; 81 82import com.sleepycat.db.Database; 83import com.sleepycat.db.DatabaseType; 84import com.sleepycat.db.DatabaseConfig; 85import com.sleepycat.db.DatabaseException; 86import com.sleepycat.db.Environment; 87import com.sleepycat.db.EnvironmentConfig; 88 89import java.io.File; 90import java.io.FileNotFoundException; 91 92... 93 94Database myDatabase = null; 95Environment myEnv = null; 96try { 97 EnvironmentConfig myEnvConfig = new EnvironmentConfig(); 98 myEnvConfig.setInitializeCache(true); 99 myEnvConfig.setInitializeLocking(true); 100 myEnvConfig.setInitializeLogging(true); 101 myEnvConfig.setTransactional(true); 102 103 myEnv = new Environment(new File("/my/env/home"), 104 myEnvConfig); 105 106 // Open the database. 107 DatabaseConfig dbConfig = new DatabaseConfig(); 108 dbConfig.setTransactional(true); 109 dbConfig.setType(DatabaseType.BTREE); 110 111 // Set BTree reverse split to off 112 dbConfig.setReverseSplitOff(true); 113 114 myDatabase = myEnv.openDatabase(null, // txn handle 115 "sampleDatabase", // db file name 116 "null", // db name 117 dbConfig); 118} catch (DatabaseException de) { 119 // Exception handling goes here 120} catch (FileNotFoundException fnfe) { 121 // Exception handling goes here 122}</pre> 123 <p> 124 Or, if you are using the DPL: 125</p> 126 <pre class="programlisting">package db.txn; 127 128import com.sleepycat.db.Database; 129import com.sleepycat.db.DatabaseType; 130import com.sleepycat.db.DatabaseConfig; 131import com.sleepycat.db.DatabaseException; 132import com.sleepycat.db.Environment; 133import com.sleepycat.db.EnvironmentConfig; 134 135import java.io.File; 136import java.io.FileNotFoundException; 137 138... 139 140EntityStore myStore = null; 141Environment myEnv = null; 142try { 143 EnvironmentConfig myEnvConfig = new EnvironmentConfig(); 144 myEnvConfig.setInitializeCache(true); 145 myEnvConfig.setInitializeLocking(true); 146 myEnvConfig.setInitializeLogging(true); 147 myEnvConfig.setTransactional(true); 148 149 myEnv = new Environment(new File("/my/env/home"), 150 myEnvConfig); 151 152 // Configure the store. 153 StoreConfig myStoreConfig = new StoreConfig(); 154 myStoreConfig.setAllowCreate(true); 155 myStoreConfig.setTransactional(true); 156 157 // Configure the underlying database. 158 DatabaseConfig dbConfig = new DatabaseConfig(); 159 dbConfig.setTransactional(true); 160 dbConfig.setAllowCreate(true); 161 dbConfig.setType(DatabaseType.BTREE); 162 163 // Set BTree reverse split to off 164 dbConfig.setReverseSplitOff(true); 165 166 // Instantiate the store 167 myStore = new EntityStore(myEnv, "store_name", myStoreConfig); 168 169 // Set the DatabaseConfig object, so that the underlying 170 // database is configured for uncommitted reads. 171 myStore.setPrimaryConfig(SomeEntityClass.class, dbConfig); 172 173} catch (DatabaseException de) { 174 // Exception handling goes here 175} catch (FileNotFoundException fnfe) { 176 // Exception handling goes here 177}</pre> 178 </div> 179 <div class="navfooter"> 180 <hr /> 181 <table width="100%" summary="Navigation footer"> 182 <tr> 183 <td width="40%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a>��</td> 184 <td width="20%" align="center"> 185 <a accesskey="u" href="txnconcurrency.html">Up</a> 186 </td> 187 <td width="40%" align="right">��<a accesskey="n" href="filemanagement.html">Next</a></td> 188 </tr> 189 <tr> 190 <td width="40%" align="left" valign="top">No Wait on Blocks��</td> 191 <td width="20%" align="center"> 192 <a accesskey="h" href="index.html">Home</a> 193 </td> 194 <td width="40%" align="right" valign="top">��Chapter��5.��Managing DB Files</td> 195 </tr> 196 </table> 197 </div> 198 </body> 199</html> 200