1 8 9 package com.sleepycat.je.util; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 14 import com.sleepycat.je.DatabaseException; 15 import com.sleepycat.je.config.EnvironmentParams; 16 import com.sleepycat.je.dbi.EnvironmentImpl; 17 import com.sleepycat.je.log.DumpFileReader; 18 import com.sleepycat.je.log.FileManager; 19 import com.sleepycat.je.log.PrintFileReader; 20 import com.sleepycat.je.log.StatsFileReader; 21 import com.sleepycat.je.tree.Key; 22 import com.sleepycat.je.utilint.CmdUtil; 23 import com.sleepycat.je.utilint.DbLsn; 24 25 29 public class DbPrintLog { 30 31 34 private void dump(File envHome, 35 String entryTypes, 36 String txnIds, 37 long startLsn, 38 long endLsn, 39 boolean verbose, 40 boolean stats) 41 throws IOException , DatabaseException { 42 43 EnvironmentImpl env = 44 CmdUtil.makeUtilityEnvironment(envHome, true); 45 FileManager fileManager = env.getFileManager(); 46 fileManager.setIncludeDeletedFiles(true); 47 int readBufferSize = 48 env.getConfigManager().getInt 49 (EnvironmentParams.LOG_ITERATOR_READ_SIZE); 50 51 DumpFileReader reader = null; 53 if (stats) { 54 reader = new StatsFileReader(env, readBufferSize, startLsn, endLsn, 55 entryTypes, txnIds, verbose); 56 } else { 57 reader = new PrintFileReader(env, readBufferSize, startLsn, 58 endLsn, entryTypes, txnIds, verbose); 59 } 60 61 System.out.println("<DbPrintLog>"); 63 while (reader.readNextEntry()) { 64 } 65 reader.summarize(); 66 System.out.println("</DbPrintLog>"); 67 env.close(); 68 } 69 70 73 public static void main(String [] argv) { 74 try { 75 int whichArg = 0; 76 String entryTypes = null; 77 String txnIds = null; 78 long startLsn = DbLsn.NULL_LSN; 79 long endLsn = DbLsn.NULL_LSN; 80 boolean verbose = true; 81 boolean stats = false; 82 83 File envHome = new File ("."); 85 Key.DUMP_BINARY = true; 86 87 while (whichArg < argv.length) { 88 String nextArg = argv[whichArg]; 89 if (nextArg.equals("-h")) { 90 whichArg++; 91 envHome = new File (CmdUtil.getArg(argv, whichArg)); 92 } else if (nextArg.equals("-ty")) { 93 whichArg++; 94 entryTypes = CmdUtil.getArg(argv, whichArg); 95 } else if (nextArg.equals("-tx")) { 96 whichArg++; 97 txnIds = CmdUtil.getArg(argv, whichArg); 98 } else if (nextArg.equals("-s")) { 99 whichArg++; 100 long startFileNum = 101 CmdUtil.readLongNumber(CmdUtil.getArg(argv, whichArg)); 102 startLsn = DbLsn.makeLsn(startFileNum, 0); 103 } else if (nextArg.equals("-e")) { 104 whichArg++; 105 long endFileNum = 106 CmdUtil.readLongNumber(CmdUtil.getArg(argv, whichArg)); 107 endLsn = DbLsn.makeLsn(endFileNum, 0); 108 } else if (nextArg.equals("-k")) { 109 whichArg++; 110 String dumpType = CmdUtil.getArg(argv, whichArg); 111 if (dumpType.equalsIgnoreCase("text")) { 112 Key.DUMP_BINARY = false; 113 } 114 } else if (nextArg.equals("-q")) { 115 whichArg++; 116 verbose = false; 117 } else if (nextArg.equals("-S")) { 118 whichArg++; 119 stats = true; 120 } else { 121 System.err.println 122 (nextArg + " is not a supported option."); 123 usage(); 124 System.exit(-1); 125 } 126 whichArg++; 127 } 128 129 DbPrintLog printer = new DbPrintLog(); 130 printer.dump(envHome, entryTypes, txnIds, 131 startLsn, endLsn, verbose, stats); 132 133 } catch (Throwable e) { 134 e.printStackTrace(); 135 System.out.println(e.getMessage()); 136 usage(); 137 System.exit(1); 138 } 139 } 140 141 private static void usage() { 142 System.out.println("Usage: " + 143 CmdUtil.getJavaCommand(DbPrintLog.class)); 144 System.out.println(" -h <envHomeDir>"); 145 System.out.println(" -e <end file number, in hex>"); 146 System.out.println(" -k <binary|text> (format for dumping the key)"); 147 System.out.println(" -s <start file number, in hex>"); 148 System.out.println(" -tx <targetted txn ids, comma separated>"); 149 System.out.println(" -ty <targetted entry types, comma separated>"); 150 System.out.println(" -S show Summary of log entries"); 151 System.out.println(" -q if specified, concise version is printed"); 152 System.out.println(" Default is verbose version.)"); 153 System.out.println("All arguments are optional"); 154 } 155 } 156 | Popular Tags |