/** * Sets the attribute of caching blocks in the scan. * * @param scan * The current scan. * @param cacheBlocks * True, set the attribute of caching blocks into the scan, the scanner with this scan * caches blocks. * False, the scanner doesn't cache blocks for this scan. */ public static void setCacheMobBlocks(Scan scan, boolean cacheBlocks) { scan.setAttribute(MobConstants.MOB_CACHE_BLOCKS, Bytes.toBytes(cacheBlocks)); }
/** * Enable/disable "raw" mode for this scan. * If "raw" is enabled the scan will return all * delete marker and deleted rows that have not * been collected, yet. * This is mostly useful for Scan on column families * that have KEEP_DELETED_ROWS enabled. * It is an error to specify any column when "raw" is set. * @param raw True/False to enable/disable "raw" mode. */ public Scan setRaw(boolean raw) { setAttribute(RAW_ATTR, Bytes.toBytes(raw)); return this; }
/** * Enable collection of {@link ScanMetrics}. For advanced users. * @param enabled Set to true to enable accumulating scan metrics */ public Scan setScanMetricsEnabled(final boolean enabled) { setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.valueOf(enabled))); return this; }
/** * Publish the scan metrics. For now, we use scan.setAttribute to pass the metrics back to the * application or TableInputFormat.Later, we could push it to other systems. We don't use metrics * framework because it doesn't support multi-instances of the same metrics on the same machine; * for scan/map reduce scenarios, we will have multiple scans running at the same time. By * default, scan metrics are disabled; if the application wants to collect them, this behavior can * be turned on by calling calling {@link Scan#setScanMetricsEnabled(boolean)} */ protected void writeScanMetrics() { if (this.scanMetrics == null || scanMetricsPublished) { return; } // Publish ScanMetrics to the Scan Object. // As we have claimed in the comment of Scan.getScanMetrics, this relies on that user will not // call ResultScanner.getScanMetrics and reset the ScanMetrics. Otherwise the metrics published // to Scan will be messed up. scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA, ProtobufUtil.toScanMetrics(scanMetrics, false).toByteArray()); scanMetricsPublished = true; }
/** * Gets the number of rows in the given table. * @param table to get the scanner * @return the number of rows */ public static int countMobRows(final Table table) throws IOException { Scan scan = new Scan(); // Do not retrieve the mob data when scanning scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); return HBaseTestingUtility.countRows(table, scan); } }
/** * Set the scan attribute * * @param reversed if true, scan will be backward order * @param mobScanRaw if true, scan will get the mob reference * @return this */ public void setScan(Scan scan, boolean reversed, boolean mobScanRaw) { scan.setReversed(reversed); scan.setMaxVersions(4); if(mobScanRaw) { scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); } }
@Test public void testAttributesSerialization() throws IOException { Scan scan = new Scan(); scan.setAttribute("attribute1", Bytes.toBytes("value1")); scan.setAttribute("attribute2", Bytes.toBytes("value2")); scan.setAttribute("attribute3", Bytes.toBytes("value3")); ClientProtos.Scan scanProto = ProtobufUtil.toScan(scan); Scan scan2 = ProtobufUtil.toScan(scanProto); Assert.assertNull(scan2.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan2.getAttribute("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan2.getAttribute("attribute2"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value3"), scan2.getAttribute("attribute3"))); Assert.assertEquals(3, scan2.getAttributesMap().size()); }
/** * Gets the number of cells in the given table. * @param table to get the scanner * @return the number of cells */ private int countMobCells(final Table table) throws IOException { Scan scan = new Scan(); // Do not retrieve the mob data when scanning scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); ResultScanner results = table.getScanner(scan); int count = 0; for (Result res : results) { count += res.size(); } results.close(); return count; }
scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName));
private int countMobRows() throws IOException { Scan scan = new Scan(); // Do not retrieve the mob data when scanning scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); InternalScanner scanner = region.getScanner(scan); int scannedCount = 0; List<Cell> results = new ArrayList<>(); boolean hasMore = true; while (hasMore) { hasMore = scanner.next(results); for (Cell c : results) { if (MobUtils.isMobReferenceCell(c)) { scannedCount++; } } results.clear(); } scanner.close(); return scannedCount; }
Scan scan = new Scan(); String tableName = this.name.getMethodName() + i; scan.setAttribute(SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName)); scans.add(scan);
scan.addFamily(Bytes.toBytes(familyName)); scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); ResultScanner results = table.getScanner(scan); Path mobFamilyPath = MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(),
public static Scan buildScan(RawScan rawScan) { Scan scan = new Scan(); scan.setCaching(rawScan.hbaseCaching); scan.setMaxResultSize(rawScan.hbaseMaxResultSize); scan.setCacheBlocks(true); scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE)); if (rawScan.startKey != null) { scan.setStartRow(rawScan.startKey); } if (rawScan.endKey != null) { scan.setStopRow(rawScan.endKey); } if (rawScan.fuzzyKeys != null) { applyFuzzyFilter(scan, rawScan.fuzzyKeys); } if (rawScan.hbaseColumns != null) { applyHBaseColums(scan, rawScan.hbaseColumns); } return scan; }
this.loadColumnFamiliesOnDemand = get.getLoadColumnFamiliesOnDemandValue(); for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) { setAttribute(attr.getKey(), attr.getValue());
private int countReferencedMobFiles() throws IOException { Scan scan = new Scan(); scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); InternalScanner scanner = region.getScanner(scan);
scan.setAttribute("absent", null); Assert.assertTrue(scan.getAttributesMap().isEmpty()); Assert.assertNull(scan.getAttribute("absent")); scan.setAttribute("attribute1", Bytes.toBytes("value1")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan.getAttribute("attribute1"))); Assert.assertEquals(1, scan.getAttributesMap().size()); scan.setAttribute("attribute1", Bytes.toBytes("value12")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), scan.getAttribute("attribute1"))); Assert.assertEquals(1, scan.getAttributesMap().size()); scan.setAttribute("attribute2", Bytes.toBytes("value2")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan.getAttribute("attribute2"))); Assert.assertEquals(2, scan.getAttributesMap().size()); scan.setAttribute("attribute2", null); Assert.assertNull(scan.getAttribute("attribute2")); Assert.assertEquals(1, scan.getAttributesMap().size()); scan.setAttribute("attribute2", null); Assert.assertNull(scan.getAttribute("attribute2")); Assert.assertEquals(1, scan.getAttributesMap().size()); scan.setAttribute("attribute1", null); Assert.assertNull(scan.getAttribute("attribute1")); Assert.assertTrue(scan.getAttributesMap().isEmpty());
private String assertHasOneMobRow(Table table, TableName tn, String familyName) throws IOException { Scan scan = new Scan(); scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); ResultScanner rs = table.getScanner(scan); Result r = rs.next(); Assert.assertNotNull(r); String fileName = MobUtils.getMobFileName(r.getColumnLatestCell(FAMILY, QF)); Path filePath = new Path( MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName), fileName); FileSystem fs = TEST_UTIL.getTestFileSystem(); Assert.assertTrue(fs.exists(filePath)); r = rs.next(); Assert.assertNull(r); return fileName; } }
private void result(byte[] fam, byte[] row, byte[] qual, byte[] row2, Table table, byte[] value, byte[] value2, byte[] row1, byte[] value1) throws IOException { Scan s = new Scan(row); // If filters are used this attribute can be specifically check for in // filterKV method and // kvs can be filtered out if the tags of interest is not found in that kv s.setAttribute("visibility", Bytes.toBytes("myTag")); ResultScanner scanner = null; try { scanner = table.getScanner(s); Result next = scanner.next(); assertTrue(Bytes.equals(next.getRow(), row)); assertTrue(Bytes.equals(next.getValue(fam, qual), value)); Result next2 = scanner.next(); assertTrue(next2 != null); assertTrue(Bytes.equals(next2.getRow(), row1)); assertTrue(Bytes.equals(next2.getValue(fam, qual), value1)); next2 = scanner.next(); assertTrue(next2 != null); assertTrue(Bytes.equals(next2.getRow(), row2)); assertTrue(Bytes.equals(next2.getValue(fam, qual), value2)); } finally { if (scanner != null) scanner.close(); } }
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); InternalScanner scanner = (InternalScanner) store.getScanner(scan, scan.getFamilyMap().get(store.getColumnFamilyDescriptor().getName()),
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); InternalScanner scanner = (InternalScanner) store.getScanner(scan, scan.getFamilyMap().get(store.getColumnFamilyDescriptor().getName()),