You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by el...@apache.org on 2018/12/07 22:29:15 UTC

[32/51] [abbrv] hbase git commit: HBASE-18735 Provide an option to kill a MiniHBaseCluster without waiting on shutdown

HBASE-18735 Provide an option to kill a MiniHBaseCluster without waiting on shutdown

Signed-off-by: Josh Elser <el...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3ad2a89f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3ad2a89f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3ad2a89f

Branch: refs/heads/HBASE-20952
Commit: 3ad2a89fdfb1e330e8e743ddb46f61e346cf15ba
Parents: fdddc47
Author: Artem Ervits <ar...@gmail.com>
Authored: Thu Nov 29 16:37:50 2018 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Thu Nov 29 16:37:50 2018 -0500

----------------------------------------------------------------------
 .../hadoop/hbase/HBaseTestingUtility.java       | 44 +++++++++++++++-----
 .../hadoop/hbase/TestHBaseTestingUtility.java   | 35 ++++++++++++++--
 2 files changed, 64 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/3ad2a89f/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
index 655bbdb..31a7cad 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
@@ -1237,9 +1237,41 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
   }
 
   /**
-   * Shutdown HBase mini cluster.  Does not shutdown zk or dfs if running.
+   * Shutdown HBase mini cluster.Does not shutdown zk or dfs if running.
+   * @throws java.io.IOException in case command is unsuccessful
    */
   public void shutdownMiniHBaseCluster() throws IOException {
+    cleanup();
+    if (this.hbaseCluster != null) {
+      this.hbaseCluster.shutdown();
+      // Wait till hbase is down before going on to shutdown zk.
+      this.hbaseCluster.waitUntilShutDown();
+      this.hbaseCluster = null;
+    }
+    if (zooKeeperWatcher != null) {
+      zooKeeperWatcher.close();
+      zooKeeperWatcher = null;
+    }
+  }
+
+  /**
+   * Abruptly Shutdown HBase mini cluster. Does not shutdown zk or dfs if running.
+   * @throws java.io.IOException throws in case command is unsuccessful
+   */
+  public void killMiniHBaseCluster() throws IOException {
+    cleanup();
+    if (this.hbaseCluster != null) {
+      getMiniHBaseCluster().killAll();
+      this.hbaseCluster = null;
+    }
+    if (zooKeeperWatcher != null) {
+      zooKeeperWatcher.close();
+      zooKeeperWatcher = null;
+    }
+  }
+
+  // close hbase admin, close current connection and reset MIN MAX configs for RS.
+  private void cleanup() throws IOException {
     if (hbaseAdmin != null) {
       hbaseAdmin.close();
       hbaseAdmin = null;
@@ -1251,16 +1283,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
     // unset the configuration for MIN and MAX RS to start
     conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1);
     conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -1);
-    if (this.hbaseCluster != null) {
-      this.hbaseCluster.shutdown();
-      // Wait till hbase is down before going on to shutdown zk.
-      this.hbaseCluster.waitUntilShutDown();
-      this.hbaseCluster = null;
-    }
-    if (zooKeeperWatcher != null) {
-      zooKeeperWatcher.close();
-      zooKeeperWatcher = null;
-    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/3ad2a89f/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
index 97de8a9..0ec97ef 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
@@ -26,11 +26,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Random;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
@@ -62,6 +58,9 @@ import org.slf4j.LoggerFactory;
  */
 @Category({MiscTests.class, LargeTests.class})
 public class TestHBaseTestingUtility {
+  private static final int NUMTABLES = 1;
+  private static final int NUMROWS = 100;
+  private static final int NUMREGIONS = 10;
 
   @ClassRule
   public static final HBaseClassTestRule CLASS_RULE =
@@ -471,4 +470,32 @@ public class TestHBaseTestingUtility {
       htu.shutdownMiniCluster();
     }
   }
+
+  // This test demonstrates how long killHBTU takes vs. shutdownHBTU takes
+  // for realistic results, adjust NUMROWS, NUMTABLES to much larger number.
+  @Test
+  public void testKillMiniHBaseCluster() throws Exception {
+
+    HBaseTestingUtility htu = new HBaseTestingUtility();
+    htu.startMiniZKCluster();
+
+    try {
+      htu.startMiniHBaseCluster();
+
+      TableName tableName;
+      byte[] FAM_NAME;
+
+      for(int i = 0; i < NUMTABLES; i++) {
+        tableName = TableName.valueOf(name.getMethodName() + i);
+        FAM_NAME = Bytes.toBytes("fam" + i);
+
+        try (Table table = htu.createMultiRegionTable(tableName, FAM_NAME, NUMREGIONS)) {
+          htu.loadRandomRows(table, FAM_NAME, 100, NUMROWS);
+        }
+      }
+    } finally {
+      htu.killMiniHBaseCluster();
+      htu.shutdownMiniZKCluster();
+    }
+  }
 }