From bbf60850f066b2cd09a78fc14f3636393d1ebb6f Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Wed, 15 Jul 2015 12:03:59 -0700 Subject: [PATCH] HBASE-14092 Add -noLock and -noBalanceSwitch options to hbck --- .../org/apache/hadoop/hbase/util/HBaseFsck.java | 50 ++++++++++++++++------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index 0c3ff83..abf4977 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -231,6 +231,8 @@ public class HBaseFsck extends Configured implements Closeable { * Options ***********/ private static boolean details = false; // do we display the full report + private static boolean useLock = true; // do we use the hbck exclusivity lock + private static boolean switchBalancer = true; // do we use the hbck exclusivity lock private long timelag = DEFAULT_TIME_LAG; // tables whose modtime is older private boolean fixAssignments = false; // fix assignment errors? private boolean fixMeta = false; // fix meta errors? @@ -476,18 +478,21 @@ public class HBaseFsck extends Configured implements Closeable { */ public void connect() throws IOException { - // Check if another instance of balancer is running - hbckOutFd = checkAndMarkRunningHbck(); - if (hbckOutFd == null) { - setRetCode(-1); - LOG.error("Another instance of hbck is running, exiting this instance.[If you are sure" + - " no other instance is running, delete the lock file " + - HBCK_LOCK_PATH + " and rerun the tool]"); - throw new IOException("Duplicate hbck - Abort"); + if (useLock) { + // Check if another instance of balancer is running + hbckOutFd = checkAndMarkRunningHbck(); + if (hbckOutFd == null) { + setRetCode(-1); + LOG.error("Another instance of hbck is running, exiting this instance.[If you are sure" + + " no other instance is running, delete the lock file " + + HBCK_LOCK_PATH + " and rerun the tool]"); + throw new IOException("Duplicate hbck - Abort"); + } + + // Make sure to cleanup the lock + hbckLockCleanup.set(true); } - // Make sure to cleanup the lock - hbckLockCleanup.set(true); // Add a shutdown hook to this thread, in case user tries to // kill the hbck with a ctrl-c, we want to cleanup the lock so that @@ -666,7 +671,6 @@ public class HBaseFsck extends Configured implements Closeable { fixOrphanTables(); LOG.info("Checking and fixing region consistency"); - // Check and fix consistency checkAndFixConsistency(); @@ -684,13 +688,19 @@ public class HBaseFsck extends Configured implements Closeable { errors.print("Version: " + status.getHBaseVersion()); offlineHdfsIntegrityRepair(); + boolean oldBalancer = true; // turn the balancer off - boolean oldBalancer = admin.setBalancerRunning(false, true); + if (switchBalancer) { + oldBalancer = admin.setBalancerRunning(false, true); + } + try { onlineConsistencyRepair(); } finally { - admin.setBalancerRunning(oldBalancer, false); + if (switchBalancer) { + admin.setBalancerRunning(oldBalancer, false); + } } if (checkRegionBoundaries) { @@ -4140,6 +4150,14 @@ public class HBaseFsck extends Configured implements Closeable { details = true; } + public static void setNoLock() { + useLock = false; + } + + public static void setNoBalaceSwitch() { + switchBalancer = false; + } + /** * Set summary mode. * Print only summary of the tables and status (OK or INCONSISTENT) @@ -4392,6 +4410,8 @@ public class HBaseFsck extends Configured implements Closeable { out.println(" -metaonly Only check the state of the hbase:meta table."); out.println(" -sidelineDir HDFS path to backup existing meta."); out.println(" -boundaries Verify that regions boundaries are the same between META and store files."); + out.println(" -noLock Turn off using the hdfs lock file."); + out.println(" -noBalanceSwitch Don't switch the balancer off."); out.println(""); out.println(" Metadata Repair options: (expert features, use with caution!)"); @@ -4481,6 +4501,10 @@ public class HBaseFsck extends Configured implements Closeable { return printUsageAndExit(); } else if (cmd.equals("-details")) { setDisplayFullReport(); + } else if (cmd.equals("-noLock")) { + setNoLock(); + } else if (cmd.equals("-noBalanceSwitch")) { + setNoBalaceSwitch(); } else if (cmd.equals("-timelag")) { if (i == args.length - 1) { errors.reportError(ERROR_CODE.WRONG_USAGE, "HBaseFsck: -timelag needs a value."); -- 2.4.3