1 8 9 package com.sleepycat.je.logversion; 10 11 import java.io.BufferedOutputStream ; 12 import java.io.File ; 13 import java.io.FileOutputStream ; 14 import java.io.PrintWriter ; 15 import java.util.Set ; 16 17 import javax.transaction.xa.XAResource ; 18 19 import com.sleepycat.je.CheckpointConfig; 20 import com.sleepycat.je.Cursor; 21 import com.sleepycat.je.Database; 22 import com.sleepycat.je.DatabaseConfig; 23 import com.sleepycat.je.DatabaseEntry; 24 import com.sleepycat.je.DbInternal; 25 import com.sleepycat.je.Environment; 26 import com.sleepycat.je.EnvironmentConfig; 27 import com.sleepycat.je.JEVersion; 28 import com.sleepycat.je.OperationStatus; 29 import com.sleepycat.je.Transaction; 30 import com.sleepycat.je.XAEnvironment; 31 import com.sleepycat.je.config.EnvironmentParams; 32 import com.sleepycat.je.log.LogEntryType; 33 import com.sleepycat.je.log.TestUtilLogReader; 34 import com.sleepycat.je.log.LogUtils.XidImpl; 35 import com.sleepycat.je.util.TestUtils; 36 37 56 public class MakeLogEntryVersionData { 57 58 59 private static int N_ENTRIES = 4; 60 61 private MakeLogEntryVersionData() { 62 } 63 64 public static void main(String [] args) 65 throws Exception { 66 67 if (args.length != 1) { 68 throw new Exception ("Home directory arg is required."); 69 } 70 71 File homeDir = new File (args[0]); 72 File logFile = new File (homeDir, TestUtils.LOG_FILE_NAME); 73 File renamedLogFile = new File (homeDir, "je-" + 74 JEVersion.CURRENT_VERSION.getNumericVersionString() + ".jdb"); 75 File summaryFile = new File (homeDir, "je-" + 76 JEVersion.CURRENT_VERSION.getNumericVersionString() + ".txt"); 77 78 if (logFile.exists()) { 79 throw new Exception ("Home directory must be empty of log files."); 80 } 81 82 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 83 DbInternal.disableParameterValidation(envConfig); 84 envConfig.setAllowCreate(true); 85 envConfig.setTransactional(true); 86 87 envConfig.setConfigParam 88 (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false"); 89 envConfig.setConfigParam 90 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 91 envConfig.setConfigParam 92 (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false"); 93 envConfig.setConfigParam 94 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 95 96 envConfig.setConfigParam 97 (EnvironmentParams.JE_LOGGING_LEVEL.getName(), "CONFIG"); 98 99 envConfig.setConfigParam(EnvironmentParams.LOG_FILE_MAX.getName(), 100 Integer.toString(100 * (1 << 20))); 101 102 envConfig.setConfigParam 103 (EnvironmentParams.BIN_DELTA_PERCENT.getName(), 104 Integer.toString(75)); 105 106 envConfig.setConfigParam 107 (EnvironmentParams.COMPRESSOR_PURGE_ROOT.getName(), "true"); 108 109 envConfig.setConfigParam 110 (EnvironmentParams.NODE_MAX.getName(), 111 Integer.toString(N_ENTRIES)); 112 113 CheckpointConfig forceCheckpoint = new CheckpointConfig(); 114 forceCheckpoint.setForce(true); 115 116 XAEnvironment env = new XAEnvironment(homeDir, envConfig); 117 118 for (int i = 0; i < 2; i += 1) { 119 boolean transactional = (i == 0); 120 String dbName = transactional ? Utils.DB1_NAME : Utils.DB2_NAME; 121 122 DatabaseConfig dbConfig = new DatabaseConfig(); 123 dbConfig.setAllowCreate(true); 124 dbConfig.setTransactional(transactional); 125 dbConfig.setSortedDuplicates(true); 126 Database db = env.openDatabase(null, dbName, dbConfig); 127 128 Transaction txn = null; 129 if (transactional) { 130 txn = env.beginTransaction(null, null); 131 } 132 133 for (int j = 0; j < N_ENTRIES; j += 1) { 134 db.put(txn, Utils.entry(j), Utils.entry(0)); 135 } 136 db.put(txn, Utils.entry(0), Utils.entry(1)); 137 138 139 env.checkpoint(forceCheckpoint); 140 141 142 for (int j = 0; j < N_ENTRIES - 1; j += 1) { 143 db.delete(txn, Utils.entry(j)); 144 } 145 146 if (transactional) { 147 txn.abort(); 148 } 149 150 db.close(); 151 } 152 153 154 env.compress(); 155 env.compress(); 156 157 158 DatabaseConfig dbConfig = new DatabaseConfig(); 159 dbConfig.setAllowCreate(false); 160 dbConfig.setReadOnly(true); 161 dbConfig.setSortedDuplicates(true); 162 Database db = env.openDatabase(null, Utils.DB2_NAME, dbConfig); 163 Cursor cursor = db.openCursor(null, null); 164 try { 165 DatabaseEntry key = new DatabaseEntry(); 166 DatabaseEntry data = new DatabaseEntry(); 167 OperationStatus status = cursor.getFirst(key, data, null); 168 if (status != OperationStatus.SUCCESS) { 169 throw new Exception ("Expected SUCCESS but got: " + status); 170 } 171 if (Utils.value(key) != 3 || Utils.value(data) != 0) { 172 throw new Exception ("Expected {3,0} but got: {" + 173 Utils.value(key) + ',' + 174 Utils.value(data) + '}'); 175 } 176 } finally { 177 cursor.close(); 178 } 179 db.close(); 180 181 XidImpl xid = 182 new XidImpl(1, "MakeLogEntryVersionData".getBytes(), null); 183 env.start(xid, XAResource.TMNOFLAGS); 184 env.prepare(xid); 185 env.rollback(xid); 186 187 env.close(); 188 189 194 Set expectedTypes = LogEntryType.getAllTypes(); 195 expectedTypes.remove(LogEntryType.LOG_MAPLN_TRANSACTIONAL); 196 197 198 envConfig.setReadOnly(true); 199 Environment env2 = new Environment(homeDir, envConfig); 200 PrintWriter writer = new PrintWriter ![JavaDoc](../../../../../cmn/javadoc.gif) 201 (new BufferedOutputStream (new FileOutputStream (summaryFile))); 202 TestUtilLogReader reader = new TestUtilLogReader 203 (DbInternal.envGetEnvironmentImpl(env2)); 204 while (reader.readNextEntry()) { 205 LogEntryType type = reader.getEntryType(); 206 writer.println(type.toString()); 207 expectedTypes.remove(type); 208 } 209 writer.close(); 210 env2.close(); 211 212 if (expectedTypes.size() > 0) { 213 throw new Exception ("Types not output: " + expectedTypes); 214 } 215 216 if (!logFile.exists()) { 217 throw new Exception ("What happened to: " + logFile); 218 } 219 220 if (!logFile.renameTo(renamedLogFile)) { 221 throw new Exception ![JavaDoc](../../../../../cmn/javadoc.gif) 222 ("Could not rename: " + logFile + " to " + renamedLogFile); 223 } 224 225 System.out.println("Created: " + renamedLogFile); 226 System.out.println("Created: " + summaryFile); 227 } 228 } 229 | Popular Tags |