1 8 package com.sleepycat.je.recovery; 9 10 import java.util.HashSet ; 11 import java.util.logging.Level ; 12 13 import com.sleepycat.bind.tuple.IntegerBinding; 14 import com.sleepycat.je.BtreeStats; 15 import com.sleepycat.je.CheckpointConfig; 16 import com.sleepycat.je.Cursor; 17 import com.sleepycat.je.Database; 18 import com.sleepycat.je.DatabaseConfig; 19 import com.sleepycat.je.DatabaseEntry; 20 import com.sleepycat.je.DatabaseException; 21 import com.sleepycat.je.DbInternal; 22 import com.sleepycat.je.EnvironmentConfig; 23 import com.sleepycat.je.LockMode; 24 import com.sleepycat.je.OperationStatus; 25 import com.sleepycat.je.StatsConfig; 26 import com.sleepycat.je.config.EnvironmentParams; 27 import com.sleepycat.je.recovery.stepwise.TestData; 28 import com.sleepycat.je.util.TestUtils; 29 import com.sleepycat.je.utilint.Tracer; 30 31 39 public class CheckReverseSplitsTest extends CheckBase { 40 41 private static final boolean DEBUG = false; 42 private static final String DB_NAME = "simpleDB"; 43 44 private int max = 12; 45 private boolean useDups; 46 private boolean purgeRoot = false; 47 private static CheckpointConfig FORCE_CONFIG = new CheckpointConfig(); 48 static { 49 FORCE_CONFIG.setForce(true); 50 } 51 52 57 public void testReverseSplit() 58 throws Throwable { 59 60 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 61 turnOffEnvDaemons(envConfig); 62 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), 63 "4"); 64 envConfig.setAllowCreate(true); 65 66 DatabaseConfig dbConfig = new DatabaseConfig(); 67 dbConfig.setSortedDuplicates(useDups); 68 dbConfig.setAllowCreate(true); 69 70 71 testOneCase(DB_NAME, envConfig, dbConfig, 72 new TestGenerator(true ){ 73 void generateData(Database db) 74 throws DatabaseException { 75 setupReverseSplit(db); 76 } 77 }, 78 envConfig, dbConfig); 79 80 81 85 86 87 HashSet currentExpected = new HashSet (); 88 DatabaseEntry keyEntry = new DatabaseEntry(); 89 DatabaseEntry dataEntry = new DatabaseEntry(); 90 for (int i = 2; i < max; i++) { 91 if (useDups) { 92 IntegerBinding.intToEntry(0, keyEntry); 93 } else { 94 IntegerBinding.intToEntry(i, keyEntry); 95 } 96 IntegerBinding.intToEntry(i, dataEntry); 97 currentExpected.add(new TestData(keyEntry, dataEntry)); 98 } 99 100 stepwiseLoop(DB_NAME, envConfig, dbConfig, currentExpected, 0); 101 } 102 103 public void testReverseSplitDups() 104 throws Throwable { 105 106 useDups = true; 107 testReverseSplit(); 108 } 109 110 127 private void setupReverseSplit(Database db) 128 throws DatabaseException { 129 130 DatabaseEntry key = new DatabaseEntry(); 131 DatabaseEntry data = new DatabaseEntry(); 132 133 134 for (int i = 0; i < max; i ++) { 135 if (useDups) { 136 IntegerBinding.intToEntry(0, key); 137 } else { 138 IntegerBinding.intToEntry(i, key); 139 } 140 IntegerBinding.intToEntry(i, data); 141 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 142 } 143 144 145 Cursor c = db.openCursor(null, null); 146 try { 147 assertEquals(OperationStatus.SUCCESS, c.getFirst(key, data, 148 LockMode.DEFAULT)); 149 assertEquals(OperationStatus.SUCCESS, c.delete()); 150 assertEquals(OperationStatus.SUCCESS, 151 c.getFirst(key, data, LockMode.DEFAULT)); 152 assertEquals(OperationStatus.SUCCESS, c.delete()); 153 } finally { 154 c.close(); 155 } 156 157 Tracer.trace(Level.SEVERE, DbInternal.envGetEnvironmentImpl(env), 158 "After deletes"); 159 160 161 setStepwiseStart(); 162 163 167 env.checkpoint(FORCE_CONFIG); 168 169 170 env.compress(); 171 Tracer.trace(Level.SEVERE, DbInternal.envGetEnvironmentImpl(env), 172 "After compress"); 173 174 183 for (int i = max; i < max+13; i ++) { 184 if (useDups) { 185 IntegerBinding.intToEntry(0, key); 186 } else { 187 IntegerBinding.intToEntry(i, key); 188 } 189 IntegerBinding.intToEntry(i, data); 190 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 191 } 192 193 Tracer.trace(Level.SEVERE, DbInternal.envGetEnvironmentImpl(env), 194 "After data setup"); 195 196 } 197 198 201 public void testCompleteRemoval() 202 throws Throwable { 203 204 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 205 turnOffEnvDaemons(envConfig); 206 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), 207 "4"); 208 envConfig.setAllowCreate(true); 209 if (purgeRoot) { 210 envConfig.setConfigParam( 211 EnvironmentParams.COMPRESSOR_PURGE_ROOT.getName(), 212 "true"); 213 } 214 215 DatabaseConfig dbConfig = new DatabaseConfig(); 216 dbConfig.setSortedDuplicates(useDups); 217 dbConfig.setAllowCreate(true); 218 219 220 testOneCase(DB_NAME, envConfig, dbConfig, 221 new TestGenerator(true ){ 222 void generateData(Database db) 223 throws DatabaseException { 224 setupCompleteRemoval(db); 225 } 226 }, 227 envConfig, dbConfig); 228 229 230 234 HashSet currentExpected = new HashSet (); 235 stepwiseLoop(DB_NAME, envConfig, dbConfig, currentExpected, 0); 236 } 237 238 public void testCompleteRemovalDups() 239 throws Throwable { 240 241 useDups = true; 242 testCompleteRemoval(); 243 } 244 245 public void testCompleteRemovalPurgeRoot() 246 throws Throwable { 247 248 purgeRoot = true; 249 testCompleteRemoval(); 250 } 251 252 255 private void setupCompleteRemoval(Database db) 256 throws DatabaseException { 257 258 DatabaseEntry key = new DatabaseEntry(); 259 DatabaseEntry data = new DatabaseEntry(); 260 261 262 for (int i = 0; i < max; i ++) { 263 if (useDups) { 264 IntegerBinding.intToEntry(0, key); 265 } else { 266 IntegerBinding.intToEntry(i, key); 267 } 268 IntegerBinding.intToEntry(i, data); 269 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 270 } 271 272 Tracer.trace(Level.SEVERE, DbInternal.envGetEnvironmentImpl(env), 273 "After inserts"); 274 275 276 Cursor c = db.openCursor(null, null); 277 try { 278 int count = 0; 279 while (c.getNext(key, data, LockMode.DEFAULT) == 280 OperationStatus.SUCCESS) { 281 assertEquals(OperationStatus.SUCCESS, c.delete()); 282 count++; 283 } 284 } finally { 285 c.close(); 286 } 287 Tracer.trace(Level.SEVERE, DbInternal.envGetEnvironmentImpl(env), 288 "After deletes"); 289 290 291 292 293 setStepwiseStart(); 294 295 296 env.checkpoint(FORCE_CONFIG); 297 298 299 env.compress(); 300 BtreeStats stats = (BtreeStats) db.getStats(new StatsConfig()); 301 if (useDups) { 302 assertEquals(0, stats.getDuplicateInternalNodeCount()); 303 } else { 304 if (purgeRoot) { 305 assertEquals(0, stats.getInternalNodeCount()); 306 } else { 307 assertEquals(1, stats.getBottomInternalNodeCount()); 308 } 309 } 310 311 312 for (int i = max*2; i < ((max*2) +5); i ++) { 313 if (useDups) { 314 IntegerBinding.intToEntry(0, key); 315 } else { 316 IntegerBinding.intToEntry(i, key); 317 } 318 IntegerBinding.intToEntry(i, data); 319 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 320 } 321 } 322 } 323 | Popular Tags |