diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java index e2c4008b70c..64da15d1e88 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java @@ -99,14 +99,26 @@ public class HbckChore extends ScheduledChore { private volatile long checkingStartTimestamp = 0; private volatile long checkingEndTimestamp = 0; + private boolean disabled = false; + public HbckChore(MasterServices master) { super("HbckChore-", master, master.getConfiguration().getInt(HBCK_CHORE_INTERVAL, DEFAULT_HBCK_CHORE_INTERVAL)); this.master = master; + int interval = + master.getConfiguration().getInt(HBCK_CHORE_INTERVAL, DEFAULT_HBCK_CHORE_INTERVAL); + if (interval <= 0) { + LOG.warn(HBCK_CHORE_INTERVAL + " is <=0 hence disabling hbck chore"); + disableChore(); + } } @Override protected synchronized void chore() { + if (isDisabled() || isRunning()) { + LOG.warn("hbckChore is either disabled or is already running. Can't run the chore"); + return; + } running = true; regionInfoMap.clear(); orphanRegionsOnRS.clear(); @@ -124,6 +136,29 @@ public class HbckChore extends ScheduledChore { running = false; } + // This function does the sanity checks of making sure the chore is not run when it is + // disabled or when it's already running. It returns whether the chore was actually run or not. + protected boolean runChore() { + if (isDisabled() || isRunning()) { + if (isDisabled()) { + LOG.warn("hbck chore is disabled! Set " + HBCK_CHORE_INTERVAL + " > 0 to enable it."); + } else { + LOG.warn("hbck chore already running. Can't run till it finishes."); + } + return false; + } + chore(); + return true; + } + + private void disableChore() { + this.disabled = true; + } + + public boolean isDisabled() { + return this.disabled; + } + private void saveCheckResultToSnapshot() { // Need synchronized here, as this "snapshot" may be access by web ui. rwLock.writeLock().lock(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java index 4c2b7cf1258..ed64a3b6feb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java @@ -2342,11 +2342,7 @@ public class MasterRpcServices extends RSRpcServices rpcPreCheck("runHbckChore"); LOG.info("{} request HBCK chore to run", master.getClientIdAuditPrefix()); HbckChore hbckChore = master.getHbckChore(); - boolean ran = false; - if (!hbckChore.isRunning()) { - hbckChore.chore(); - ran = true; - } + boolean ran = hbckChore.runChore(); return RunHbckChoreResponse.newBuilder().setRan(ran).build(); } diff --git a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp index 183740bb4e2..1da84ac815b 100644 --- a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp @@ -80,7 +80,11 @@
+ <% if (hbckChore.isDisabled()) { %> + HBCK chore is currently disabled. Set hbase.master.hbck.chore.interval > 0 in the config & do a rolling-restart to enable it. + <% } else { %> Checking started at <%= iso8601start %> and generated report at <%= iso8601end %>. Execute 'hbck_chore_run' in hbase shell to generate a new sub-report. + <% } %>