Search in sources :

Example 11 with ScanBuilder

use of io.cdap.cdap.data2.util.hbase.ScanBuilder in project cdap by caskdata.

the class ReplicationStatusTool method getScanBuilder.

private static ScanBuilder getScanBuilder(HBaseTableUtil tableUtil, String rowType) {
    ScanBuilder scan = tableUtil.buildScan();
    // FIX: get scan based on start row and stop row
    // ReplicationStatusKey startKey = new ReplicationStatusKey(Bytes.toBytes(prefix));
    // scan.setStartRow(startKey.getKey());
    // scan.setStopRow(Bytes.stopKeyForPrefix(startKey.getKey()));
    scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(rowType));
    scan.setMaxVersions(1);
    return scan;
}
Also used : ScanBuilder(co.cask.cdap.data2.util.hbase.ScanBuilder)

Example 12 with ScanBuilder

use of io.cdap.cdap.data2.util.hbase.ScanBuilder in project cdap by caskdata.

the class HBaseMetadataTable method listTopics.

@Override
public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException {
    byte[] startRow = MessagingUtils.topicScanKey(namespaceId);
    ScanBuilder scanBuilder = tableUtil.buildScan().setStartRow(startRow).setStopRow(Bytes.stopKeyForPrefix(startRow));
    return scanTopics(scanBuilder);
}
Also used : ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder)

Example 13 with ScanBuilder

use of io.cdap.cdap.data2.util.hbase.ScanBuilder in project cdap by caskdata.

the class HBaseTable method scanPersisted.

@ReadOnly
@Override
protected Scanner scanPersisted(io.cdap.cdap.api.dataset.table.Scan scan) throws Exception {
    ScanBuilder hScan = tableUtil.buildScan();
    hScan.addFamily(columnFamily);
    // TODO (CDAP-11954): use common utility method to extract these configs
    if (scan.getProperties().containsKey(CONFIG_HBASE_CLIENT_CACHE_BLOCKS)) {
        hScan.setCacheBlocks(Boolean.valueOf(scan.getProperties().get(CONFIG_HBASE_CLIENT_CACHE_BLOCKS)));
    } else if (arguments.containsKey(CONFIG_HBASE_CLIENT_CACHE_BLOCKS)) {
        hScan.setCacheBlocks(Boolean.valueOf(arguments.get(CONFIG_HBASE_CLIENT_CACHE_BLOCKS)));
    } else if (properties.containsKey(CONFIG_HBASE_CLIENT_CACHE_BLOCKS)) {
        hScan.setCacheBlocks(Boolean.valueOf(properties.get(CONFIG_HBASE_CLIENT_CACHE_BLOCKS)));
    } else {
        // NOTE: by default we assume scanner is used in mapreduce job, hence no cache blocks
        hScan.setCacheBlocks(false);
    }
    if (scan.getProperties().containsKey(CONFIG_HBASE_CLIENT_SCANNER_CACHING)) {
        hScan.setCaching(Integer.valueOf(scan.getProperties().get(CONFIG_HBASE_CLIENT_SCANNER_CACHING)));
    } else if (arguments.containsKey(CONFIG_HBASE_CLIENT_SCANNER_CACHING)) {
        hScan.setCaching(Integer.valueOf(arguments.get(CONFIG_HBASE_CLIENT_SCANNER_CACHING)));
    } else if (properties.containsKey(CONFIG_HBASE_CLIENT_SCANNER_CACHING)) {
        hScan.setCaching(Integer.valueOf(properties.get(CONFIG_HBASE_CLIENT_SCANNER_CACHING)));
    } else {
        // NOTE: by default we use this hard-coded value, for backwards-compatibility with CDAP<4.1.2|4.2.1|4.3
        hScan.setCaching(1000);
    }
    byte[] startRow = scan.getStartRow();
    byte[] stopRow = scan.getStopRow();
    if (startRow != null) {
        hScan.setStartRow(startRow);
    }
    if (stopRow != null) {
        hScan.setStopRow(stopRow);
    }
    setFilterIfNeeded(hScan, scan.getFilter());
    hScan.setAttribute(TxConstants.TX_OPERATION_ATTRIBUTE_KEY, getEncodedTx());
    ResultScanner resultScanner = wrapResultScanner(table.getScanner(hScan.build()));
    return new HBaseScanner(resultScanner, columnFamily);
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Example 14 with ScanBuilder

use of io.cdap.cdap.data2.util.hbase.ScanBuilder in project cdap by caskdata.

the class ReplicationStatusTool method getScanBuilder.

private static ScanBuilder getScanBuilder(HBaseTableUtil tableUtil, String rowType) {
    ScanBuilder scan = tableUtil.buildScan();
    // FIX: get scan based on start row and stop row
    // ReplicationStatusKey startKey = new ReplicationStatusKey(Bytes.toBytes(prefix));
    // scan.setStartRow(startKey.getKey());
    // scan.setStopRow(Bytes.stopKeyForPrefix(startKey.getKey()));
    scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(rowType));
    scan.setMaxVersions(1);
    return scan;
}
Also used : ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder)

Example 15 with ScanBuilder

use of io.cdap.cdap.data2.util.hbase.ScanBuilder 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

ScanBuilder (co.cask.cdap.data2.util.hbase.ScanBuilder)9 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)8 ScanBuilder (io.cdap.cdap.data2.util.hbase.ScanBuilder)5 Result (org.apache.hadoop.hbase.client.Result)4 IOException (java.io.IOException)3 HTable (org.apache.hadoop.hbase.client.HTable)3 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)2 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)2 ReplicationStatusKey (co.cask.cdap.replication.ReplicationStatusKey)2 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)2 HBaseTableUtilFactory (io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory)2 ReplicationStatusKey (io.cdap.cdap.replication.ReplicationStatusKey)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 ParseException (org.apache.commons.cli.ParseException)2 Table (org.apache.hadoop.hbase.client.Table)2 ReadOnly (co.cask.cdap.api.annotation.ReadOnly)1 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1