Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (revision 995156) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (working copy) @@ -1788,11 +1788,56 @@ return new Path(regiondir, RECOVERED_EDITS_DIR); } + 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 ... | --split ...}"); + System.err.println("Usage: HLog "); + 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); + } + /** * Pass one or more log file names and it will either dump out a text version * on stdout or split the specified log files. @@ -1809,44 +1854,24 @@ if (args[0].compareTo("--dump") != 0) { if (args[0].compareTo("--split") == 0) { dump = false; - } else { usage(); System.exit(-1); } } 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++) { + try { 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(); - } + dump(conf, logPath); } else { - if (!fs.getFileStatus(logPath).isDir()) { - throw new IOException(args[i] + " is not a directory"); - } - splitLog(baseDir, logPath, oldLogDir, fs, conf); + split(conf, logPath); } + } 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)); } \ No newline at end of file Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java (revision 995156) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java (working copy) @@ -29,6 +29,7 @@ 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 @@ Configuration conf; WALReader reader; + // Needed logging exceptions + Path path; + int edit = 0; public SequenceFileLogReader() { } @@ -100,12 +104,17 @@ 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 @@ @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); } - return null; + boolean b = false; + try { + b = this.reader.next(e.getKey(), e.getEdit()); + } catch (IOException ioe) { + throw addFileInfoToException(ioe); + } + 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 @@ 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