Debian Codegraph @

docs/gsg_txn/JAVA/reversesplit.html

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