@Override public List<TopicId> listTopics() throws IOException { return scanTopics(tableUtil.buildScan()); }
@Override public List<TopicId> listTopics() throws IOException { return scanTopics(tableUtil.buildScan()); }
@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 = getScanner(scanBuilder); return new HBaseScanner(resultScanner, columnFamily, rowKeyDistributor); } catch (IOException e) { throw new DataSetException("Scan failed on table " + tableId, e); } }
@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 = getScanner(scanBuilder); return new HBaseScanner(resultScanner, columnFamily, rowKeyDistributor); } catch (IOException e) { throw new DataSetException("Scan failed on table " + tableId, e); } }
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; }
@Override public QueueScanner createScanner(ConsumerConfig consumerConfig, HTable hTable, Scan scan, int numRows) throws IOException { // we should roughly divide by number of buckets, but don't want another RPC for the case we are not exactly right ScanBuilder distributedScan = tableUtil.buildScan(scan); int caching = (int) (1.1 * numRows / distributorBuckets); distributedScan.setCaching(caching); ResultScanner scanner = DistributedScanner.create(hTable, distributedScan.build(), rowKeyDistributor, scansExecutor); return new HBaseQueueScanner(scanner, numRows, rowKeyConverter); }
@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); }
@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); }
@ReadOnly @Override protected Scanner scanPersisted(co.cask.cdap.api.dataset.table.Scan scan) throws Exception { ScanBuilder hScan = tableUtil.buildScan(); hScan.addFamily(columnFamily);
@ReadOnly @Override protected Scanner scanPersisted(co.cask.cdap.api.dataset.table.Scan scan) throws Exception { ScanBuilder hScan = tableUtil.buildScan(); hScan.addFamily(columnFamily);
@Override public void rollback(byte[] startKey, byte[] stopKey, byte[] txWritePtr) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startKey) .setStopRow(stopKey) .setCaching(scanCacheRows) .build(); List<Put> batchPuts = new ArrayList<>(); try (ResultScanner scanner = DistributedScanner.create(hTable, scan, rowKeyDistributor, scanExecutor)) { for (Result result : scanner) { // No need to turn the key back to the original row key because we want to put with the actual row key PutBuilder putBuilder = tableUtil.buildPut(result.getRow()); putBuilder.add(columnFamily, TX_COL, txWritePtr); batchPuts.add(putBuilder.build()); } } try { if (!batchPuts.isEmpty()) { hTable.put(batchPuts); if (!hTable.isAutoFlush()) { hTable.flushCommits(); } } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override public void rollback(byte[] startKey, byte[] stopKey, byte[] txWritePtr) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startKey) .setStopRow(stopKey) .setCaching(scanCacheRows) .build(); List<Put> batchPuts = new ArrayList<>(); try (ResultScanner scanner = DistributedScanner.create(hTable, scan, rowKeyDistributor, scanExecutor)) { for (Result result : scanner) { // No need to turn the key back to the original row key because we want to put with the actual row key PutBuilder putBuilder = tableUtil.buildPut(result.getRow()); putBuilder.add(columnFamily, TX_COL, txWritePtr); batchPuts.add(putBuilder.build()); } } try { if (!batchPuts.isEmpty()) { hTable.put(batchPuts); if (!hTable.isAutoFlush()) { hTable.flushCommits(); } } } catch (IOException e) { throw exceptionHandler.handle(e); } }
@Override public CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startRow) .setStopRow(stopRow)
@Override public CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startRow) .setStopRow(stopRow)
@Override protected StateScanner scanStates(byte[] startRow, byte[] stopRow) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startRow) .setStopRow(stopRow)
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(); } }
@Override protected CloseableIterator<RawMessageTableEntry> read(byte[] startRow, byte[] stopRow) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startRow) .setStopRow(stopRow)
@Override protected CloseableIterator<RawMessageTableEntry> read(byte[] startRow, byte[] stopRow) throws IOException { Scan scan = tableUtil.buildScan() .setStartRow(startRow) .setStopRow(stopRow)
private ResultScanner createHBaseScanner(ConsumerConfig consumerConfig, HTable hTable, Scan scan, int numRows) throws IOException { // Modify the scan with sharded key prefix ScanBuilder shardedScan = tableUtil.buildScan(scan); // we should roughly divide by number of buckets, but don't want another RPC for the case we are not exactly right int caching = (int) (1.1 * numRows / distributorBuckets); shardedScan.setCaching(caching); if (scan.getStartRow().length > 0) { byte[] rowKey = getShardedKey(consumerConfig, consumerConfig.getInstanceId(), scan.getStartRow()); shardedScan.setStartRow(rowKey); } if (scan.getStopRow().length > 0) { byte[] rowKey = getShardedKey(consumerConfig, consumerConfig.getInstanceId(), scan.getStopRow()); shardedScan.setStopRow(rowKey); } return DistributedScanner.create(hTable, shardedScan.build(), rowKeyDistributor, scansExecutor); }