use of io.cdap.cdap.replication.ReplicationStatusKey in project cdap by caskdata.
the class ReplicationStatusTool method dumpReplicationStateTable.
private static void dumpReplicationStateTable() throws Exception {
System.out.println("\nThis is all the HBase regions on the Cluster:");
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
ScanBuilder scan = tableUtil.buildScan();
scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.WRITE_TIME_ROW_TYPE));
scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.REPLICATE_TIME_ROW_TYPE));
try (Table table = tableUtil.createTable(hConf, getReplicationStateTableId(tableUtil));
ResultScanner resultScanner = table.getScanner(scan.build())) {
Result result;
while ((result = resultScanner.next()) != null) {
ReplicationStatusKey key = new ReplicationStatusKey(result.getRow());
String rowType = key.getRowType();
String region = key.getRegionName();
UUID rsID = key.getRsID();
Long writeTime = getTimeFromResult(result, ReplicationConstants.ReplicationStatusTool.WRITE_TIME_ROW_TYPE);
Long replicateTime = getTimeFromResult(result, ReplicationConstants.ReplicationStatusTool.REPLICATE_TIME_ROW_TYPE);
System.out.println("Key=>rowType:" + rowType + ":region:" + region + ":RSID:" + rsID + " writeTime:" + writeTime + ":replicateTime:" + replicateTime);
}
}
}
use of io.cdap.cdap.replication.ReplicationStatusKey in project cdap by caskdata.
the class ReplicationStatusTool method getMapFromTable.
private static Map<String, Long> getMapFromTable(String rowType) throws IOException {
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
// Scan the table to scan for all regions.
ScanBuilder scan = getScanBuilder(tableUtil, rowType);
Result result;
HashMap<String, Long> timeMap = new HashMap<>();
try (Table table = tableUtil.createTable(hConf, getReplicationStateTableId(tableUtil));
ResultScanner resultScanner = table.getScanner(scan.build())) {
while ((result = resultScanner.next()) != null) {
ReplicationStatusKey key = new ReplicationStatusKey(result.getRow());
String region = key.getRegionName();
Long timestamp = getTimeFromResult(result, rowType);
if (timeMap.get(region) == null || timestamp > timeMap.get(region)) {
timeMap.put(region, timestamp);
}
}
} catch (Exception e) {
LOG.error("Error while reading table.", e);
throw Throwables.propagate(e);
}
return timeMap;
}
Aggregations