Author: stack
Date: Wed Sep 8 18:38:16 2010
New Revision: 995185
URL: http://svn.apache.org/viewvc?rev=995185&view=rev
Log:
HBASE-2889 Tool to look at HLogs -- parse and tail -f; added part 1, some fixup
of hlog main
Modified:
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
Modified:
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
URL:
http://svn.apache.org/viewvc/hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java?rev=995185&r1=995184&r2=995185&view=diff
==============================================================================
---
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
(original)
+++
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
Wed Sep 8 18:38:16 2010
@@ -1785,9 +1785,54 @@ public class HLog implements Syncable {
return this.actionListeners.remove(list);
}
+ public static final long FIXED_OVERHEAD = ClassSize.align(
+ ClassSize.OBJECT + (5 * ClassSize.REFERENCE) +
+ ClassSize.ATOMIC_INTEGER + Bytes.SIZEOF_INT + (3 * Bytes.SIZEOF_LONG));
+
private static void usage() {
- System.err.println("Usage: java org.apache.hbase.HLog" +
- " {--dump <logfile>... | --split <logdir>...}");
+ System.err.println("Usage: HLog <ARGS>");
+ System.err.println("Arguments:");
+ System.err.println(" --dump Dump textual representation of passed one or
more files");
+ System.err.println(" For example: HLog --dump
hdfs://example.com:9000/hbase/.logs/MACHINE/LOGFILE");
+ System.err.println(" --split Split the passed directory of WAL logs");
+ System.err.println(" For example: HLog --split
hdfs://example.com:9000/hbase/.logs/DIR");
+ }
+
+ private static void dump(final Configuration conf, final Path p)
+ throws IOException {
+ FileSystem fs = FileSystem.get(conf);
+ if (!fs.exists(p)) {
+ throw new FileNotFoundException(p.toString());
+ }
+ if (!fs.isFile(p)) {
+ throw new IOException(p + " is not a file");
+ }
+ Reader log = getReader(fs, p, conf);
+ try {
+ int count = 0;
+ HLog.Entry entry;
+ while ((entry = log.next()) != null) {
+ System.out.println("#" + count + ", pos=" + log.getPosition() + " " +
+ entry.toString());
+ count++;
+ }
+ } finally {
+ log.close();
+ }
+ }
+
+ private static void split(final Configuration conf, final Path p)
+ throws IOException {
+ FileSystem fs = FileSystem.get(conf);
+ if (!fs.exists(p)) {
+ throw new FileNotFoundException(p.toString());
+ }
+ final Path baseDir = new Path(conf.get(HConstants.HBASE_DIR));
+ final Path oldLogDir = new Path(baseDir,
HConstants.HREGION_OLDLOGDIR_NAME);
+ if (!fs.getFileStatus(p).isDir()) {
+ throw new IOException(p + " is not a directory");
+ }
+ splitLog(baseDir, p, oldLogDir, fs, conf);
}
/**
@@ -1813,38 +1858,18 @@ public class HLog implements Syncable {
}
}
Configuration conf = HBaseConfiguration.create();
- FileSystem fs = FileSystem.get(conf);
- final Path baseDir = new Path(conf.get(HConstants.HBASE_DIR));
- final Path oldLogDir = new Path(baseDir,
HConstants.HREGION_OLDLOGDIR_NAME);
for (int i = 1; i < args.length; i++) {
Path logPath = new Path(args[i]);
- if (!fs.exists(logPath)) {
- throw new FileNotFoundException(args[i] + " does not exist");
- }
- if (dump) {
- if (!fs.isFile(logPath)) {
- throw new IOException(args[i] + " is not a file");
- }
- Reader log = getReader(fs, logPath, conf);
- try {
- HLog.Entry entry;
- while ((entry = log.next()) != null) {
- System.out.println(entry.toString());
- }
- } finally {
- log.close();
+ try {
+ if (dump) {
+ dump(conf, logPath);
+ } else {
+ split(conf, logPath);
}
- } else {
- if (!fs.getFileStatus(logPath).isDir()) {
- throw new IOException(args[i] + " is not a directory");
- }
- splitLog(baseDir, logPath, oldLogDir, fs, conf);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ System.exit(-1);
}
}
}
-
- public static final long FIXED_OVERHEAD = ClassSize.align(
- ClassSize.OBJECT + (5 * ClassSize.REFERENCE) +
- ClassSize.ATOMIC_INTEGER + Bytes.SIZEOF_INT + (3 * Bytes.SIZEOF_LONG));
-
}
Modified:
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
URL:
http://svn.apache.org/viewvc/hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java?rev=995185&r1=995184&r2=995185&view=diff
==============================================================================
---
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
(original)
+++
hbase/branches/0.89.20100830/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
Wed Sep 8 18:38:16 2010
@@ -29,6 +29,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.regionserver.wal.HLog;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.io.SequenceFile;
+import org.mortbay.log.Log;
public class SequenceFileLogReader implements HLog.Reader {
@@ -93,6 +94,9 @@ public class SequenceFileLogReader imple
Configuration conf;
WALReader reader;
+ // Needed logging exceptions
+ Path path;
+ int edit = 0;
public SequenceFileLogReader() { }
@@ -100,12 +104,17 @@ public class SequenceFileLogReader imple
public void init(FileSystem fs, Path path, Configuration conf)
throws IOException {
this.conf = conf;
+ this.path = path;
reader = new WALReader(fs, path, conf);
}
@Override
public void close() throws IOException {
- reader.close();
+ try {
+ reader.close();
+ } catch (IOException ioe) {
+ throw addFileInfoToException(ioe);
+ }
}
@Override
@@ -115,21 +124,29 @@ public class SequenceFileLogReader imple
@Override
public HLog.Entry next(HLog.Entry reuse) throws IOException {
- if (reuse == null) {
+ HLog.Entry e = reuse;
+ if (e == null) {
HLogKey key = HLog.newKey(conf);
WALEdit val = new WALEdit();
- if (reader.next(key, val)) {
- return new HLog.Entry(key, val);
- }
- } else if (reader.next(reuse.getKey(), reuse.getEdit())) {
- return reuse;
+ e = new HLog.Entry(key, val);
+ }
+ boolean b = false;
+ try {
+ b = this.reader.next(e.getKey(), e.getEdit());
+ } catch (IOException ioe) {
+ throw addFileInfoToException(ioe);
}
- return null;
+ edit++;
+ return b? e: null;
}
@Override
public void seek(long pos) throws IOException {
- reader.seek(pos);
+ try {
+ reader.seek(pos);
+ } catch (IOException ioe) {
+ throw addFileInfoToException(ioe);
+ }
}
@Override
@@ -137,4 +154,15 @@ public class SequenceFileLogReader imple
return reader.getPosition();
}
-}
+ private IOException addFileInfoToException(final IOException ioe)
+ throws IOException {
+ long pos = -1;
+ try {
+ pos = getPosition();
+ } catch (IOException e) {
+ Log.warn("Failed getting position to add to throw", e);
+ }
+ return new IOException((this.path == null? "": this.path.toString()) +
+ ", pos=" + pos + ", edit=" + this.edit, ioe);
+ }
+}
\ No newline at end of file