use of co.cask.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();
HTable hTable = tableUtil.createHTable(hConf, getReplicationStateTableId(tableUtil));
// Scan the table to scan for all regions.
ScanBuilder scan = getScanBuilder(tableUtil, rowType);
Result result;
HashMap<String, Long> timeMap = new HashMap<>();
try (ResultScanner resultScanner = hTable.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);
} finally {
hTable.close();
}
return timeMap;
}
use of co.cask.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();
HTable hTable = tableUtil.createHTable(hConf, getReplicationStateTableId(tableUtil));
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));
Result result;
try (ResultScanner resultScanner = hTable.getScanner(scan.build())) {
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);
}
} finally {
hTable.close();
}
}
Aggregations