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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations