KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > recovery > CheckSR11307


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2004,2006 Oracle. All rights reserved.
5  *
6  * $Id: CheckSR11307.java,v 1.11 2006/10/30 21:14:48 bostic Exp $
7  */

8 package com.sleepycat.je.recovery;
9
10 import com.sleepycat.je.CheckpointConfig;
11 import com.sleepycat.je.Cursor;
12 import com.sleepycat.je.Database;
13 import com.sleepycat.je.DatabaseConfig;
14 import com.sleepycat.je.DatabaseEntry;
15 import com.sleepycat.je.DatabaseException;
16 import com.sleepycat.je.DbInternal;
17 import com.sleepycat.je.EnvironmentConfig;
18 import com.sleepycat.je.OperationStatus;
19 import com.sleepycat.je.dbi.DatabaseImpl;
20 import com.sleepycat.je.dbi.EnvironmentImpl;
21 import com.sleepycat.je.tree.BIN;
22 import com.sleepycat.je.tree.DBIN;
23 import com.sleepycat.je.tree.DIN;
24 import com.sleepycat.je.tree.Key;
25 import com.sleepycat.je.tree.Tree.SearchType;
26 import com.sleepycat.je.util.TestUtils;
27
28 public class CheckSR11307 extends CheckBase {
29
30     private static final String JavaDoc DB_NAME = "simpleDB";
31
32     /**
33      * SR #11307
34      */

35     public void testSR11307()
36         throws Throwable JavaDoc {
37
38         EnvironmentConfig envConfig = TestUtils.initEnvConfig();
39         turnOffEnvDaemons(envConfig);
40         envConfig.setAllowCreate(true);
41                                  
42         DatabaseConfig dbConfig = new DatabaseConfig();
43         dbConfig.setAllowCreate(true);
44     dbConfig.setSortedDuplicates(true);
45
46         DatabaseConfig validateDbConfig = new DatabaseConfig();
47     validateDbConfig.setSortedDuplicates(true);
48
49         EnvironmentConfig restartConfig = TestUtils.initEnvConfig();
50         turnOffEnvDaemons(restartConfig);
51
52         testOneCase(DB_NAME,
53                     envConfig,
54                     dbConfig,
55                     new TestGenerator(){
56                         void generateData(Database db)
57                             throws DatabaseException {
58
59                             addData(db);
60                         }
61                     },
62                     restartConfig,
63                     validateDbConfig);
64     }
65
66     private void put(Database db, String JavaDoc keyString, String JavaDoc dataString)
67     throws DatabaseException {
68
69     DatabaseEntry key = new DatabaseEntry(keyString.getBytes());
70     DatabaseEntry data = new DatabaseEntry(dataString.getBytes());
71     assertEquals(OperationStatus.SUCCESS, db.put(null, key, data));
72     }
73
74     private void delete(Database db, String JavaDoc keyString, String JavaDoc dataString)
75     throws DatabaseException {
76
77     DatabaseEntry key = new DatabaseEntry(keyString.getBytes());
78     DatabaseEntry data = new DatabaseEntry(dataString.getBytes());
79
80     Cursor c = db.openCursor(null, null);
81     assertEquals(OperationStatus.SUCCESS,
82              c.getSearchBoth(key, data, null));
83     assertEquals(OperationStatus.SUCCESS, c.delete());
84     c.close();
85     }
86
87     /*
88      * We're trying to emulate the following log synopsis. The replay of this
89      * log will end up putting a DBIN in a DBIN if the requiresExactMatch is
90      * false in the call to readINs() in pass 7 of recovery.
91
92      <entry lsn="0x3d9/0x1cd2" type="LN/0" prev="0x1ca0" size="36" cksum="2555578370"><ln><node>6809</node><data>yrhwlvlgvq</data></ln><dbId id="3"/><key val="cfhaa"/></entry>
93
94      <entry lsn="0x3d9/0x4787" type="DBIN/1" prev="0x46d2" size="75" cksum="2518487070"><dbin><node>6807</node><key val="yrhwlvlgvq"/><isRoot val="false"/><level val="1"/><entries numEntries="1" length="128"><ref knownDeleted="false"><key val="yrhwlvlgvq"/><DbLsn val="0x3d9/0x1cd2"/></ref></entries><key val="cfhaa"/></dbin><dbId id="3"/></entry>
95
96      <entry lsn="0x3dc/0x1e029" type="DIN/1" prev="0x1dfbd" size="94" cksum="419435527"><din><node>6806</node><key val="ubpgspglfn"/><isRoot val="true"/><level val="2"/><entries numEntries="1" length="128"><ref knownDeleted="false"><key val="ubpgspglfn"/><DbLsn val="0x3d9/0x4787"/></ref></entries><key val="cfhaa"/><ref knownDeleted="false"><key val="cfhaa"/><DbLsn val="0x3dc/0x1c226"/></ref></din><dbId id="3"/></entry>
97
98      <entry lsn="0x3dc/0x4b3b5" type="DBIN/1" prev="0x4b349" size="213" cksum="4263720111"><dbin><node>5904</node><key val="gutjjgrfan"/><isRoot val="false"/><level val="1"/><entries numEntries="7" length="128"><ref knownDeleted="false"><key val="gutjjgrfan"/><DbLsn val="0x3dc/0x4848a"/></ref><ref knownDeleted="false"><key val="insjaepgnc"/><DbLsn val="0x3dc/0x48458"/></ref><ref knownDeleted="false"><key val="lthfpygdej"/><DbLsn val="0x3d8/0x584bb"/></ref><ref knownDeleted="false"><key val="qugxbqwtgd"/><DbLsn val="0x3dc/0x48426"/></ref><ref knownDeleted="false"><key val="savescwzoy"/><DbLsn val="0x3da/0x38d5"/></ref><ref knownDeleted="false"><key val="srbzmnargv"/><DbLsn val="0x3dc/0x484bc"/></ref><ref knownDeleted="false"><key val="ttkwptlkxv"/><DbLsn val="0x3db/0xa2d4a"/></ref></entries><key val="cfgaa"/></dbin><dbId id="3"/></entry>
99
100      <entry lsn="0x3dc/0x4dce2" type="DIN/1" prev="0x4dc76" size="94" cksum="4266267702"><din><node>5903</node><key val="fyfmgvxwux"/><isRoot val="true"/><level val="2"/><entries numEntries="1" length="128"><ref knownDeleted="false"><key val="fyfmgvxwux"/><DbLsn val="0x3dc/0x4b3b5"/></ref></entries><key val="cfgaa"/><ref knownDeleted="false"><key val="cfgaa"/><DbLsn val="0x3d9/0xc08d1"/></ref></din><dbId id="3"/></entry>
101
102      <entry lsn="0x3dd/0xe5c6d" type="CkptStart/0" prev="0xe57cb" size="26" cksum="2882930936"><CkptStart invoker="daemon" time="2004-10-30 13:26:19.89" id="1747"/></entry>
103
104      <entry lsn="0x3dd/0xe5d4f" type="IN/1" prev="0xe5cd7" size="236" cksum="1038102495"><in><node>17</node><key val="aaaaa"/><isRoot val="true"/><level val="10002"/><entries numEntries="11" length="128"><ref knownDeleted="false"><key val="aaaaa"/><DbLsn val="0x3dd/0xda14e"/></ref><ref knownDeleted="false"><key val="bbfaa"/><DbLsn val="0x3dd/0xdf614"/></ref><ref knownDeleted="false"><key val="ceaaa"/><DbLsn val="0x3dd/0xde785"/></ref><ref knownDeleted="false"><key val="dgcaa"/><DbLsn val="0x3dd/0xe063f"/></ref><ref knownDeleted="false"><key val="ecgaa"/><DbLsn val="0x3dd/0xddbe0"/></ref><ref knownDeleted="false"><key val="ejaaa"/><DbLsn val="0x3dd/0xe4ea1"/></ref><ref knownDeleted="false"><key val="gbbaa"/><DbLsn val="0x3dd/0xe40bb"/></ref><ref knownDeleted="false"><key val="hdcaa"/><DbLsn val="0x3dd/0xe36a1"/></ref><ref knownDeleted="false"><key val="hjhaa"/><DbLsn val="0x3dd/0xe0c81"/></ref><ref knownDeleted="false"><key val="igcaa"/><DbLsn val="0x3dd/0xd18dc"/></ref><ref knownDeleted="false"><key val="jdaaa"/><DbLsn val="0x3dd/0xd863a"/></ref></entries></in><dbId id="3"/></entry>
105
106      <entry lsn="0x3dd/0xed260" type="CkptEnd/0" prev="0xed22e" size="71" cksum="4160163625"><CkptEnd invoker="daemon" time="2004-10-30 13:26:20.046" lastNodeId="36927" lastDbId="4" lastTxnId="11033" id="1747" rootExists="true"><ckptStart><DbLsn val="0x3dd/0xe5c6d"/></ckptStart><root><DbLsn val="0x3dd/0xec74d"/></root><firstActive><DbLsn val="0x3dd/0xe5c6d"/></firstActive></CkptEnd></entry>
107
108      <entry lsn="0x3de/0x390ee" type="BIN/1" prev="0x38c70" size="2180" cksum="1778961065"><bin><node>2317</node><key val="ceaaa"/><isRoot val="false"/><level val="10001"/><entries numEntries="119" length="128">...<ref knownDeleted="false"><key val="cfhaa"/><DbLsn val="0x3dc/0x1e029"/></ref>...</entries></bin><dbId id="3"/></entry>
109
110      <entry lsn="0x3de/0x3b64c" type="DelDupLN_TX/0" prev="0x3b607" size="61" cksum="1460079772"><ln><node>6809</node></ln><dbId id="3"/><key val="cfhaa"/><DbLsn val="0x3d9/0x1cd2"/><knownDeleted val="false"/><txn id="11046__Txn"><DbLsn val="0x3de/0x3b3c7"/></txn><key val="yrhwlvlgvq"/></entry>
111
112      <entry lsn="0x3de/0x3b6e2" type="DupCountLN_TX/0" prev="0x3b697" size="55" cksum="4138272827"><dupCountLN><node>6805</node><data></data><count v="0"/></dupCountLN><dbId id="3"/><key val="cfhaa"/><DbLsn val="0x3dc/0x1c226"/><knownDeleted val="false"/><txn id="11046__Txn"><DbLsn val="0x3de/0x3b64c"/></txn></entry>
113
114      <entry lsn="0x3de/0x3b838" type="DBIN/1" prev="0x3b76c" size="75" cksum="2625900628"><dbin><node>6807</node><key val="yrhwlvlgvq"/><isRoot val="false"/><level val="1"/><entries numEntries="1" length="128"><ref knownDeleted="false"><key val="yrhwlvlgvq"/><DbLsn val="0x3de/0x3b64c"/></ref></entries><key val="cfhaa"/></dbin><dbId id="3"/></entry>
115
116      <entry lsn="0x3de/0x3bec7" type="DIN/1" prev="0x3bdcd" size="94" cksum="635376858"><din><node>6806</node><key val="ubpgspglfn"/><isRoot val="true"/><level val="2"/><entries numEntries="1" length="128"><ref knownDeleted="false"><key val="ubpgspglfn"/><DbLsn val="0x3de/0x3b838"/></ref></entries><key val="cfhaa"/><ref knownDeleted="false"><key val="cfhaa"/><DbLsn val="0x3de/0x3b6e2"/></ref></din><dbId id="3"/></entry>
117
118      <entry lsn="0x3de/0x40df6" type="INDupDelete/0" prev="0x40d8a" size="35" cksum="2389575622"><INDupDeleteEntry node="6806"><key val="cfhaa"/><key val="ubpgspglfn"/><dbId id="3"/></INDupDeleteEntry></entry>
119
120      <entry lsn="0x3de/0x46660" type="BIN/1" prev="0x465f4" size="2162" cksum="3104884361"><bin><node>2317</node><key val="ceaaa"/><isRoot val="false"/><level val="10001"/><entries numEntries="118" length="128">...<ref knownDeleted="false"><key val="cfgaa"/><DbLsn val="0x3dc/0x4dce2"/></ref>...</entries></bin><dbId id="3"/></entry>
121
122      <entry lsn="0x3de/0x50fa2" type="BIN/1" prev="0x50f36" size="2162" cksum="111985926"><bin><node>2317</node><key val="ceaaa"/><isRoot val="false"/><level val="10001"/><entries numEntries="118" length="128">...<ref knownDeleted="false"><key val="cfgaa"/>...</entries></bin><dbId id="3"/></entry>
123
124      Trace list:
125      lsn=0x3dd/0xe5d4f node=17
126      lsn=0x3de/0x50fa2 node=2317
127      lsn=0x3dc/0x4dce2 node=5903
128      lsn=0x3dc/0x4b3b5 node=5904
129
130     */

131     private void addData(Database db)
132         throws DatabaseException {
133
134     DatabaseImpl dbImpl = DbInternal.dbGetDatabaseImpl(db);
135         EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
136         CheckpointConfig ckptConfig = new CheckpointConfig();
137         ckptConfig.setForce(true);
138
139     /*
140      * Create a one element dup tree by making a dupe and then reducing it
141      * back to one element.
142      */

143     put(db, "cfhaa", "yrhwlvlgvq");
144     put(db, "cfhaa", "blort");
145     delete(db, "cfhaa", "blort");
146     env.compress();
147         env.sync();
148
149     /* Same thing for cfgaa. */
150     put(db, "cfgaa", "urhwlvlgvq");
151     put(db, "cfgaa", "blort");
152     delete(db, "cfgaa", "blort");
153     put(db, "cfiaa", "yrhwlvlgvq");
154     put(db, "cffaa", "yrhwlvlgvq");
155         env.sync();
156         env.sync();
157
158     /* Write out the DelDupLN and DupCountLN. */
159     delete(db, "cfhaa", "yrhwlvlgvq");
160     BIN bin = (BIN) dbImpl.getTree().search("cfhaa".getBytes(),
161                         SearchType.NORMAL,
162                         -1,
163                                                 null,
164                                                 true);
165     assertNotNull(bin);
166     int idx = bin.findEntry("cfhaa".getBytes(), false, true);
167     DIN din = (DIN) bin.getTarget(idx);
168     assertNotNull(din);
169     idx = din.findEntry("yrhwlvlgvq".getBytes(), false, true);
170     DBIN dbin = (DBIN) din.getTarget(idx);
171     Key.DUMP_BINARY = false;
172     dbin.log(envImpl.getLogManager());
173     din.log(envImpl.getLogManager());
174     bin.releaseLatch();
175     env.compress();
176     bin.log(envImpl.getLogManager());
177     }
178 }
179
Popular Tags