001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: DbPrintLog.java,v 1.39.2.6 2008/01/07 15:14:17 cwl Exp $
007: */
008:
009: package com.sleepycat.je.util;
010:
011: import java.io.File;
012: import java.io.IOException;
013:
014: import com.sleepycat.je.DatabaseException;
015: import com.sleepycat.je.config.EnvironmentParams;
016: import com.sleepycat.je.dbi.EnvironmentImpl;
017: import com.sleepycat.je.log.DumpFileReader;
018: import com.sleepycat.je.log.FileManager;
019: import com.sleepycat.je.log.PrintFileReader;
020: import com.sleepycat.je.log.StatsFileReader;
021: import com.sleepycat.je.tree.Key;
022: import com.sleepycat.je.tree.Key.DumpType;
023: import com.sleepycat.je.utilint.CmdUtil;
024: import com.sleepycat.je.utilint.DbLsn;
025:
026: /**
027: * DbPrintLog is a debugging utility that dumps JE log files into a human
028: * readable form.
029: */
030: public class DbPrintLog {
031:
032: /**
033: * Dump a JE log into human readable form.
034: */
035: private void dump(File envHome, String entryTypes, String txnIds,
036: long startLsn, long endLsn, boolean verbose, boolean stats)
037: throws IOException, DatabaseException {
038:
039: EnvironmentImpl env = CmdUtil.makeUtilityEnvironment(envHome,
040: true);
041: FileManager fileManager = env.getFileManager();
042: fileManager.setIncludeDeletedFiles(true);
043: int readBufferSize = env.getConfigManager().getInt(
044: EnvironmentParams.LOG_ITERATOR_READ_SIZE);
045:
046: /* Make a reader. */
047: DumpFileReader reader = null;
048: if (stats) {
049: reader = new StatsFileReader(env, readBufferSize, startLsn,
050: endLsn, entryTypes, txnIds, verbose);
051: } else {
052: reader = new PrintFileReader(env, readBufferSize, startLsn,
053: endLsn, entryTypes, txnIds, verbose);
054: }
055:
056: /* Enclose the output in a tag to keep proper XML syntax. */
057: System.out.println("<DbPrintLog>");
058: while (reader.readNextEntry()) {
059: }
060: reader.summarize();
061: System.out.println("</DbPrintLog>");
062: env.close();
063: }
064:
065: /**
066: * Main
067: */
068: public static void main(String[] argv) {
069: try {
070: int whichArg = 0;
071: String entryTypes = null;
072: String txnIds = null;
073: long startLsn = DbLsn.NULL_LSN;
074: long endLsn = DbLsn.NULL_LSN;
075: boolean verbose = true;
076: boolean stats = false;
077:
078: /* Default to looking in current directory. */
079: File envHome = new File(".");
080: Key.DUMP_TYPE = DumpType.BINARY;
081:
082: while (whichArg < argv.length) {
083: String nextArg = argv[whichArg];
084: if (nextArg.equals("-h")) {
085: whichArg++;
086: envHome = new File(CmdUtil.getArg(argv, whichArg));
087: } else if (nextArg.equals("-ty")) {
088: whichArg++;
089: entryTypes = CmdUtil.getArg(argv, whichArg);
090: } else if (nextArg.equals("-tx")) {
091: whichArg++;
092: txnIds = CmdUtil.getArg(argv, whichArg);
093: } else if (nextArg.equals("-s")) {
094: whichArg++;
095: String arg = CmdUtil.getArg(argv, whichArg);
096: int slashOff = arg.indexOf("/");
097: if (slashOff < 0) {
098: long startFileNum = CmdUtil.readLongNumber(arg);
099: startLsn = DbLsn.makeLsn(startFileNum, 0);
100: } else {
101: long startFileNum = CmdUtil.readLongNumber(arg
102: .substring(0, slashOff));
103: long startOffset = CmdUtil.readLongNumber(arg
104: .substring(slashOff + 1));
105: startLsn = DbLsn.makeLsn(startFileNum,
106: startOffset);
107: }
108: } else if (nextArg.equals("-e")) {
109: whichArg++;
110: String arg = CmdUtil.getArg(argv, whichArg);
111: int slashOff = arg.indexOf("/");
112: if (slashOff < 0) {
113: long endFileNum = CmdUtil.readLongNumber(arg);
114: endLsn = DbLsn.makeLsn(endFileNum, 0);
115: } else {
116: long endFileNum = CmdUtil.readLongNumber(arg
117: .substring(0, slashOff));
118: long endOffset = CmdUtil.readLongNumber(arg
119: .substring(slashOff + 1));
120: endLsn = DbLsn.makeLsn(endFileNum, endOffset);
121: }
122: } else if (nextArg.equals("-k")) {
123: whichArg++;
124: String dumpType = CmdUtil.getArg(argv, whichArg);
125: if (dumpType.equalsIgnoreCase("text")) {
126: Key.DUMP_TYPE = DumpType.TEXT;
127: } else if (dumpType.equalsIgnoreCase("hex")) {
128: Key.DUMP_TYPE = DumpType.HEX;
129: } else if (dumpType.equalsIgnoreCase("binary")) {
130: Key.DUMP_TYPE = DumpType.BINARY;
131: } else if (dumpType.equalsIgnoreCase("obfuscate")) {
132: Key.DUMP_TYPE = DumpType.OBFUSCATE;
133: } else if (dumpType.equalsIgnoreCase("none")) {
134: Key.DUMP_TYPE = DumpType.NONE;
135: } else {
136: System.err
137: .println(dumpType
138: + " is not a supported dump format type.");
139: }
140: } else if (nextArg.equals("-q")) {
141: whichArg++;
142: verbose = false;
143: } else if (nextArg.equals("-S")) {
144: whichArg++;
145: stats = true;
146: } else {
147: System.err.println(nextArg
148: + " is not a supported option.");
149: usage();
150: System.exit(-1);
151: }
152: whichArg++;
153: }
154:
155: DbPrintLog printer = new DbPrintLog();
156: printer.dump(envHome, entryTypes, txnIds, startLsn, endLsn,
157: verbose, stats);
158:
159: } catch (Throwable e) {
160: e.printStackTrace();
161: System.out.println(e.getMessage());
162: usage();
163: System.exit(1);
164: }
165: }
166:
167: private static void usage() {
168: System.out.println("Usage: "
169: + CmdUtil.getJavaCommand(DbPrintLog.class));
170: System.out.println(" -h <envHomeDir>");
171: System.out.println(" -e <end file number or LSN, in hex>");
172: System.out.println(" -k <binary|text|hex|obfuscate|none> "
173: + "(format for dumping the key)");
174: System.out.println(" -s <start file number or LSN, in hex>");
175: System.out.println(" -tx <targetted txn ids, comma separated>");
176: System.out
177: .println(" -ty <targetted entry types, comma separated>");
178: System.out.println(" -S show Summary of log entries");
179: System.out
180: .println(" -q if specified, concise version is printed");
181: System.out.println(" Default is verbose version.)");
182: System.out.println("All arguments are optional");
183: }
184: }
|