hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1169996 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
Date Tue, 13 Sep 2011 01:15:17 GMT
Author: todd
Date: Tue Sep 13 01:15:17 2011
New Revision: 1169996

URL: http://svn.apache.org/viewvc?rev=1169996&view=rev
Log:
HBASE-4272. Add -metaonly flag to hbck feature to only inspect and try to repair META and
ROOT.

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1169996&r1=1169995&r2=1169996&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Tue Sep 13 01:15:17 2011
@@ -582,6 +582,8 @@ Release 0.90.5 - Unreleased
                for a region (todd)
    HBASE-4313  Refactor TestHBaseFsck to make adding individual hbck tests
                easier (Jonathan Hsieh)
+   HBASE-4272. Add -metaonly flag to hbck feature to only inspect and try
+               to repair META and ROOT. (todd)
 
 Release 0.90.4 - August 10, 2011
 

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java?rev=1169996&r1=1169995&r2=1169996&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java Tue Sep 13 01:15:17
2011
@@ -92,6 +92,8 @@ public class HBaseFsck {
   private boolean fix = false; // do we want to try fixing the errors?
   private boolean rerun = false; // if we tried to fix something rerun hbck
   private static boolean summary = false; // if we want to print less output
+  private boolean checkMetaOnly = false;
+  
   // Empty regioninfo qualifiers in .META.
   private Set<Result> emptyRegionInfoQualifiers = new HashSet<Result>();
   private int numThreads = MAX_NUM_THREADS;
@@ -145,6 +147,7 @@ public class HBaseFsck {
       errors.reportError("Encountered fatal error. Exiting...");
       return -1;
     }
+    
     getMetaEntries();
 
     // Check if .META. is found only once and in the right place
@@ -155,28 +158,28 @@ public class HBaseFsck {
     }
 
     // get a list of all tables that have not changed recently.
-    AtomicInteger numSkipped = new AtomicInteger(0);
-    HTableDescriptor[] allTables = getTables(numSkipped);
-    errors.print("Number of Tables: " +
-        (allTables == null ? 0 : allTables.length));
-    if (details) {
-      if (numSkipped.get() > 0) {
-        errors.detail("Number of Tables in flux: " + numSkipped.get());
-      }
-      if (allTables != null && allTables.length > 0) {
-        for (HTableDescriptor td : allTables) {
-        String tableName = td.getNameAsString();
-        errors.detail("  Table: " + tableName + "\t" +
-                           (td.isReadOnly() ? "ro" : "rw") + "\t" +
-                           (td.isRootRegion() ? "ROOT" :
-                            (td.isMetaRegion() ? "META" : "    ")) + "\t" +
-                           " families: " + td.getFamilies().size());
+    if (!checkMetaOnly) {
+      AtomicInteger numSkipped = new AtomicInteger(0);
+      HTableDescriptor[] allTables = getTables(numSkipped);
+      errors.print("Number of Tables: " +
+          (allTables == null ? 0 : allTables.length));
+      if (details) {
+        if (numSkipped.get() > 0) {
+          errors.detail("Number of Tables in flux: " + numSkipped.get());
+        }
+        if (allTables != null && allTables.length > 0) {
+          for (HTableDescriptor td : allTables) {
+          String tableName = td.getNameAsString();
+          errors.detail("  Table: " + tableName + "\t" +
+                             (td.isReadOnly() ? "ro" : "rw") + "\t" +
+                             (td.isRootRegion() ? "ROOT" :
+                              (td.isMetaRegion() ? "META" : "    ")) + "\t" +
+                             " families: " + td.getFamilies().size());
+          }
         }
-
       }
-
     }
-
+    
     // From the master, get a list of all known live region servers
     Collection<ServerName> regionServers = status.getServers();
     errors.print("Number of live region servers: " +
@@ -278,10 +281,15 @@ public class HBaseFsck {
     boolean foundVersionFile = false;
     FileStatus[] files = fs.listStatus(rootDir);
     for (FileStatus file : files) {
-      if (file.getPath().getName().equals(HConstants.VERSION_FILE_NAME)) {
+      String dirName = file.getPath().getName();
+      if (dirName.equals(HConstants.VERSION_FILE_NAME)) {
         foundVersionFile = true;
       } else {
-        tableDirs.add(file);
+        if (!checkMetaOnly ||
+            dirName.equals("-ROOT-") ||
+            dirName.equals(".META.")) {
+          tableDirs.add(file);
+        }
       }
     }
 
@@ -814,8 +822,11 @@ public class HBaseFsck {
     MetaScanner.metaScan(conf, visitor, null, null,
       Integer.MAX_VALUE, HConstants.ROOT_TABLE_NAME);
 
-    // Scan .META. to pick up user regions
-    MetaScanner.metaScan(conf, visitor);
+    if (!checkMetaOnly) {
+      // Scan .META. to pick up user regions
+      MetaScanner.metaScan(conf, visitor);
+    }
+    
     errors.print("");
   }
 
@@ -1050,6 +1061,9 @@ public class HBaseFsck {
 
         // list all online regions from this region server
         List<HRegionInfo> regions = server.getOnlineRegions();
+        if (hbck.checkMetaOnly) {
+          regions = filterOnlyMetaRegions(regions);
+        }
         if (details) {
           errors.detail("RegionServer: " + rsinfo.getServerName() +
                            " number of regions: " + regions.size());
@@ -1075,6 +1089,16 @@ public class HBaseFsck {
         notifyAll(); // wakeup anybody waiting for this item to be done
       }
     }
+
+    private List<HRegionInfo> filterOnlyMetaRegions(List<HRegionInfo> regions)
{
+      List<HRegionInfo> ret = Lists.newArrayList();
+      for (HRegionInfo hri : regions) {
+        if (hri.isMetaRegion() || hri.isRootRegion()) {
+          ret.add(hri);
+        }
+      }
+      return ret;
+    }
   }
 
   /**
@@ -1165,6 +1189,14 @@ public class HBaseFsck {
   }
 
   /**
+   * Set META check mode.
+   * Print only info about META table deployment/state
+   */
+  void setCheckMetaOnly() {
+    checkMetaOnly = true;
+  }
+
+  /**
    * Check if we should rerun fsck again. This checks if we've tried to
    * fix something and we should rerun fsck tool again.
    * Display the full report from fsck. This displays all live and dead
@@ -1210,7 +1242,7 @@ public class HBaseFsck {
     System.err.println("   -sleepBeforeRerun {timeInSeconds} Sleep this many seconds" +
                        " before checking if the fix worked if run with -fix");
     System.err.println("   -summary Print only summary of the tables and status.");
-
+    System.err.println("   -metaonly Only check the state of ROOT and META tables.");
     Runtime.getRuntime().exit(-2);
   }
 
@@ -1261,6 +1293,8 @@ public class HBaseFsck {
         fsck.setFixErrors(true);
       } else if (cmd.equals("-summary")) {
         fsck.setSummary();
+      } else if (cmd.equals("-metaonly")) {
+        fsck.setCheckMetaOnly();
       } else {
         String str = "Unknown command line option : " + cmd;
         LOG.info(str);



Mime
View raw message