Scan scan = scanBuilder.setCaching(metadataScanSize).build(); try (ResultScanner scanner = metadataTable.getScanner(scan)) { for (Result result : scanner) {
Scan scan = scanBuilder.setCaching(metadataScanSize).build(); try (ResultScanner scanner = metadataTable.getScanner(scan)) { for (Result result : scanner) {
@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); }
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 { hScan.setCaching(1000);
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 { hScan.setCaching(1000);
/** * Scans the HBase table to get a list of {@link TopicId}. */ private List<TopicId> scanTopics(ScanBuilder scanBuilder) throws IOException { Scan scan = scanBuilder.setFilter(new FirstKeyOnlyFilter()).setCaching(scanCacheRows).build(); try { List<TopicId> topicIds = new ArrayList<>(); try (ResultScanner resultScanner = hTable.getScanner(scan)) { for (Result result : resultScanner) { TopicId topicId = MessagingUtils.toTopicId(result.getRow()); byte[] value = result.getValue(columnFamily, COL); Map<String, String> properties = GSON.fromJson(Bytes.toString(value), MAP_TYPE); TopicMetadata metadata = new TopicMetadata(topicId, properties); if (metadata.exists()) { topicIds.add(topicId); } } } return topicIds; } catch (IOException e) { throw exceptionHandler.handle(e); } }
/** * Scans the HBase table to get a list of {@link TopicId}. */ private List<TopicId> scanTopics(ScanBuilder scanBuilder) throws IOException { Scan scan = scanBuilder.setFilter(new FirstKeyOnlyFilter()).setCaching(scanCacheRows).build(); try { List<TopicId> topicIds = new ArrayList<>(); try (ResultScanner resultScanner = hTable.getScanner(scan)) { for (Result result : resultScanner) { TopicId topicId = MessagingUtils.toTopicId(result.getRow()); byte[] value = result.getValue(columnFamily, COL); Map<String, String> properties = GSON.fromJson(Bytes.toString(value), MAP_TYPE); TopicMetadata metadata = new TopicMetadata(topicId, properties); if (metadata.exists()) { topicIds.add(topicId); } } } return topicIds; } catch (IOException e) { throw exceptionHandler.handle(e); } }
private ScanBuilder configureRangeScan(ScanBuilder scan, @Nullable byte[] startRow, @Nullable byte[] stopRow, @Nullable FuzzyRowFilter filter) { // todo: should be configurable scan.setCaching(1000); if (startRow != null) { scan.setStartRow(startRow); } if (stopRow != null) { scan.setStopRow(stopRow); } scan.addFamily(columnFamily); if (filter != null) { List<Pair<byte[], byte[]>> fuzzyPairs = Lists.newArrayListWithExpectedSize(filter.getFuzzyKeysData().size()); for (ImmutablePair<byte[], byte[]> pair : filter.getFuzzyKeysData()) { if (rowKeyDistributor != null) { fuzzyPairs.addAll(rowKeyDistributor.getDistributedFilterPairs(pair)); } else { // Make a copy of filter pair because the key and mask will get modified in HBase FuzzyRowFilter. fuzzyPairs.add(Pair.newPair(Arrays.copyOf(pair.getFirst(), pair.getFirst().length), Arrays.copyOf(pair.getSecond(), pair.getSecond().length))); } } scan.setFilter(new org.apache.hadoop.hbase.filter.FuzzyRowFilter(fuzzyPairs)); } return scan; }
private ScanBuilder configureRangeScan(ScanBuilder scan, @Nullable byte[] startRow, @Nullable byte[] stopRow, @Nullable FuzzyRowFilter filter) { // todo: should be configurable scan.setCaching(1000); if (startRow != null) { scan.setStartRow(startRow); } if (stopRow != null) { scan.setStopRow(stopRow); } scan.addFamily(columnFamily); if (filter != null) { List<Pair<byte[], byte[]>> fuzzyPairs = Lists.newArrayListWithExpectedSize(filter.getFuzzyKeysData().size()); for (ImmutablePair<byte[], byte[]> pair : filter.getFuzzyKeysData()) { if (rowKeyDistributor != null) { fuzzyPairs.addAll(rowKeyDistributor.getDistributedFilterPairs(pair)); } else { // Make a copy of filter pair because the key and mask will get modified in HBase FuzzyRowFilter. fuzzyPairs.add(Pair.newPair(Arrays.copyOf(pair.getFirst(), pair.getFirst().length), Arrays.copyOf(pair.getSecond(), pair.getSecond().length))); } } scan.setFilter(new org.apache.hadoop.hbase.filter.FuzzyRowFilter(fuzzyPairs)); } return scan; }
@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); } }
.setStartRow(startRow) .setStopRow(stopRow) .setCaching(scanCacheRows) .build();
.setStartRow(startRow) .setStopRow(stopRow) .setCaching(scanCacheRows) .build();
.setMaxVersions(1) .addColumn(QueueEntryRow.COLUMN_FAMILY, stateColumnName) .setCaching(MAX_SCAN_ROWS) .build();
.setStartRow(startRow) .setStopRow(stopRow) .setCaching(scanCacheRows) .build();
.setStartRow(startRow) .setStopRow(stopRow) .setCaching(scanCacheRows) .build();
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); }