Search in sources :

Example 6 with ScanBuilder

use of co.cask.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 7 with ScanBuilder

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

Example 8 with ScanBuilder

use of co.cask.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(co.cask.cdap.data2.util.hbase.ScanBuilder)

Example 9 with ScanBuilder

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

the class HBaseTable method scanPersisted.

@ReadOnly
@Override
protected Scanner scanPersisted(co.cask.cdap.api.dataset.table.Scan scan) throws Exception {
    ScanBuilder hScan = tableUtil.buildScan();
    hScan.addFamily(columnFamily);
    // todo: should be configurable
    // NOTE: by default we assume scanner is used in mapreduce job, hence no cache blocks
    hScan.setCacheBlocks(false);
    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, txCodec.encode(tx));
    ResultScanner resultScanner = wrapResultScanner(hTable.getScanner(hScan.build()));
    return new HBaseScanner(resultScanner, columnFamily);
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ScanBuilder(co.cask.cdap.data2.util.hbase.ScanBuilder) ReadOnly(co.cask.cdap.api.annotation.ReadOnly)

Example 10 with ScanBuilder

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

the class HBaseMetricsTable method scan.

@Override
public Scanner scan(@Nullable byte[] startRow, @Nullable byte[] stopRow, @Nullable FuzzyRowFilter filter) {
    ScanBuilder scanBuilder = tableUtil.buildScan();
    configureRangeScan(scanBuilder, startRow, stopRow, filter);
    try {
        ResultScanner resultScanner = hTable.getScanner(scanBuilder.build());
        return new HBaseScanner(resultScanner, columnFamily);
    } catch (IOException e) {
        throw new DataSetException("Scan failed on table " + tableId, e);
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) DataSetException(co.cask.cdap.api.dataset.DataSetException) ScanBuilder(co.cask.cdap.data2.util.hbase.ScanBuilder) IOException(java.io.IOException)

Aggregations

ScanBuilder (co.cask.cdap.data2.util.hbase.ScanBuilder)9 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)5 HTable (org.apache.hadoop.hbase.client.HTable)3 ImmutablePair (co.cask.cdap.common.utils.ImmutablePair)2 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 IOException (java.io.IOException)2 Result (org.apache.hadoop.hbase.client.Result)2 ReadOnly (co.cask.cdap.api.annotation.ReadOnly)1 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1 FuzzyRowFilter (co.cask.cdap.data2.dataset2.lib.table.FuzzyRowFilter)1 ConsumerConfig (co.cask.cdap.data2.queue.ConsumerConfig)1 ConsumerGroupConfig (co.cask.cdap.data2.queue.ConsumerGroupConfig)1 QueueScanner (co.cask.cdap.data2.transaction.queue.QueueScanner)1 HBaseConsumerStateStore (co.cask.cdap.data2.transaction.queue.hbase.HBaseConsumerStateStore)1 HBaseQueueAdmin (co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueAdmin)1 ShardedHBaseQueueStrategy (co.cask.cdap.data2.transaction.queue.hbase.ShardedHBaseQueueStrategy)1 TableId (co.cask.cdap.data2.util.TableId)1