You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by sa...@apache.org on 2019/08/09 08:12:01 UTC

[hbase] branch branch-2.2 updated: HBASE-22803 Modify config value range to enable turning off of the hbck chore (#466)

This is an automated email from the ASF dual-hosted git repository.

sakthi pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.2 by this push:
     new 66197dd  HBASE-22803 Modify config value range to enable turning off of the hbck chore (#466)
66197dd is described below

commit 66197dd2d0ee601e640b700a777cef085765d000
Author: Sakthi <sa...@apache.org>
AuthorDate: Thu Aug 8 17:33:42 2019 -0700

    HBASE-22803 Modify config value range to enable turning off of the hbck chore (#466)
    
    Signed-off-by: Guanghao Zhang <zg...@apache.org>
---
 .../org/apache/hadoop/hbase/master/HbckChore.java  | 35 ++++++++++++++++++++++
 .../hadoop/hbase/master/MasterRpcServices.java     |  6 +---
 .../main/resources/hbase-webapps/master/hbck.jsp   |  4 +++
 .../hbase/master/assignment/TestHbckChore.java     | 18 +++++++++++
 4 files changed, 58 insertions(+), 5 deletions(-)

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 0417e30..5bb4e95 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
@@ -101,14 +101,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();
     disabledTableRegions.clear();
@@ -127,6 +139,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 c8b56fb..49dda7d 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
@@ -2324,11 +2324,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 49db066..014a189 100644
--- a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
+++ b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
@@ -81,7 +81,11 @@
     <div class="page-header">
       <h1>HBCK Chore Report</h1>
       <p>
+        <% if (hbckChore.isDisabled()) { %>
+        <span>HBCK chore is currently disabled. Set hbase.master.hbck.chore.interval > 0 in the config & do a rolling-restart to enable it.</span>
+        <% } else { %>
         <span>Checking started at <%= iso8601start %> and generated report at <%= iso8601end %>. Execute 'hbck_chore_run' in hbase shell to generate a new sub-report.</span>
+        <% } %>
       </p>
     </div>
   </div>
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java
index 7ef90d4..a367318 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java
@@ -198,4 +198,22 @@ public class TestHbckChore extends TestAssignmentManagerBase {
     hbckChore.choreForTesting();
     assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
   }
+
+  @Test
+  public void testChoreDisable() {
+    // The way to disable to chore is to set hbase.master.hbck.chore.interval <= 0
+    // When the interval is > 0, the chore should run.
+    long lastRunTime = hbckChore.getCheckingEndTimestamp();
+    hbckChore.choreForTesting();
+    boolean ran = lastRunTime != hbckChore.getCheckingEndTimestamp();
+    assertTrue(ran);
+
+    // When the interval <= 0, the chore shouldn't run
+    master.getConfiguration().setInt("hbase.master.hbck.chore.interval", 0);
+    HbckChore hbckChoreWithChangedConf = new HbckChore(master);
+    lastRunTime = hbckChoreWithChangedConf.getCheckingEndTimestamp();
+    hbckChoreWithChangedConf.choreForTesting();
+    ran = lastRunTime != hbckChoreWithChangedConf.getCheckingEndTimestamp();
+    assertFalse(ran);
+  }
 }
\ No newline at end of file