Package org.apache.hadoop.hbase
Class HBaseCluster
java.lang.Object
org.apache.hadoop.hbase.HBaseCluster
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.conf.Configurable
- Direct Known Subclasses:
DistributedHBaseCluster,MiniHBaseCluster
@Public
public abstract class HBaseCluster
extends Object
implements Closeable, org.apache.hadoop.conf.Configurable
This class defines methods that can help with managing HBase clusters from unit tests and system
tests. There are 3 types of cluster deployments:
- MiniHBaseCluster: each server is run in the same JVM in separate threads, used by unit tests
- DistributedHBaseCluster: the cluster is pre-deployed, system and integration tests can interact with the cluster.
- ProcessBasedLocalHBaseCluster: each server is deployed locally but in separate JVMs.
HBaseCluster unifies the way tests interact with the cluster, so that the same test can be run against a mini-cluster during unit test execution, or a distributed cluster having tens/hundreds of nodes during execution of integration tests.
HBaseCluster exposes client-side public interfaces to tests, so that tests does not assume running in a particular mode. Not all the tests are suitable to be run on an actual cluster, and some tests will still need to mock stuff and introspect internal state. For those use cases from unit tests, or if more control is needed, you can use the subclasses directly. In that sense, this class does not abstract away every interface that MiniHBaseCluster or DistributedHBaseCluster provide.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.hadoop.conf.Configurationprotected org.apache.hadoop.hbase.ClusterMetricsthe status of the cluster before we begin(package private) static final org.slf4j.Logger -
Constructor Summary
ConstructorsConstructorDescriptionHBaseCluster(org.apache.hadoop.conf.Configuration conf) Construct an HBaseCluster -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Closes all the resources held open for this cluster.abstract org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService.BlockingInterfacegetAdminProtocol(org.apache.hadoop.hbase.ServerName serverName) Returns an AdminProtocol interface to the regionserverabstract org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService.BlockingInterfacegetClientProtocol(org.apache.hadoop.hbase.ServerName serverName) Returns a ClientProtocol interface to the regionserverabstract org.apache.hadoop.hbase.ClusterMetricsReturns a ClusterMetrics for this HBase cluster.org.apache.hadoop.conf.ConfigurationgetConf()org.apache.hadoop.hbase.ClusterMetricsReturns a ClusterStatus for this HBase cluster as observed at the starting of the HBaseClusterabstract org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService.BlockingInterfaceReturns anMasterProtos.MasterService.BlockingInterfaceto the active masterorg.apache.hadoop.hbase.ServerNameGet the ServerName of region server serving the first hbase:meta regionabstract org.apache.hadoop.hbase.ServerNamegetServerHoldingRegion(org.apache.hadoop.hbase.TableName tn, byte[] regionName) Get the ServerName of region server serving the specified regionbooleanabstract booleanisKilledRS(org.apache.hadoop.hbase.ServerName serverName) Keeping track of killed servers and being able to check if a particular server was killed makes it possible to do fault tolerance testing for dead servers in a deterministic way.abstract voidkillDataNode(org.apache.hadoop.hbase.ServerName serverName) Kills the datanode process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.abstract voidkillJournalNode(org.apache.hadoop.hbase.ServerName serverName) Kills the journalnode process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.abstract voidkillMaster(org.apache.hadoop.hbase.ServerName serverName) Kills the master process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.abstract voidkillNameNode(org.apache.hadoop.hbase.ServerName serverName) Kills the namenode process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.abstract voidkillRegionServer(org.apache.hadoop.hbase.ServerName serverName) Kills the region server process if this is a distributed cluster, otherwise this causes the region server to exit doing basic clean up only.abstract voidkillZkNode(org.apache.hadoop.hbase.ServerName serverName) Kills the zookeeper node process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.booleanrestoreClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics desiredStatus) Restores the cluster to given state if this is a real cluster, otherwise does nothing.booleanRestores the cluster to it's initial state if this is a real cluster, otherwise does nothing.abstract voidresumeRegionServer(org.apache.hadoop.hbase.ServerName serverName) Resume the region servervoidsetConf(org.apache.hadoop.conf.Configuration conf) abstract voidshutdown()Shut down the HBase clusterabstract voidstartDataNode(org.apache.hadoop.hbase.ServerName serverName) Starts a new datanode on the given hostname or if this is a mini/local cluster, silently logs warning message.abstract voidstartJournalNode(org.apache.hadoop.hbase.ServerName serverName) Starts a new journalnode on the given hostname or if this is a mini/local cluster, silently logs warning message.abstract voidstartMaster(String hostname, int port) Starts a new master on the given hostname or if this is a mini/local cluster, starts a master locally.abstract voidstartNameNode(org.apache.hadoop.hbase.ServerName serverName) Starts a new namenode on the given hostname or if this is a mini/local cluster, silently logs warning message.abstract voidstartRegionServer(String hostname, int port) Starts a new region server on the given hostname or if this is a mini/local cluster, starts a region server locally.abstract voidstartZkNode(String hostname, int port) Starts a new zookeeper node on the given hostname or if this is a mini/local cluster, silently logs warning message.abstract voidstopDataNode(org.apache.hadoop.hbase.ServerName serverName) Stops the datanode if this is a distributed cluster, otherwise silently logs warning message.abstract voidstopJournalNode(org.apache.hadoop.hbase.ServerName serverName) Stops the journalnode if this is a distributed cluster, otherwise silently logs warning message.abstract voidstopMaster(org.apache.hadoop.hbase.ServerName serverName) Stops the given master, by attempting a gradual stop.abstract voidstopNameNode(org.apache.hadoop.hbase.ServerName serverName) Stops the namenode if this is a distributed cluster, otherwise silently logs warning message.abstract voidstopRegionServer(org.apache.hadoop.hbase.ServerName serverName) Stops the given region server, by attempting a gradual stop.abstract voidstopZkNode(org.apache.hadoop.hbase.ServerName serverName) Stops the region zookeeper if this is a distributed cluster, otherwise silently logs warning message.abstract voidsuspendRegionServer(org.apache.hadoop.hbase.ServerName serverName) Suspend the region serverbooleanBlocks until there is an active master and that master has completed initialization.abstract booleanwaitForActiveAndReadyMaster(long timeout) Blocks until there is an active master and that master has completed initialization.voidwaitForDatanodesRegistered(int nbDN) abstract voidwaitForDataNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified datanode to join the clusterabstract voidwaitForDataNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified datanode to stop the thread / process.abstract voidwaitForJournalNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified journalnode to join the clusterabstract voidwaitForJournalNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified journalnode to stopabstract voidwaitForMasterToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified master to stop the thread / process.voidWait for the namenode.abstract voidwaitForNameNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified namenode to join the clusterabstract voidwaitForNameNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified namenode to stopvoidwaitForRegionServerToStart(String hostname, int port, long timeout) Wait for the specified region server to join the clusterabstract voidwaitForRegionServerToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified region server to stop the thread / process.abstract voidwaitForZkNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified zookeeper node to join the clusterabstract voidwaitForZkNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) Wait for the specified zookeeper node to stop the thread / process.abstract voidWait for HBase Cluster to shut down.
-
Field Details
-
LOG
-
conf
-
initialClusterStatus
the status of the cluster before we begin
-
-
Constructor Details
-
HBaseCluster
Construct an HBaseCluster- Parameters:
conf- Configuration to be used for cluster
-
-
Method Details
-
setConf
- Specified by:
setConfin interfaceorg.apache.hadoop.conf.Configurable
-
getConf
- Specified by:
getConfin interfaceorg.apache.hadoop.conf.Configurable
-
getClusterMetrics
Returns a ClusterMetrics for this HBase cluster.- Throws:
IOException- See Also:
-
getInitialClusterMetrics
Returns a ClusterStatus for this HBase cluster as observed at the starting of the HBaseCluster- Throws:
IOException
-
getMasterAdminService
public abstract org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService.BlockingInterface getMasterAdminService() throws IOExceptionReturns anMasterProtos.MasterService.BlockingInterfaceto the active master- Throws:
IOException
-
getAdminProtocol
public abstract org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService.BlockingInterface getAdminProtocol(org.apache.hadoop.hbase.ServerName serverName) throws IOException Returns an AdminProtocol interface to the regionserver- Throws:
IOException
-
getClientProtocol
public abstract org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService.BlockingInterface getClientProtocol(org.apache.hadoop.hbase.ServerName serverName) throws IOException Returns a ClientProtocol interface to the regionserver- Throws:
IOException
-
startRegionServer
Starts a new region server on the given hostname or if this is a mini/local cluster, starts a region server locally.- Parameters:
hostname- the hostname to start the regionserver on- Throws:
IOException- if something goes wrong
-
killRegionServer
public abstract void killRegionServer(org.apache.hadoop.hbase.ServerName serverName) throws IOException Kills the region server process if this is a distributed cluster, otherwise this causes the region server to exit doing basic clean up only.- Throws:
IOException- if something goes wrong
-
isKilledRS
Keeping track of killed servers and being able to check if a particular server was killed makes it possible to do fault tolerance testing for dead servers in a deterministic way. A concrete example of such case is - killing servers and waiting for all regions of a particular table to be assigned. We can check for server column in META table and that its value is not one of the killed servers. -
stopRegionServer
public abstract void stopRegionServer(org.apache.hadoop.hbase.ServerName serverName) throws IOException Stops the given region server, by attempting a gradual stop.- Throws:
IOException- if something goes wrong
-
waitForRegionServerToStart
Wait for the specified region server to join the cluster- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForRegionServerToStop
public abstract void waitForRegionServerToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified region server to stop the thread / process.- Throws:
IOException- if something goes wrong or timeout occurs
-
suspendRegionServer
public abstract void suspendRegionServer(org.apache.hadoop.hbase.ServerName serverName) throws IOException Suspend the region server- Parameters:
serverName- the hostname to suspend the regionserver on- Throws:
IOException- if something goes wrong
-
resumeRegionServer
public abstract void resumeRegionServer(org.apache.hadoop.hbase.ServerName serverName) throws IOException Resume the region server- Parameters:
serverName- the hostname to resume the regionserver on- Throws:
IOException- if something goes wrong
-
startZkNode
Starts a new zookeeper node on the given hostname or if this is a mini/local cluster, silently logs warning message.- Parameters:
hostname- the hostname to start the regionserver on- Throws:
IOException- if something goes wrong
-
killZkNode
Kills the zookeeper node process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.- Throws:
IOException- if something goes wrong
-
stopZkNode
Stops the region zookeeper if this is a distributed cluster, otherwise silently logs warning message.- Throws:
IOException- if something goes wrong
-
waitForZkNodeToStart
public abstract void waitForZkNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified zookeeper node to join the cluster- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForZkNodeToStop
public abstract void waitForZkNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified zookeeper node to stop the thread / process.- Throws:
IOException- if something goes wrong or timeout occurs
-
startDataNode
public abstract void startDataNode(org.apache.hadoop.hbase.ServerName serverName) throws IOException Starts a new datanode on the given hostname or if this is a mini/local cluster, silently logs warning message.- Throws:
IOException- if something goes wrong
-
killDataNode
Kills the datanode process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.- Throws:
IOException- if something goes wrong
-
stopDataNode
Stops the datanode if this is a distributed cluster, otherwise silently logs warning message.- Throws:
IOException- if something goes wrong
-
waitForDataNodeToStart
public abstract void waitForDataNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified datanode to join the cluster- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForDataNodeToStop
public abstract void waitForDataNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified datanode to stop the thread / process.- Throws:
IOException- if something goes wrong or timeout occurs
-
startNameNode
public abstract void startNameNode(org.apache.hadoop.hbase.ServerName serverName) throws IOException Starts a new namenode on the given hostname or if this is a mini/local cluster, silently logs warning message.- Throws:
IOException- if something goes wrong
-
killNameNode
Kills the namenode process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.- Throws:
IOException- if something goes wrong
-
stopNameNode
Stops the namenode if this is a distributed cluster, otherwise silently logs warning message.- Throws:
IOException- if something goes wrong
-
waitForNameNodeToStart
public abstract void waitForNameNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified namenode to join the cluster- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForNameNodeToStop
public abstract void waitForNameNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified namenode to stop- Throws:
IOException- if something goes wrong or timeout occurs
-
startJournalNode
public abstract void startJournalNode(org.apache.hadoop.hbase.ServerName serverName) throws IOException Starts a new journalnode on the given hostname or if this is a mini/local cluster, silently logs warning message.- Throws:
IOException- if something goes wrong
-
killJournalNode
public abstract void killJournalNode(org.apache.hadoop.hbase.ServerName serverName) throws IOException Kills the journalnode process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.- Throws:
IOException- if something goes wrong
-
stopJournalNode
public abstract void stopJournalNode(org.apache.hadoop.hbase.ServerName serverName) throws IOException Stops the journalnode if this is a distributed cluster, otherwise silently logs warning message.- Throws:
IOException- if something goes wrong
-
waitForJournalNodeToStart
public abstract void waitForJournalNodeToStart(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified journalnode to join the cluster- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForJournalNodeToStop
public abstract void waitForJournalNodeToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified journalnode to stop- Throws:
IOException- if something goes wrong or timeout occurs
-
startMaster
Starts a new master on the given hostname or if this is a mini/local cluster, starts a master locally.- Parameters:
hostname- the hostname to start the master on- Throws:
IOException- if something goes wrong
-
killMaster
Kills the master process if this is a distributed cluster, otherwise, this causes master to exit doing basic clean up only.- Throws:
IOException- if something goes wrong
-
stopMaster
Stops the given master, by attempting a gradual stop.- Throws:
IOException- if something goes wrong
-
waitForMasterToStop
public abstract void waitForMasterToStop(org.apache.hadoop.hbase.ServerName serverName, long timeout) throws IOException Wait for the specified master to stop the thread / process.- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForActiveAndReadyMaster
Blocks until there is an active master and that master has completed initialization.- Returns:
- true if an active master becomes available. false if there are no masters left.
- Throws:
IOException- if something goes wrong or timeout occurs
-
waitForActiveAndReadyMaster
Blocks until there is an active master and that master has completed initialization.- Parameters:
timeout- the timeout limit in ms- Returns:
- true if an active master becomes available. false if there are no masters left.
- Throws:
IOException
-
waitUntilShutDown
Wait for HBase Cluster to shut down.- Throws:
IOException
-
shutdown
Shut down the HBase cluster- Throws:
IOException
-
restoreInitialStatus
Restores the cluster to it's initial state if this is a real cluster, otherwise does nothing. This is a best effort restore. If the servers are not reachable, or insufficient permissions, etc. restoration might be partial.- Returns:
- whether restoration is complete
- Throws:
IOException
-
restoreClusterMetrics
public boolean restoreClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics desiredStatus) throws IOException Restores the cluster to given state if this is a real cluster, otherwise does nothing. This is a best effort restore. If the servers are not reachable, or insufficient permissions, etc. restoration might be partial.- Returns:
- whether restoration is complete
- Throws:
IOException
-
getServerHoldingMeta
Get the ServerName of region server serving the first hbase:meta region- Throws:
IOException
-
getServerHoldingRegion
public abstract org.apache.hadoop.hbase.ServerName getServerHoldingRegion(org.apache.hadoop.hbase.TableName tn, byte[] regionName) throws IOException Get the ServerName of region server serving the specified region- Parameters:
regionName- Name of the region in bytestn- Table name that has the region.- Returns:
- ServerName that hosts the region or null
- Throws:
IOException
-
isDistributedCluster
- Returns:
- whether we are interacting with a distributed cluster as opposed to an in-process mini/local cluster.
-
close
Closes all the resources held open for this cluster. Note that this call does not shutdown the cluster.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- See Also:
-
waitForNamenodeAvailable
Wait for the namenode.- Throws:
InterruptedException
-
waitForDatanodesRegistered
- Throws:
Exception
-