hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r995182 - in /hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal: HLog.java SequenceFileLogReader.java
Date Wed, 08 Sep 2010 18:33:51 GMT
Author: stack
Date: Wed Sep  8 18:33:51 2010
New Revision: 995182

URL: http://svn.apache.org/viewvc?rev=995182&view=rev
Log:
HBASE-2889 Tool to look at HLogs -- parse and tail -f; added part 1, some fixup of hlog main

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java?rev=995182&r1=995181&r2=995182&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java Wed Sep 
8 18:33:51 2010
@@ -1788,9 +1788,54 @@ public class HLog implements Syncable {
     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 <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);
   }
 
   /**
@@ -1809,44 +1854,24 @@ public class HLog implements Syncable {
     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

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java?rev=995182&r1=995181&r2=995182&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceFileLogReader.java
Wed Sep  8 18:33:51 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



Mime
View raw message