1 8 package com.sleepycat.je.recovery; 9 10 import com.sleepycat.bind.tuple.IntegerBinding; 11 import com.sleepycat.je.CheckpointConfig; 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.config.EnvironmentParams; 20 import com.sleepycat.je.dbi.EnvironmentImpl; 21 import com.sleepycat.je.tree.BIN; 22 import com.sleepycat.je.tree.Tree; 23 import com.sleepycat.je.util.TestUtils; 24 25 public class CheckBINDeltaTest extends CheckBase { 26 27 private static final String DB_NAME = "simpleDB"; 28 private static final boolean DEBUG = false; 29 30 34 public void testBINDelta() 35 throws Throwable { 36 37 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 38 turnOffEnvDaemons(envConfig); 39 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), 40 "4"); 41 envConfig.setConfigParam(EnvironmentParams.BIN_DELTA_PERCENT.getName(), 42 "75"); 43 envConfig.setAllowCreate(true); 44 45 DatabaseConfig dbConfig = new DatabaseConfig(); 46 dbConfig.setAllowCreate(true); 47 48 EnvironmentConfig restartConfig = TestUtils.initEnvConfig(); 49 turnOffEnvDaemons(restartConfig); 50 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), 51 "4"); 52 53 testOneCase(DB_NAME, 54 envConfig, 55 dbConfig, 56 new TestGenerator(){ 57 void generateData(Database db) 58 throws DatabaseException { 59 addData(db); 60 } 61 }, 62 restartConfig, 63 new DatabaseConfig()); 64 } 65 66 105 private void addData(Database db) 106 throws DatabaseException { 107 108 DatabaseEntry key = new DatabaseEntry(); 109 DatabaseEntry data = new DatabaseEntry(); 110 111 112 for (int i = 0; i < 140; i += 10) { 113 IntegerBinding.intToEntry(i, key); 114 IntegerBinding.intToEntry(i, data); 115 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 116 } 117 118 CheckpointConfig ckptConfig = new CheckpointConfig(); 119 ckptConfig.setForce(true); 120 env.checkpoint(ckptConfig); 121 122 Tree tree = DbInternal.dbGetDatabaseImpl(db).getTree(); 123 com.sleepycat.je.tree.Key.DUMP_INT_BINDING = true; 124 if (DEBUG) { 125 tree.dump(); 126 } 127 128 132 IntegerBinding.intToEntry(0, key); 133 IntegerBinding.intToEntry(100, data); 134 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 135 IntegerBinding.intToEntry(20, key); 136 assertEquals(OperationStatus.SUCCESS, db.put(null, key, data)); 137 138 EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env); 139 BIN bin = (BIN)tree.getFirstNode(); 140 bin.log(envImpl.getLogManager(), true, false, false, false, null); 141 bin = tree.getNextBin(bin, false ); 142 bin.log(envImpl.getLogManager(), true, false, false, false, null); 143 bin.releaseLatch(); 144 145 149 for (int i = 0; i < 50; i+=10) { 150 IntegerBinding.intToEntry(i, key); 151 assertEquals(OperationStatus.SUCCESS, db.delete(null, key)); 152 } 153 154 155 env.compress(); 156 if (DEBUG) { 157 tree.dump(); 158 } 159 } 160 } 161 | Popular Tags |