Search in sources :

Example 1 with ReplicationStatusKey

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);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ReplicationStatusKey(io.cdap.cdap.replication.ReplicationStatusKey) ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) UUID(java.util.UUID) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) Result(org.apache.hadoop.hbase.client.Result)

Example 2 with ReplicationStatusKey

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;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) ReplicationStatusKey(io.cdap.cdap.replication.ReplicationStatusKey) ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)2 HBaseTableUtilFactory (io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory)2 ScanBuilder (io.cdap.cdap.data2.util.hbase.ScanBuilder)2 ReplicationStatusKey (io.cdap.cdap.replication.ReplicationStatusKey)2 Result (org.apache.hadoop.hbase.client.Result)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 Table (org.apache.hadoop.hbase.client.Table)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 ParseException (org.apache.commons.cli.ParseException)1