HBASE-18735 Provide an option to kill a MiniHBaseCluster without waiting on shutdown
Signed-off-by: Josh Elser <elserj@apache.org>
This commit is contained in:
parent
fdddc47e77
commit
3ad2a89fdf
|
@ -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 {
|
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) {
|
if (hbaseAdmin != null) {
|
||||||
hbaseAdmin.close();
|
hbaseAdmin.close();
|
||||||
hbaseAdmin = null;
|
hbaseAdmin = null;
|
||||||
|
@ -1251,16 +1283,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
|
||||||
// unset the configuration for MIN and MAX RS to start
|
// unset the configuration for MIN and MAX RS to start
|
||||||
conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1);
|
conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1);
|
||||||
conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,11 +26,7 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
|
@ -62,6 +58,9 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
@Category({MiscTests.class, LargeTests.class})
|
@Category({MiscTests.class, LargeTests.class})
|
||||||
public class TestHBaseTestingUtility {
|
public class TestHBaseTestingUtility {
|
||||||
|
private static final int NUMTABLES = 1;
|
||||||
|
private static final int NUMROWS = 100;
|
||||||
|
private static final int NUMREGIONS = 10;
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static final HBaseClassTestRule CLASS_RULE =
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
|
@ -471,4 +470,32 @@ public class TestHBaseTestingUtility {
|
||||||
htu.shutdownMiniCluster();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue