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);
}
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());
}
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]);
}
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);
}
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);
}
Aggregations