1 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 DB_NAME = "simpleDB"; 31 32 35 public void testSR11307() 36 throws Throwable { 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 keyString, String 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 keyString, String 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 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 143 put(db, "cfhaa", "yrhwlvlgvq"); 144 put(db, "cfhaa", "blort"); 145 delete(db, "cfhaa", "blort"); 146 env.compress(); 147 env.sync(); 148 149 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 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 |