use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TestRSGroupsBase method getNumServers.
// return the real number of region servers, excluding the master embedded region server in 2.0+
protected int getNumServers() throws IOException {
ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.MASTER, Option.LIVE_SERVERS));
ServerName masterName = status.getMasterName();
int count = 0;
for (ServerName sn : status.getLiveServerMetrics().keySet()) {
if (!sn.equals(masterName)) {
count++;
}
}
return count;
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TestRSGroupsBase method getTableServerRegionMap.
protected Map<TableName, Map<ServerName, List<String>>> getTableServerRegionMap() throws IOException {
Map<TableName, Map<ServerName, List<String>>> map = Maps.newTreeMap();
Admin admin = TEST_UTIL.getAdmin();
ClusterMetrics metrics = admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.SERVERS_NAME));
for (ServerName serverName : metrics.getServersName()) {
for (RegionInfo region : admin.getRegions(serverName)) {
TableName tableName = region.getTable();
map.computeIfAbsent(tableName, k -> new TreeMap<>()).computeIfAbsent(serverName, k -> new ArrayList<>()).add(region.getRegionNameAsString());
}
}
return map;
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TestMasterFailover method testSimpleMasterFailover.
/**
* Simple test of master failover.
* <p>
* Starts with three masters. Kills a backup master. Then kills the active
* master. Ensures the final master becomes active and we can still contact
* the cluster.
*/
@Test
public void testSimpleMasterFailover() throws Exception {
final int NUM_MASTERS = 3;
final int NUM_RS = 3;
// Start the cluster
HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
try {
StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
TEST_UTIL.startMiniCluster(option);
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
// get all the master threads
List<MasterThread> masterThreads = cluster.getMasterThreads();
// wait for each to come online
for (MasterThread mt : masterThreads) {
assertTrue(mt.isAlive());
}
// verify only one is the active master and we have right number
int numActive = 0;
int activeIndex = -1;
ServerName activeName = null;
HMaster active = null;
for (int i = 0; i < masterThreads.size(); i++) {
if (masterThreads.get(i).getMaster().isActiveMaster()) {
numActive++;
activeIndex = i;
active = masterThreads.get(activeIndex).getMaster();
activeName = active.getServerName();
}
}
assertEquals(1, numActive);
assertEquals(NUM_MASTERS, masterThreads.size());
LOG.info("Active master " + activeName);
// Check that ClusterStatus reports the correct active and backup masters
assertNotNull(active);
ClusterMetrics status = active.getClusterMetrics();
assertEquals(activeName, status.getMasterName());
assertEquals(2, status.getBackupMasterNames().size());
// attempt to stop one of the inactive masters
int backupIndex = (activeIndex == 0 ? 1 : activeIndex - 1);
HMaster master = cluster.getMaster(backupIndex);
LOG.debug("\n\nStopping a backup master: " + master.getServerName() + "\n");
cluster.stopMaster(backupIndex, false);
cluster.waitOnMaster(backupIndex);
// Verify still one active master and it's the same
for (int i = 0; i < masterThreads.size(); i++) {
if (masterThreads.get(i).getMaster().isActiveMaster()) {
assertEquals(activeName, masterThreads.get(i).getMaster().getServerName());
activeIndex = i;
active = masterThreads.get(activeIndex).getMaster();
}
}
assertEquals(1, numActive);
assertEquals(2, masterThreads.size());
int rsCount = masterThreads.get(activeIndex).getMaster().getClusterMetrics().getLiveServerMetrics().size();
LOG.info("Active master " + active.getServerName() + " managing " + rsCount + " regions servers");
assertEquals(3, rsCount);
// wait for the active master to acknowledge loss of the backup from ZK
final HMaster activeFinal = active;
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(5), () -> activeFinal.getBackupMasters().size() == 1);
// Check that ClusterStatus reports the correct active and backup masters
assertNotNull(active);
status = active.getClusterMetrics();
assertEquals(activeName, status.getMasterName());
assertEquals(1, status.getBackupMasterNames().size());
// kill the active master
LOG.debug("\n\nStopping the active master " + active.getServerName() + "\n");
cluster.stopMaster(activeIndex, false);
cluster.waitOnMaster(activeIndex);
// wait for an active master to show up and be ready
assertTrue(cluster.waitForActiveAndReadyMaster());
LOG.debug("\n\nVerifying backup master is now active\n");
// should only have one master now
assertEquals(1, masterThreads.size());
// and he should be active
active = masterThreads.get(0).getMaster();
assertNotNull(active);
status = active.getClusterMetrics();
ServerName masterName = status.getMasterName();
assertNotNull(masterName);
assertEquals(active.getServerName(), masterName);
assertTrue(active.isActiveMaster());
assertEquals(0, status.getBackupMasterNames().size());
int rss = status.getLiveServerMetrics().size();
LOG.info("Active master {} managing {} region servers", masterName.getServerName(), rss);
assertEquals(3, rss);
} finally {
// Stop the cluster
TEST_UTIL.shutdownMiniCluster();
}
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TestMasterFailoverBalancerPersistence method testMasterFailoverBalancerPersistence.
/**
* Test that if the master fails, the load balancer maintains its
* state (running or not) when the next master takes over
*
* @throws Exception
*/
@Test
public void testMasterFailoverBalancerPersistence() throws Exception {
// Start the cluster
HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(3).build();
TEST_UTIL.startMiniCluster(option);
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
assertTrue(cluster.waitForActiveAndReadyMaster());
HMaster active = cluster.getMaster();
// check that the balancer is on by default for the active master
ClusterMetrics clusterStatus = active.getClusterMetrics();
assertTrue(clusterStatus.getBalancerOn());
active = killActiveAndWaitForNewActive(cluster);
// ensure the load balancer is still running on new master
clusterStatus = active.getClusterMetrics();
assertTrue(clusterStatus.getBalancerOn());
// turn off the load balancer
active.balanceSwitch(false);
// once more, kill active master and wait for new active master to show up
active = killActiveAndWaitForNewActive(cluster);
// ensure the load balancer is not running on the new master
clusterStatus = active.getClusterMetrics();
assertFalse(clusterStatus.getBalancerOn());
// Stop the cluster
TEST_UTIL.shutdownMiniCluster();
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TestReplicationStatusAfterLagging method testReplicationStatusAfterLagging.
@Test
public void testReplicationStatusAfterLagging() throws Exception {
UTIL2.shutdownMiniHBaseCluster();
restartSourceCluster(1);
// add some values to cluster 1
for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
Put p = new Put(Bytes.toBytes("row" + i));
p.addColumn(famName, Bytes.toBytes("col1"), Bytes.toBytes("val" + i));
htable1.put(p);
}
UTIL2.startMiniHBaseCluster();
Thread.sleep(10000);
Admin hbaseAdmin = UTIL1.getAdmin();
ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
List<ReplicationLoadSource> loadSources = metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
assertEquals(1, loadSources.size());
ReplicationLoadSource loadSource = loadSources.get(0);
assertTrue(loadSource.hasEditsSinceRestart());
assertTrue(loadSource.getTimestampOfLastShippedOp() > 0);
assertEquals(0, loadSource.getReplicationLag());
}
Aggregations