Search in sources :

Example 21 with ClusterMetrics

use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.

the class TestReplicationStatusSourceStartedTargetStoppedWithRecovery method testReplicationStatusSourceStartedTargetStoppedWithRecovery.

@Test
public void testReplicationStatusSourceStartedTargetStoppedWithRecovery() throws Exception {
    UTIL2.shutdownMiniHBaseCluster();
    // 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);
    }
    Thread.sleep(10000);
    restartSourceCluster(1);
    Admin hbaseAdmin = UTIL1.getAdmin();
    ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
    Thread.sleep(10000);
    ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
    List<ReplicationLoadSource> loadSources = metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
    assertEquals(2, loadSources.size());
    boolean foundRecovery = false;
    boolean foundNormal = false;
    for (ReplicationLoadSource loadSource : loadSources) {
        if (loadSource.isRecovered()) {
            foundRecovery = true;
            assertTrue(loadSource.hasEditsSinceRestart());
            assertEquals(0, loadSource.getTimestampOfLastShippedOp());
            assertTrue(loadSource.getReplicationLag() > 0);
        } else {
            foundNormal = true;
            assertFalse(loadSource.hasEditsSinceRestart());
            assertEquals(0, loadSource.getTimestampOfLastShippedOp());
            assertEquals(0, loadSource.getReplicationLag());
        }
    }
    assertTrue("No normal queue found.", foundNormal);
    assertTrue("No recovery queue found.", foundRecovery);
}
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)

Example 22 with ClusterMetrics

use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.

the class TestReplicationStatusSourceStartedTargetStoppedNoOps method testReplicationStatusSourceStartedTargetStoppedNoOps.

@Test
public void testReplicationStatusSourceStartedTargetStoppedNoOps() throws Exception {
    UTIL2.shutdownMiniHBaseCluster();
    restartSourceCluster(1);
    Admin hbaseAdmin = UTIL1.getAdmin();
    ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
    Thread.sleep(10000);
    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);
    assertFalse(loadSource.hasEditsSinceRestart());
    assertEquals(0, loadSource.getTimestampOfLastShippedOp());
    assertEquals(0, loadSource.getReplicationLag());
    assertFalse(loadSource.isRecovered());
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 23 with ClusterMetrics

use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.

the class Action method getCurrentServers.

/**
 * Returns current region servers - active master
 */
protected ServerName[] getCurrentServers() throws IOException {
    ClusterMetrics clusterStatus = cluster.getClusterMetrics();
    Collection<ServerName> regionServers = clusterStatus.getLiveServerMetrics().keySet();
    int count = regionServers.size();
    if (count <= 0) {
        return new ServerName[] {};
    }
    ServerName master = clusterStatus.getMasterName();
    Set<ServerName> masters = new HashSet<>();
    masters.add(master);
    masters.addAll(clusterStatus.getBackupMasterNames());
    ArrayList<ServerName> tmp = new ArrayList<>(count);
    tmp.addAll(regionServers);
    tmp.removeAll(masters);
    if (skipMetaRS) {
        ServerName metaServer = cluster.getServerHoldingMeta();
        tmp.remove(metaServer);
    }
    return tmp.toArray(new ServerName[0]);
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 24 with ClusterMetrics

use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.

the class DumpClusterStatusAction method perform.

@Override
public void perform() throws Exception {
    getLogger().debug("Performing action: Dump cluster status");
    final ClusterMetrics currentMetrics = cluster.getClusterMetrics();
    getLogger().info("Cluster status\n{}", currentMetrics);
    reportMissingRegionServers(currentMetrics);
    reportNewRegionServers(currentMetrics);
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics)

Example 25 with ClusterMetrics

use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.

the class UnbalanceRegionsAction method perform.

@Override
public void perform() throws Exception {
    getLogger().info("Unbalancing regions");
    ClusterMetrics status = this.cluster.getClusterMetrics();
    List<ServerName> victimServers = new LinkedList<>(status.getLiveServerMetrics().keySet());
    int targetServerCount = (int) Math.ceil(fractionOfServers * victimServers.size());
    List<ServerName> targetServers = new ArrayList<>(targetServerCount);
    for (int i = 0; i < targetServerCount; ++i) {
        int victimIx = RandomUtils.nextInt(0, victimServers.size());
        targetServers.add(victimServers.remove(victimIx));
    }
    unbalanceRegions(status, victimServers, targetServers, fractionOfRegions);
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

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