KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > util > DbPrintLog


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: DbPrintLog.java,v 1.39 2006/10/30 21:14:28 bostic Exp $
7  */

8
9 package com.sleepycat.je.util;
10
11 import java.io.File JavaDoc;
12 import java.io.IOException JavaDoc;
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 /**
26  * DbPrintLog is a debugging utility that dumps JE log files into a human
27  * readable form.
28  */

29 public class DbPrintLog {
30
31     /**
32      * Dump a JE log into human readable form.
33      */

34     private void dump(File JavaDoc envHome,
35               String JavaDoc entryTypes,
36               String JavaDoc txnIds,
37               long startLsn,
38               long endLsn,
39               boolean verbose,
40                       boolean stats)
41         throws IOException JavaDoc, 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         // Make a reader.
52
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         // Enclose the output in a tag to keep proper XML syntax.
62
System.out.println("<DbPrintLog>");
63         while (reader.readNextEntry()) {
64         }
65         reader.summarize();
66         System.out.println("</DbPrintLog>");
67         env.close();
68     }
69
70     /**
71      * Main
72      */

73     public static void main(String JavaDoc [] argv) {
74         try {
75             int whichArg = 0;
76             String JavaDoc entryTypes = null;
77             String JavaDoc txnIds = null;
78             long startLsn = DbLsn.NULL_LSN;
79             long endLsn = DbLsn.NULL_LSN;
80             boolean verbose = true;
81             boolean stats = false;
82
83             // default to looking in current directory
84
File JavaDoc envHome = new File JavaDoc(".");
85             Key.DUMP_BINARY = true;
86
87             while (whichArg < argv.length) {
88                 String JavaDoc nextArg = argv[whichArg];
89                 if (nextArg.equals("-h")) {
90                     whichArg++;
91                     envHome = new File JavaDoc(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 JavaDoc 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 JavaDoc 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