/** * Get all available versions. * @return this * @deprecated It is easy to misunderstand with column family's max versions, so use * {@link #readAllVersions()} instead. */ @Deprecated public Scan setMaxVersions() { return readAllVersions(); }
private int cellsCount(Table table, Filter filter) throws IOException { Scan scan = new Scan().setFilter(filter).readAllVersions(); try (ResultScanner scanner = table.getScanner(scan)) { List<Cell> results = new ArrayList<>(); Result result; while ((result = scanner.next()) != null) { result.listCells().forEach(results::add); } return results.size(); } }
throws IOException { Scan scan = new Scan().withStartRow(get.getRow()).withStopRow(get.getRow(), true).readAllVersions(); NavigableMap<byte[], NavigableMap<byte[], MutableLong>> sums = new TreeMap<>(Bytes.BYTES_COMPARATOR);
try (Table metaTable = conn.getTable(TableName.META_TABLE_NAME); ResultScanner scanner = metaTable.getScanner( new Scan().addFamily(HConstants.REPLICATION_BARRIER_FAMILY).readAllVersions())) { for (;;) { Result result = scanner.next();
private void migrateNamespaceTable() throws IOException { try (Table nsTable = masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME); ResultScanner scanner = nsTable.getScanner( new Scan().addFamily(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES).readAllVersions()); BufferedMutator mutator = masterServices.getConnection().getBufferedMutator(TableName.META_TABLE_NAME)) { for (Result result;;) { result = scanner.next(); if (result == null) { break; } Put put = new Put(result.getRow()); result .getColumnCells(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES, TableDescriptorBuilder.NAMESPACE_COL_DESC_BYTES) .forEach(c -> put.addColumn(HConstants.NAMESPACE_FAMILY, HConstants.NAMESPACE_COL_DESC_QUALIFIER, c.getTimestamp(), CellUtil.cloneValue(c))); mutator.mutate(put); } } // schedule a disable procedure instead of block waiting here, as when disabling a table we will // wait until master is initialized, but we are part of the initialization... masterServices.getMasterProcedureExecutor().submitProcedure( new DisableTableProcedure(masterServices.getMasterProcedureExecutor().getEnvironment(), TableName.NAMESPACE_TABLE_NAME, false)); }
public static ReplicationBarrierResult getReplicationBarrierResult(Connection conn, TableName tableName, byte[] row, byte[] encodedRegionName) throws IOException { byte[] metaStartKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false); byte[] metaStopKey = RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false); Scan scan = new Scan().withStartRow(metaStartKey).withStopRow(metaStopKey) .addColumn(getCatalogFamily(), getRegionStateColumn()) .addFamily(HConstants.REPLICATION_BARRIER_FAMILY).readAllVersions().setReversed(true) .setCaching(10); try (Table table = getMetaHTable(conn); ResultScanner scanner = table.getScanner(scan)) { for (Result result;;) { result = scanner.next(); if (result == null) { return new ReplicationBarrierResult(new long[0], null, Collections.emptyList()); } byte[] regionName = result.getRow(); // TODO: we may look up a region which has already been split or merged so we need to check // whether the encoded name matches. Need to find a way to quit earlier when there is no // record for the given region, for now it will scan to the end of the table. if (!Bytes.equals(encodedRegionName, Bytes.toBytes(RegionInfo.encodeRegionName(regionName)))) { continue; } return getReplicationBarrierResult(result); } } }
/** * Get all available versions. * @return this * @deprecated It is easy to misunderstand with column family's max versions, so use * {@link #readAllVersions()} instead. */ @Deprecated public Scan setMaxVersions() { return readAllVersions(); }
Scan scanSpec = new Scan().withStartRow(Bytes.toBytes(r1)); scanSpec.setTimeRange(0, 6); scanSpec.readAllVersions(); List<Cell> results = null; try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { scanSpec.readAllVersions(); try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>(); scanSpec.readAllVersions(); try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>();
@Test public void testDeleteFamily() throws IOException { KeyValue[] kvs = new KeyValue[] { create("R1", "cf", "a", 100, KeyValue.Type.DeleteFamily, "dont-care"), create("R1", "cf", "b", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "c", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "e", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "e", 11, KeyValue.Type.DeleteColumn, "dont-care"), create("R1", "cf", "f", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "g", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "g", 11, KeyValue.Type.Delete, "dont-care"), create("R1", "cf", "h", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"), create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); try (StoreScanner scan = new StoreScanner(new Scan().readAllVersions(), scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); assertEquals(true, scan.next(results)); assertEquals(0, results.size()); assertEquals(true, scan.next(results)); assertEquals(1, results.size()); assertEquals(kvs[kvs.length - 1], results.get(0)); assertEquals(false, scan.next(results)); } }
@Test public void test() throws Exception { doIncrement(0); assertSum(); // we do not hack scan operation so using scan we could get the original values added into the // table. try (ResultScanner scanner = TABLE.getScanner(new Scan().withStartRow(ROW) .withStopRow(ROW, true).addFamily(FAMILY).readAllVersions().setAllowPartialResults(true))) { Result r = scanner.next(); assertTrue(r.rawCells().length > 2); } UTIL.flush(NAME); HRegion region = UTIL.getHBaseCluster().findRegionsForTable(NAME).get(0); HStore store = region.getStore(FAMILY); for (;;) { region.compact(true); if (store.getStorefilesCount() == 1) { break; } } assertSum(); // Should only have two cells after flush and major compaction try (ResultScanner scanner = TABLE.getScanner(new Scan().withStartRow(ROW) .withStopRow(ROW, true).addFamily(FAMILY).readAllVersions().setAllowPartialResults(true))) { Result r = scanner.next(); assertEquals(2, r.rawCells().length); } } }
public static void setScanAttributes(Scan scan, Map<String, Object> statsProps) { scan.setCacheBlocks(false); scan.readAllVersions(); scan.setAttribute(ANALYZE_TABLE, TRUE_BYTES); if (statsProps != null) { Object gp_width = statsProps.get(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB); if (gp_width != null) { scan.setAttribute(BaseScannerRegionObserver.GUIDEPOST_WIDTH_BYTES, PLong.INSTANCE.toBytes(gp_width)); } Object gp_per_region = statsProps.get(QueryServices.STATS_GUIDEPOST_PER_REGION_ATTRIB); if (gp_per_region != null) { scan.setAttribute(BaseScannerRegionObserver.GUIDEPOST_PER_REGION, PInteger.INSTANCE.toBytes(gp_per_region)); } } }
scan.readAllVersions().setFilter(new ColumnValueFilter(FAMILIES[0], QUALIFIERS_FIVE[0], CompareOperator.GREATER_OR_EQUAL, VALUES[0])); KeyValue[] expectedGreaterOrEqual =
public static ReplicationBarrierResult getReplicationBarrierResult(Connection conn, TableName tableName, byte[] row, byte[] encodedRegionName) throws IOException { byte[] metaStartKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false); byte[] metaStopKey = RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false); Scan scan = new Scan().withStartRow(metaStartKey).withStopRow(metaStopKey) .addColumn(getCatalogFamily(), getRegionStateColumn()) .addFamily(HConstants.REPLICATION_BARRIER_FAMILY).readAllVersions().setReversed(true) .setCaching(10); try (Table table = getMetaHTable(conn); ResultScanner scanner = table.getScanner(scan)) { for (Result result;;) { result = scanner.next(); if (result == null) { return new ReplicationBarrierResult(new long[0], null, Collections.emptyList()); } byte[] regionName = result.getRow(); // TODO: we may look up a region which has already been split or merged so we need to check // whether the encoded name matches. Need to find a way to quit earlier when there is no // record for the given region, for now it will scan to the end of the table. if (!Bytes.equals(encodedRegionName, Bytes.toBytes(RegionInfo.encodeRegionName(regionName)))) { continue; } return getReplicationBarrierResult(result); } } }
/** * Get all available versions. * @return this * @deprecated It is easy to misunderstand with column family's max versions, so use * {@link #readAllVersions()} instead. */ @Deprecated public Scan setMaxVersions() { return readAllVersions(); }
private int cellsCount(Table table, Filter filter) throws IOException { Scan scan = new Scan().setFilter(filter).readAllVersions(); try (ResultScanner scanner = table.getScanner(scan)) { List<Cell> results = new ArrayList<>(); Result result; while ((result = scanner.next()) != null) { result.listCells().forEach(results::add); } return results.size(); } }
throws IOException { Scan scan = new Scan().withStartRow(get.getRow()).withStopRow(get.getRow(), true).readAllVersions(); NavigableMap<byte[], NavigableMap<byte[], MutableLong>> sums = new TreeMap<>(Bytes.BYTES_COMPARATOR);
Scan scanSpec = new Scan().withStartRow(Bytes.toBytes(r1)); scanSpec.setTimeRange(0, 6); scanSpec.readAllVersions(); List<Cell> results = null; try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { scanSpec.readAllVersions(); try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>(); scanSpec.readAllVersions(); try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) { results = new ArrayList<>();
@Test public void testDeleteFamily() throws IOException { KeyValue[] kvs = new KeyValue[] { create("R1", "cf", "a", 100, KeyValue.Type.DeleteFamily, "dont-care"), create("R1", "cf", "b", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "c", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "d", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "e", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "e", 11, KeyValue.Type.DeleteColumn, "dont-care"), create("R1", "cf", "f", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "g", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "g", 11, KeyValue.Type.Delete, "dont-care"), create("R1", "cf", "h", 11, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"), create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"), }; List<KeyValueScanner> scanners = scanFixture(kvs); try (StoreScanner scan = new StoreScanner(new Scan().readAllVersions(), scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); assertEquals(true, scan.next(results)); assertEquals(0, results.size()); assertEquals(true, scan.next(results)); assertEquals(1, results.size()); assertEquals(kvs[kvs.length - 1], results.get(0)); assertEquals(false, scan.next(results)); } }
@Test public void test() throws Exception { doIncrement(0); assertSum(); // we do not hack scan operation so using scan we could get the original values added into the // table. try (ResultScanner scanner = TABLE.getScanner(new Scan().withStartRow(ROW) .withStopRow(ROW, true).addFamily(FAMILY).readAllVersions().setAllowPartialResults(true))) { Result r = scanner.next(); assertTrue(r.rawCells().length > 2); } UTIL.flush(NAME); HRegion region = UTIL.getHBaseCluster().findRegionsForTable(NAME).get(0); HStore store = region.getStore(FAMILY); for (;;) { region.compact(true); if (store.getStorefilesCount() == 1) { break; } } assertSum(); // Should only have two cells after flush and major compaction try (ResultScanner scanner = TABLE.getScanner(new Scan().withStartRow(ROW) .withStopRow(ROW, true).addFamily(FAMILY).readAllVersions().setAllowPartialResults(true))) { Result r = scanner.next(); assertEquals(2, r.rawCells().length); } } }
@Test public void test() throws Exception { doIncrement(0); assertSum(); // we do not hack scan operation so using scan we could get the original values added into the // table. try (ResultScanner scanner = TABLE.getScanner(new Scan().withStartRow(ROW) .withStopRow(ROW, true).addFamily(FAMILY).readAllVersions().setAllowPartialResults(true))) { Result r = scanner.next(); assertTrue(r.rawCells().length > 2); } UTIL.flush(NAME); HRegion region = UTIL.getHBaseCluster().findRegionsForTable(NAME).get(0); HStore store = region.getStore(FAMILY); for (;;) { region.compact(true); if (store.getStorefilesCount() == 1) { break; } } assertSum(); // Should only have two cells after flush and major compaction try (ResultScanner scanner = TABLE.getScanner(new Scan().withStartRow(ROW) .withStopRow(ROW, true).addFamily(FAMILY).readAllVersions().setAllowPartialResults(true))) { Result r = scanner.next(); assertEquals(2, r.rawCells().length); } } }