Search in sources :

Example 31 with ClusterMetrics

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;
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName)

Example 32 with ClusterMetrics

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;
}
Also used : Waiter(org.apache.hadoop.hbase.Waiter) LoggerFactory(org.slf4j.LoggerFactory) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HBaseClusterInterface(org.apache.hadoop.hbase.HBaseClusterInterface) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerManager(org.apache.hadoop.hbase.master.ServerManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MasterCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment) SnapshotManager(org.apache.hadoop.hbase.master.snapshot.SnapshotManager) TestName(org.junit.rules.TestName) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Configuration(org.apache.hadoop.conf.Configuration) QuotaUtil(org.apache.hadoop.hbase.quotas.QuotaUtil) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) ServerName(org.apache.hadoop.hbase.ServerName) Option(org.apache.hadoop.hbase.ClusterMetrics.Option) Maps(org.apache.hbase.thirdparty.com.google.common.collect.Maps) TableName(org.apache.hadoop.hbase.TableName) Address(org.apache.hadoop.hbase.net.Address) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Sets(org.apache.hbase.thirdparty.com.google.common.collect.Sets) IOException(java.io.IOException) BalanceRequest(org.apache.hadoop.hbase.client.BalanceRequest) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) MasterObserver(org.apache.hadoop.hbase.coprocessor.MasterObserver) List(java.util.List) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) Admin(org.apache.hadoop.hbase.client.Admin) MasterCoprocessor(org.apache.hadoop.hbase.coprocessor.MasterCoprocessor) ObserverContext(org.apache.hadoop.hbase.coprocessor.ObserverContext) Optional(java.util.Optional) CoprocessorHost(org.apache.hadoop.hbase.coprocessor.CoprocessorHost) Pattern(java.util.regex.Pattern) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) AbstractTestUpdateConfiguration(org.apache.hadoop.hbase.client.AbstractTestUpdateConfiguration) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) HMaster(org.apache.hadoop.hbase.master.HMaster) TableName(org.apache.hadoop.hbase.TableName) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 33 with ClusterMetrics

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();
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) ServerName(org.apache.hadoop.hbase.ServerName) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) Test(org.junit.Test)

Example 34 with ClusterMetrics

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();
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) Test(org.junit.Test)

Example 35 with ClusterMetrics

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());
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)39 ServerName (org.apache.hadoop.hbase.ServerName)30 Test (org.junit.Test)19 ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)18 ArrayList (java.util.ArrayList)13 List (java.util.List)12 HashMap (java.util.HashMap)9 RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)8 Admin (org.apache.hadoop.hbase.client.Admin)8 IOException (java.io.IOException)7 Map (java.util.Map)7 TableName (org.apache.hadoop.hbase.TableName)7 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)7 HashSet (java.util.HashSet)6 Configuration (org.apache.hadoop.conf.Configuration)6 TreeMap (java.util.TreeMap)5 Collections (java.util.Collections)4 LinkedList (java.util.LinkedList)4 Collectors (java.util.stream.Collectors)4 Put (org.apache.hadoop.hbase.client.Put)4