use of org.apache.hadoop.hbase.replication.ReplicationLoadSource in project hbase by apache.
the class HMaster method getReplicationLoad.
public HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> getReplicationLoad(ServerName[] serverNames) {
List<ReplicationPeerDescription> peerList = this.getReplicationPeerManager().listPeers(null);
if (peerList == null) {
return null;
}
HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> replicationLoadSourceMap = new HashMap<>(peerList.size());
peerList.stream().forEach(peer -> replicationLoadSourceMap.put(peer.getPeerId(), new ArrayList<>()));
for (ServerName serverName : serverNames) {
List<ReplicationLoadSource> replicationLoadSources = getServerManager().getLoad(serverName).getReplicationLoadSourceList();
for (ReplicationLoadSource replicationLoadSource : replicationLoadSources) {
List<Pair<ServerName, ReplicationLoadSource>> replicationLoadSourceList = replicationLoadSourceMap.get(replicationLoadSource.getPeerID());
if (replicationLoadSourceList == null) {
LOG.debug("{} does not exist, but it exists " + "in znode(/hbase/replication/rs). when the rs restarts, peerId is deleted, so " + "we just need to ignore it", replicationLoadSource.getPeerID());
continue;
}
replicationLoadSourceList.add(new Pair<>(serverName, replicationLoadSource));
}
}
for (List<Pair<ServerName, ReplicationLoadSource>> loads : replicationLoadSourceMap.values()) {
if (loads.size() > 0) {
loads.sort(Comparator.comparingLong(load -> (-1) * load.getSecond().getReplicationLag()));
}
}
return replicationLoadSourceMap;
}
use of org.apache.hadoop.hbase.replication.ReplicationLoadSource in project hbase by apache.
the class TestRegionsRecoveryChore method getServerMetrics.
private static ServerMetrics getServerMetrics(int noOfRegions) {
ServerMetrics serverMetrics = new ServerMetrics() {
@Override
public ServerName getServerName() {
return null;
}
@Override
public long getRequestCountPerSecond() {
return 0;
}
@Override
public long getRequestCount() {
return 0;
}
@Override
public long getReadRequestsCount() {
return 0;
}
@Override
public long getWriteRequestsCount() {
return 0;
}
@Override
public Size getUsedHeapSize() {
return null;
}
@Override
public Size getMaxHeapSize() {
return null;
}
@Override
public int getInfoServerPort() {
return 0;
}
@Override
public List<ReplicationLoadSource> getReplicationLoadSourceList() {
return null;
}
@Override
public Map<String, List<ReplicationLoadSource>> getReplicationLoadSourceMap() {
return null;
}
@Nullable
@Override
public ReplicationLoadSink getReplicationLoadSink() {
return null;
}
@Override
public Map<byte[], RegionMetrics> getRegionMetrics() {
Map<byte[], RegionMetrics> regionMetricsMap = new HashMap<>();
for (int i = 0; i < noOfRegions; i++) {
byte[] regionName = Bytes.toBytes("region" + regionNo + "_" + i);
regionMetricsMap.put(regionName, TestRegionsRecoveryChore.getRegionMetrics(regionName, 100 * i));
++regionNo;
}
return regionMetricsMap;
}
@Override
public Map<byte[], UserMetrics> getUserMetrics() {
return new HashMap<>();
}
@Override
public Set<String> getCoprocessorNames() {
return null;
}
@Override
public long getReportTimestamp() {
return 0;
}
@Override
public long getLastReportTimestamp() {
return 0;
}
@Override
public List<ServerTask> getTasks() {
return null;
}
};
return serverMetrics;
}
use of org.apache.hadoop.hbase.replication.ReplicationLoadSource in project hbase by apache.
the class TestGetReplicationLoad method testGetReplicationMetrics.
@Test
public void testGetReplicationMetrics() throws Exception {
String peer1 = "test1", peer2 = "test2", queueId = "1";
long ageOfLastShippedOp = 2, replicationLag = 3, timeStampOfLastShippedOp = 4, timeStampOfNextToReplicate = 5, editsRead = 6, oPsShipped = 7;
int sizeOfLogQueue = 8;
boolean recovered = false, running = false, editsSinceRestart = false;
RegionServerStatusProtos.RegionServerReportRequest.Builder request = RegionServerStatusProtos.RegionServerReportRequest.newBuilder();
ServerName serverName = cluster.getMaster(0).getServerName();
request.setServer(ProtobufUtil.toServerName(serverName));
ClusterStatusProtos.ReplicationLoadSource rload1 = ClusterStatusProtos.ReplicationLoadSource.newBuilder().setPeerID(peer1).setAgeOfLastShippedOp(ageOfLastShippedOp).setReplicationLag(replicationLag).setTimeStampOfLastShippedOp(timeStampOfLastShippedOp).setSizeOfLogQueue(sizeOfLogQueue).setTimeStampOfNextToReplicate(timeStampOfNextToReplicate).setQueueId(queueId).setEditsRead(editsRead).setOPsShipped(oPsShipped).setRunning(running).setRecovered(recovered).setEditsSinceRestart(editsSinceRestart).build();
ClusterStatusProtos.ReplicationLoadSource rload2 = ClusterStatusProtos.ReplicationLoadSource.newBuilder().setPeerID(peer2).setAgeOfLastShippedOp(ageOfLastShippedOp + 1).setReplicationLag(replicationLag + 1).setTimeStampOfLastShippedOp(timeStampOfLastShippedOp + 1).setSizeOfLogQueue(sizeOfLogQueue + 1).setTimeStampOfNextToReplicate(timeStampOfNextToReplicate + 1).setQueueId(queueId).setEditsRead(editsRead + 1).setOPsShipped(oPsShipped + 1).setRunning(running).setRecovered(recovered).setEditsSinceRestart(editsSinceRestart).build();
ClusterStatusProtos.ServerLoad sl = ClusterStatusProtos.ServerLoad.newBuilder().addReplLoadSource(rload1).addReplLoadSource(rload2).build();
request.setLoad(sl);
master.getReplicationPeerManager().addPeer(peer1, ReplicationPeerConfig.newBuilder().setClusterKey("test").build(), true);
master.getReplicationPeerManager().addPeer(peer2, ReplicationPeerConfig.newBuilder().setClusterKey("test").build(), true);
master.getMasterRpcServices().regionServerReport(null, request.build());
HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> replicationLoad = master.getReplicationLoad(new ServerName[] { serverName });
assertEquals("peer size ", 2, replicationLoad.size());
assertEquals("load size ", 1, replicationLoad.get(peer1).size());
assertEquals("log queue size of peer1", sizeOfLogQueue, replicationLoad.get(peer1).get(0).getSecond().getSizeOfLogQueue());
assertEquals("replication lag of peer2", replicationLag + 1, replicationLoad.get(peer2).get(0).getSecond().getReplicationLag());
master.stopMaster();
}
Aggregations