You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:05:26 UTC

svn commit: r1181400 - in /hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client: HBaseFsck.java HBaseFsckRepair.java

Author: nspiegelberg
Date: Tue Oct 11 02:05:25 2011
New Revision: 1181400

URL: http://svn.apache.org/viewvc?rev=1181400&view=rev
Log:
HBase fix should prompt user

Summary:
Ask user if he/she really wants to fix inconsistencies detected by fsck.

For every inconsistency, it asks the user y/n.

Test Plan:
No unit tests.

DiffCamp Revision: 166106
Reviewed By: kannan
Commenters: nspiegelberg
CC: nspiegelberg, dhruba, kannan
Revert Plan:
OK

Modified:
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java?rev=1181400&r1=1181399&r2=1181400&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java Tue Oct 11 02:05:25 2011
@@ -74,6 +74,7 @@ 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 static boolean promptResponse = false;  // "no" to all prompt questions
 
   /**
    * Constructor
@@ -370,8 +371,9 @@ public class HBaseFsck {
       // If we are trying to fix the errors
       if (shouldFix()) {
         errors.print("Trying to fix unassigned region...");
-        setShouldRerun();
-        HBaseFsckRepair.fixUnassigned(this.conf, hbi.metaEntry);
+        if (HBaseFsckRepair.fixUnassigned(this.conf, hbi.metaEntry)) {
+          setShouldRerun();
+        }
       }
     } else if (inMeta && inHdfs && isDeployed && !shouldBeDeployed) {
       errors.reportError("Region " + descriptiveName + " has should not be deployed according " +
@@ -383,8 +385,9 @@ public class HBaseFsck {
       // If we are trying to fix the errors
       if (shouldFix()) {
         errors.print("Trying to fix assignment error...");
-        setShouldRerun();
-        HBaseFsckRepair.fixDupeAssignment(this.conf, hbi.metaEntry, hbi.deployedOn);
+        if (HBaseFsckRepair.fixDupeAssignment(this.conf, hbi.metaEntry, hbi.deployedOn)) {
+          setShouldRerun();
+        }
       }
     } else if (inMeta && inHdfs && isDeployed && !deploymentMatchesMeta) {
       errors.reportError("Region " + descriptiveName + " listed in META on region server " +
@@ -393,8 +396,9 @@ public class HBaseFsck {
       // If we are trying to fix the errors
       if (shouldFix()) {
         errors.print("Trying to fix assignment error...");
-        setShouldRerun();
-        HBaseFsckRepair.fixDupeAssignment(this.conf, hbi.metaEntry, hbi.deployedOn);
+        if (HBaseFsckRepair.fixDupeAssignment(this.conf, hbi.metaEntry, hbi.deployedOn)) {
+          setShouldRerun();
+        }
       }
     } else {
       errors.reportError("Region " + descriptiveName + " is in an unforeseen state:" +
@@ -581,9 +585,10 @@ public class HBaseFsck {
         errors.reportError(".META. is not found on any region.");
         if (shouldFix()) {
           errors.print("Trying to fix a problem with .META...");
-          setShouldRerun();
           // try to fix it (treat it as unassigned region)
-          HBaseFsckRepair.fixUnassigned(conf, root.metaEntry);
+          if (HBaseFsckRepair.fixUnassigned(conf, root.metaEntry)) {
+            setShouldRerun();
+          }
         }
       }
       // If there are more than one regions pretending to hold the .META.
@@ -591,13 +596,14 @@ public class HBaseFsck {
         errors.reportError(".META. is found on more than one region.");
         if (shouldFix()) {
           errors.print("Trying to fix a problem with .META...");
-          setShouldRerun();
           // try fix it (treat is a dupe assignment)
           List <HServerAddress> deployedOn = Lists.newArrayList();
           for (HbckInfo mRegion : metaRegions) {
             deployedOn.add(mRegion.metaEntry.regionServer);
           }
-          HBaseFsckRepair.fixDupeAssignment(conf, root.metaEntry, deployedOn);
+          if (HBaseFsckRepair.fixDupeAssignment(conf, root.metaEntry, deployedOn )) {
+            setShouldRerun();
+          }
         }
       }
       // rerun hbck with hopefully fixed META
@@ -840,6 +846,17 @@ public class HBaseFsck {
   }
 
   /**
+   * Let the user allow the opportunity to specify "-y" to all
+   * reconfirmation questions.
+   */
+  static void setPromptResponse(boolean value) {
+    promptResponse = value;
+  }
+  static boolean getPromptResponse() {
+    return promptResponse;
+  }
+
+  /**
    * We are interested in only those tables that have not changed their state in
    * META during the last few seconds specified by hbase.admin.fsck.timelag
    * @param seconds - the time in seconds
@@ -855,7 +872,9 @@ public class HBaseFsck {
     System.err.println("   -timelag {timeInSeconds}  Process only regions that " +
                        " have not experienced any metadata updates in the last " +
                        " {{timeInSeconds} seconds.");
-    System.err.println("   -fix Try to fix some of the errors.");
+    System.err.println("   -fix [-y] Try to fix some of the errors." +
+                       "           If -y is specified, then do not prompt for " +
+                       "           reconfirmation from users.");
     System.err.println("   -summary Print only summary of the tables and status.");
     Runtime.getRuntime().exit(-2);
   }
@@ -892,6 +911,8 @@ public class HBaseFsck {
         i++;
       } else if (cmd.equals("-fix")) {
         fsck.setFixErrors();
+      } else if (cmd.equals("-y")) {
+        fsck.setPromptResponse(true);
       } else if (cmd.equals("-summary")) {
         fsck.setSummary();
       } else {

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java?rev=1181400&r1=1181399&r2=1181400&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java Tue Oct 11 02:05:25 2011
@@ -33,10 +33,15 @@ import org.apache.zookeeper.KeeperExcept
 
 public class HBaseFsckRepair {
 
-  public static void fixDupeAssignment(Configuration conf, HRegionInfo region,
+  public static boolean fixDupeAssignment(Configuration conf, HRegionInfo region,
       List<HServerAddress> servers)
   throws IOException {
 
+    // ask if user really really wants to fix this region
+    if (!prompt("Region " + region + " with duplicate assignment. ")) {
+      return false;
+    }
+
     HRegionInfo actualRegion = new HRegionInfo(region);
 
     // Clear status in master and zk
@@ -50,19 +55,26 @@ public class HBaseFsckRepair {
 
     // It's unassigned so fix it as such
     fixUnassigned(conf, actualRegion);
+    return true;
   }
 
-  public static void fixUnassigned(Configuration conf, HRegionInfo region)
+  public static boolean fixUnassigned(Configuration conf, HRegionInfo region)
   throws IOException {
 
     HRegionInfo actualRegion = new HRegionInfo(region);
 
+    // ask if user really really wants to fix this region
+    if (!prompt("Region " + region + " is not assigned. ")) {
+      return false;
+    }
+
     // Clear status in master and zk
     clearInMaster(conf, actualRegion);
     clearInZK(conf, actualRegion);
 
     // Clear assignment in META or ROOT
     clearAssignment(conf, actualRegion);
+    return true;
   }
 
   private static void clearInMaster(Configuration conf, HRegionInfo region)
@@ -111,4 +123,27 @@ public class HBaseFsckRepair {
         HConstants.STARTCODE_QUALIFIER);
     ht.delete(del);
   }
+
+  /**
+   * Ask the user whether we should fix this problem.
+   * Returns true if we should continue to fix the problem.
+   */
+  private static boolean prompt(String msg) throws IOException {
+    // if the user has already specified "yes" to all prompt questions,
+    // short circuit this test.
+    if (HBaseFsck.getPromptResponse()) {
+      return true;
+    }
+    int inChar;
+    while (true) {
+      System.out.println(msg + "Fix(y/n):");
+      inChar = System.in.read();
+      if (inChar == 'n' || inChar == 'N') {
+        System.out.println("Not fixing " + msg);
+        return false;
+      } else if (inChar == 'y' || inChar == 'Y') {
+        return true;
+      }
+    }
+  }
 }