private void testSmallReversedScanInternal(String[] inputRowKeys) throws IOException { int rowCount = inputRowKeys.length; for (int i = 0; i < rowCount; i++) { Put put = new Put(Bytes.toBytes(inputRowKeys[i])); put.addColumn(COLUMN_FAMILY, null, Bytes.toBytes(i)); htable.put(put); } Scan scan = new Scan(); scan.setReversed(true); scan.setSmall(true); ResultScanner scanner = htable.getScanner(scan); Result r; int value = rowCount; while ((r = scanner.next()) != null) { Assert.assertArrayEquals(r.getValue(COLUMN_FAMILY, null), Bytes.toBytes(--value)); Assert.assertArrayEquals(r.getRow(), Bytes.toBytes(inputRowKeys[value])); } Assert.assertEquals(0, value); }
private Result getReverseScanResult(Table table, byte[] row, byte[] fam) throws IOException { Scan scan = new Scan(row); scan.setSmall(true); scan.setReversed(true); scan.setCaching(1); scan.addFamily(fam); try (ResultScanner scanner = table.getScanner(scan)) { return scanner.next(); } }
/** * Run through a variety of test configurations with a small scan * @param table * @param reversed * @param rows * @param columns * @throws Exception */ private void testSmallScan(Table table, boolean reversed, int rows, int columns) throws Exception { Scan baseScan = new Scan(); baseScan.setReversed(reversed); baseScan.setSmall(true); Scan scan = new Scan(baseScan); verifyExpectedCounts(table, scan, rows, columns); scan = new Scan(baseScan); scan.setMaxResultSize(1); verifyExpectedCounts(table, scan, rows, columns); scan = new Scan(baseScan); scan.setMaxResultSize(1); scan.setCaching(Integer.MAX_VALUE); verifyExpectedCounts(table, scan, rows, columns); }
public Result getClosestRowBefore(Region r, byte[] row, byte[] family) throws IOException { Scan scan = new Scan(row); scan.setSmall(true); scan.setCaching(1); scan.setReversed(true); scan.addFamily(family); try (RegionScanner scanner = r.getScanner(scan)) { List<Cell> cells = new ArrayList<>(1); scanner.next(cells); if (r.getRegionInfo().isMetaRegion() && !isTargetTable(row, cells.get(0))) { return null; } return Result.create(cells); } }
/** * Corner case: * HBase has 4 regions, (-oo,b),[b,c),[c,d),[d,+oo), and only rowKey with byte[]={0x00} locate in region (-oo,b) . * test whether reversed small scanner will return infinity results with RowKey={0x00}. * @throws IOException */ @Test public void testSmallReversedScan02() throws IOException { Put put = new Put(new byte[] { (char) 0x00 }); put.addColumn(COLUMN_FAMILY, null, Bytes.toBytes(0)); htable.put(put); Scan scan = new Scan(); scan.setCaching(1); scan.setReversed(true); scan.setSmall(true); ResultScanner scanner = htable.getScanner(scan); Result r; int count = 1; while ((r = scanner.next()) != null) { Assert.assertArrayEquals(r.getValue(COLUMN_FAMILY, null), Bytes.toBytes(0)); Assert.assertArrayEquals(r.getRow(), new byte[] { (char) 0x00 }); Assert.assertTrue(--count >= 0); } Assert.assertEquals(0, count); } }
scan.setMaxResultSize(maxResultSize); scan.setReversed(reversed); scan.setSmall(small); scan.setConsistency(consistency); ResultScanner scanner = table.getScanner(scan);
/** * Basic client side validation of HBASE-13262 */ @Test public void testSmallScannerSeesAllRecords() throws Exception { Connection conn = TEST_UTIL.getConnection(); try (Table table = conn.getTable(TABLENAME)) { Scan s = new Scan(); s.setSmall(true); s.addFamily(FAMILY); s.setMaxResultSize(-1); s.setBatch(-1); s.setCaching(500); Entry<Long,Long> entry = sumTable(table.getScanner(s)); long rowsObserved = entry.getKey(); long entriesObserved = entry.getValue(); // Verify that we see 1M rows and 9M cells assertEquals(NUM_ROWS, rowsObserved); assertEquals(NUM_ROWS * NUM_COLS, entriesObserved); } }
scan.setSmall(true); scan.setCaching(2); scanner = table.getScanner(scan);
scan.setSmall(small); scan.setReversed(true); scan.setStartRow(Bytes.toBytes("002")); scan.setSmall(small); scan.setReversed(true); scan.setStartRow(Bytes.toBytes("002")); scan.setSmall(small); scan.setReversed(true); scan.setStartRow(Bytes.toBytes("001")); scan.setSmall(small); scan.setReversed(true); scan.setStartRow(Bytes.toBytes("000")); scan.setSmall(small); scan.setReversed(true); scan.setStartRow(Bytes.toBytes("006"));
@Test public void testScanSizeForSmallScan() throws Exception { doNPuts(100, true); Scan s = new Scan(); s.setSmall(true); s.setCaching(1); ResultScanner resultScanners = table.getScanner(s); for (int nextCount = 0; nextCount < NUM_SCAN_NEXT; nextCount++) { Result result = resultScanners.next(); assertNotNull(result); if (TABLES_ON_MASTER) { assertEquals(1, result.size()); } } numScanNext += NUM_SCAN_NEXT; assertRegionMetrics("scanCount", NUM_SCAN_NEXT); if (TABLES_ON_MASTER) { assertCounter("ScanSize_num_ops", numScanNext); } }
scan2.setScanMetricsEnabled(true); scan2.setCaching(1); scan2.setSmall(true); scanner = ht.getScanner(scan2); numBytes = 0;
scan.setSmall(proto.getSmall());
public static Scan newScan(Scan scan) { try { Scan newScan = new Scan(scan); // Clone the underlying family map instead of sharing it between // the existing and cloned Scan (which is the retarded default // behavior). TreeMap<byte [], NavigableSet<byte []>> existingMap = (TreeMap<byte[], NavigableSet<byte[]>>)scan.getFamilyMap(); Map<byte [], NavigableSet<byte []>> clonedMap = new TreeMap<byte [], NavigableSet<byte []>>(existingMap); newScan.setFamilyMap(clonedMap); // Carry over the reversed attribute newScan.setReversed(scan.isReversed()); newScan.setSmall(scan.isSmall()); return newScan; } catch (IOException e) { throw new RuntimeException(e); } } /**
private static void scan(int caching, int batch, boolean small) throws IOException { int count = 0; Scan scan = new Scan() .setCaching(caching) // co ScanCacheBatchExample-1-Set Set caching and batch parameters. .setBatch(batch) .setSmall(small) .setScanMetricsEnabled(true); ResultScanner scanner = table.getScanner(scan); for (Result result : scanner) { count++; // co ScanCacheBatchExample-2-Count Count the number of Results available. } scanner.close(); ScanMetrics metrics = scan.getScanMetrics(); System.out.println("Caching: " + caching + ", Batch: " + batch + ", Small: " + small + ", Results: " + count + ", RPCs: " + metrics.countOfRPCcalls); }
.setRowPrefixFilter(Bytes.toBytes("row_")) .setScanMetricsEnabled(true) .setSmall(true) .setReadType(ReadType.STREAM) .withStartRow(Bytes.toBytes("row_1"))
scan.setSmall(proto.getSmall());
scan.setSmall(proto.getSmall());
.setRowPrefixFilter(Bytes.toBytes("row_")) .setScanMetricsEnabled(true) .setSmall(true) .setReadType(ReadType.STREAM) .withStartRow(Bytes.toBytes("row_1"))
scan.setSmall(proto.getSmall());