1 8 package com.sleepycat.je.recovery; 9 10 import java.util.Hashtable ; 11 import java.util.List ; 12 13 import com.sleepycat.je.Cursor; 14 import com.sleepycat.je.DatabaseEntry; 15 import com.sleepycat.je.DatabaseException; 16 import com.sleepycat.je.LockMode; 17 import com.sleepycat.je.OperationStatus; 18 import com.sleepycat.je.Transaction; 19 import com.sleepycat.je.config.EnvironmentParams; 20 21 24 public class RecoveryDeltaTest extends RecoveryTestBase { 25 26 29 public void setExtraProperties() 30 throws DatabaseException { 31 32 33 envConfig.setConfigParam 34 (EnvironmentParams.BIN_DELTA_PERCENT.getName(), "75"); 35 36 40 envConfig.setConfigParam 41 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 42 46 envConfig.setConfigParam 47 (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false"); 48 } 49 50 54 public void testCompress() 55 throws Throwable { 56 57 createEnvAndDbs(1 << 20, true, NUM_DBS); 58 int numRecs = 20; 59 try { 60 Hashtable expectedData = new Hashtable (); 62 63 Transaction txn = env.beginTransaction(null, null); 65 insertData(txn, 0, numRecs - 1, expectedData, 1, true, NUM_DBS); 66 txn.commit(); 67 68 txn = env.beginTransaction(null, null); 70 deleteData(txn, expectedData, false, true, NUM_DBS); 71 txn.commit(); 72 73 74 env.compress(); 76 77 env.checkpoint(forceConfig); 79 80 closeEnv(); 81 82 recoverAndVerify(expectedData, NUM_DBS); 83 84 } catch (Throwable t) { 85 t.printStackTrace(); 87 throw t; 88 } 89 } 90 91 94 public void testRecoveryDelta() 95 throws Throwable { 96 97 createEnvAndDbs(1 << 20, true, NUM_DBS); 98 int numRecs = 20; 99 try { 100 101 Hashtable expectedData = new Hashtable (); 102 103 107 env.checkpoint(forceConfig); 108 109 110 Transaction txn = env.beginTransaction(null, null); 111 insertData(txn, 0, numRecs - 1, expectedData, 1, true, NUM_DBS); 112 txn.commit(); 113 114 119 env.checkpoint(forceConfig); 120 121 closeEnv(); 122 List infoList = recoverAndVerify(expectedData, NUM_DBS); 123 124 125 RecoveryInfo firstInfo = (RecoveryInfo) infoList.get(0); 126 assertTrue(firstInfo.numBinDeltas > 0); 127 128 } catch (Throwable t) { 129 t.printStackTrace(); 131 throw t; 132 } 133 } 134 135 144 public void testKnownDeleted() 145 throws Throwable { 146 147 createEnvAndDbs(1 << 20, true, NUM_DBS); 148 int numRecs = 20; 149 try { 150 151 152 Hashtable expectedData = new Hashtable (); 153 154 155 Transaction txn = env.beginTransaction(null, null); 156 insertData(txn, 0, numRecs - 1, expectedData, 1, false, NUM_DBS); 157 158 162 Cursor [][] cursors = new Cursor[NUM_DBS][numRecs]; 163 addCursors(cursors); 164 txn.abort(); 165 166 171 env.checkpoint(forceConfig); 172 removeCursors(cursors); 173 174 175 179 txn = env.beginTransaction(null, null); 180 insertData(txn, 0, numRecs - 1, expectedData, 1, 181 true, true, NUM_DBS); 182 txn.commit(); 183 184 185 txn = env.beginTransaction(null, null); 186 deleteData(txn, expectedData, true, false, NUM_DBS); 187 txn.abort(); 188 189 190 cursors = new Cursor[NUM_DBS][numRecs/2]; 191 addCursors(cursors); 192 env.checkpoint(forceConfig); 193 removeCursors(cursors); 194 195 closeEnv(); 196 List infoList = recoverAndVerify(expectedData, NUM_DBS); 197 198 199 RecoveryInfo firstInfo = (RecoveryInfo) infoList.get(0); 200 assertTrue(firstInfo.numBinDeltas > 0); 201 202 } catch (Throwable t) { 203 t.printStackTrace(); 205 throw t; 206 } 207 } 208 209 210 private void addCursors(Cursor [][] cursors) 211 throws DatabaseException { 212 213 DatabaseEntry key = new DatabaseEntry(); 214 DatabaseEntry data = new DatabaseEntry(); 215 216 217 for (int d = 0; d < NUM_DBS; d++) { 218 for (int i = 0; i < cursors[d].length; i++) { 219 cursors[d][i] = dbs[d].openCursor(null, null); 220 221 for (int j = 0; j < i; j++) { 222 OperationStatus status = 223 cursors[d][i].getNext(key, data, 224 LockMode.READ_UNCOMMITTED); 225 assertEquals(OperationStatus.SUCCESS, status); 226 } 227 } 228 } 229 } 230 231 private void removeCursors(Cursor[][] cursors) 232 throws DatabaseException { 233 for (int d = 0; d < NUM_DBS; d++) { 234 for (int i = 0; i < cursors[d].length; i++) { 235 cursors[d][i].close(); 236 } 237 } 238 } 239 } 240 | Popular Tags |