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 70 <span> 71 set 72 <code class="methodname">DatabaseConfig.setReverseSplitOff()</code>. 73 to <code class="literal">true</code>. 74 </span> 75 </p> 76 <p> 77 For example: 78 </p> 79 <pre class="programlisting">package db.txn; 80 81import com.sleepycat.db.Database; 82import com.sleepycat.db.DatabaseType; 83import com.sleepycat.db.DatabaseConfig; 84import com.sleepycat.db.DatabaseException; 85import com.sleepycat.db.Environment; 86import com.sleepycat.db.EnvironmentConfig; 87 88import java.io.File; 89import java.io.FileNotFoundException; 90 91... 92 93Database myDatabase = null; 94Environment myEnv = null; 95try { 96 EnvironmentConfig myEnvConfig = new EnvironmentConfig(); 97 myEnvConfig.setInitializeCache(true); 98 myEnvConfig.setInitializeLocking(true); 99 myEnvConfig.setInitializeLogging(true); 100 myEnvConfig.setTransactional(true); 101 102 myEnv = new Environment(new File("/my/env/home"), 103 myEnvConfig); 104 105 // Open the database. 106 DatabaseConfig dbConfig = new DatabaseConfig(); 107 dbConfig.setTransactional(true); 108 dbConfig.setType(DatabaseType.BTREE); 109 110 // Set BTree reverse split to off 111 dbConfig.setReverseSplitOff(true); 112 113 myDatabase = myEnv.openDatabase(null, // txn handle 114 "sampleDatabase", // db file name 115 "null", // db name 116 dbConfig); 117} catch (DatabaseException de) { 118 // Exception handling goes here 119} catch (FileNotFoundException fnfe) { 120 // Exception handling goes here 121}</pre> 122 <p> 123 Or, if you are using the DPL: 124</p> 125 <pre class="programlisting">package db.txn; 126 127import com.sleepycat.db.Database; 128import com.sleepycat.db.DatabaseType; 129import com.sleepycat.db.DatabaseConfig; 130import com.sleepycat.db.DatabaseException; 131import com.sleepycat.db.Environment; 132import com.sleepycat.db.EnvironmentConfig; 133 134import java.io.File; 135import java.io.FileNotFoundException; 136 137... 138 139EntityStore myStore = null; 140Environment myEnv = null; 141try { 142 EnvironmentConfig myEnvConfig = new EnvironmentConfig(); 143 myEnvConfig.setInitializeCache(true); 144 myEnvConfig.setInitializeLocking(true); 145 myEnvConfig.setInitializeLogging(true); 146 myEnvConfig.setTransactional(true); 147 148 myEnv = new Environment(new File("/my/env/home"), 149 myEnvConfig); 150 151 // Configure the store. 152 StoreConfig myStoreConfig = new StoreConfig(); 153 myStoreConfig.setAllowCreate(true); 154 myStoreConfig.setTransactional(true); 155 156 // Configure the underlying database. 157 DatabaseConfig dbConfig = new DatabaseConfig(); 158 dbConfig.setTransactional(true); 159 dbConfig.setAllowCreate(true); 160 dbConfig.setType(DatabaseType.BTREE); 161 162 // Set BTree reverse split to off 163 dbConfig.setReverseSplitOff(true); 164 165 // Instantiate the store 166 myStore = new EntityStore(myEnv, "store_name", myStoreConfig); 167 168 // Set the DatabaseConfig object, so that the underlying 169 // database is configured for uncommitted reads. 170 myStore.setPrimaryConfig(SomeEntityClass.class, dbConfig); 171 172} catch (DatabaseException de) { 173 // Exception handling goes here 174} catch (FileNotFoundException fnfe) { 175 // Exception handling goes here 176}</pre> 177 </div> 178 <div class="navfooter"> 179 <hr /> 180 <table width="100%" summary="Navigation footer"> 181 <tr> 182 <td width="40%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td> 183 <td width="20%" align="center"> 184 <a accesskey="u" href="txnconcurrency.html">Up</a> 185 </td> 186 <td width="40%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td> 187 </tr> 188 <tr> 189 <td width="40%" align="left" valign="top">No Wait on Blocks </td> 190 <td width="20%" align="center"> 191 <a accesskey="h" href="index.html">Home</a> 192 </td> 193 <td width="40%" align="right" valign="top"> Chapter 5. Managing DB Files</td> 194 </tr> 195 </table> 196 </div> 197 </body> 198</html> 199