1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Reverse BTree Splits</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
<link rel="up" href="txnconcurrency.html" title="Chapter 4. Concurrency" />
<link rel="prev" href="txnnowait.html" title="No Wait on Blocks" />
<link rel="next" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
</head>
<body>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Reverse BTree Splits</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td>
<th width="60%" align="center">Chapter 4. Concurrency</th>
<td width="20%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="reversesplit"></a>Reverse BTree Splits</h2>
</div>
</div>
</div>
<p>
If your application is using the Btree access method, and your
application is repeatedly deleting then adding records to your
database, then you might be able to reduce lock contention by
turning off reverse Btree splits.
</p>
<p>
As pages are emptied in a database, DB attempts to
delete empty pages in order to keep
the database as small as possible and minimize search time.
Moreover, when a page in the database fills
up, DB, of course, adds additional pages
to make room for more data.
</p>
<p>
Adding and deleting pages in the database requires that the
writing thread lock the parent page. Consequently, as the
number of pages in your database diminishes, your application
will see increasingly more lock contention; the maximum level
of concurrency in a database of two pages is far smaller than
that in a database of 100 pages, because there are fewer pages
that can be locked.
</p>
<p>
Therefore, if you prevent the database from being reduced to a
minimum number of pages, you can improve your application's
concurrency throughput. Note, however, that you should do so
only if your application tends to delete and then add the same
data. If this is not the case, then preventing reverse Btree
splits can harm your database search time.
</p>
<p>
To turn off reverse Btree splits,
<span>
set
<code class="methodname">DatabaseConfig.setReverseSplitOff()</code>.
to <code class="literal">true</code>.
</span>
</p>
<p>
For example:
</p>
<pre class="programlisting">package db.txn;
import com.sleepycat.db.Database;
import com.sleepycat.db.DatabaseType;
import com.sleepycat.db.DatabaseConfig;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import java.io.File;
import java.io.FileNotFoundException;
...
Database myDatabase = null;
Environment myEnv = null;
try {
EnvironmentConfig myEnvConfig = new EnvironmentConfig();
myEnvConfig.setInitializeCache(true);
myEnvConfig.setInitializeLocking(true);
myEnvConfig.setInitializeLogging(true);
myEnvConfig.setTransactional(true);
myEnv = new Environment(new File("/my/env/home"),
myEnvConfig);
// Open the database.
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setType(DatabaseType.BTREE);
// Set BTree reverse split to off
dbConfig.setReverseSplitOff(true);
myDatabase = myEnv.openDatabase(null, // txn handle
"sampleDatabase", // db file name
"null", // db name
dbConfig);
} catch (DatabaseException de) {
// Exception handling goes here
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
}</pre>
<p>
Or, if you are using the DPL:
</p>
<pre class="programlisting">package db.txn;
import com.sleepycat.db.Database;
import com.sleepycat.db.DatabaseType;
import com.sleepycat.db.DatabaseConfig;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import java.io.File;
import java.io.FileNotFoundException;
...
EntityStore myStore = null;
Environment myEnv = null;
try {
EnvironmentConfig myEnvConfig = new EnvironmentConfig();
myEnvConfig.setInitializeCache(true);
myEnvConfig.setInitializeLocking(true);
myEnvConfig.setInitializeLogging(true);
myEnvConfig.setTransactional(true);
myEnv = new Environment(new File("/my/env/home"),
myEnvConfig);
// Configure the store.
StoreConfig myStoreConfig = new StoreConfig();
myStoreConfig.setAllowCreate(true);
myStoreConfig.setTransactional(true);
// Configure the underlying database.
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
dbConfig.setType(DatabaseType.BTREE);
// Set BTree reverse split to off
dbConfig.setReverseSplitOff(true);
// Instantiate the store
myStore = new EntityStore(myEnv, "store_name", myStoreConfig);
// Set the DatabaseConfig object, so that the underlying
// database is configured for uncommitted reads.
myStore.setPrimaryConfig(SomeEntityClass.class, dbConfig);
} catch (DatabaseException de) {
// Exception handling goes here
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
}</pre>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="txnnowait.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="txnconcurrency.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="filemanagement.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">No Wait on Blocks </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Chapter 5. Managing DB Files</td>
</tr>
</table>
</div>
</body>
</html>
|