Refine search
/** * Fetches any persisted HBase snapshot sizes stored in the quota table. The sizes here are * computed relative to the table which the snapshot was created from. A snapshot's size will * not include the size of files which the table still refers. These sizes, in bytes, are what * is used internally to compute quota violation for tables and namespaces. * * @return A map of snapshot name to size in bytes per space quota computations */ public static Map<String,Long> getObservedSnapshotSizes(Connection conn) throws IOException { try (Table quotaTable = conn.getTable(QUOTA_TABLE_NAME); ResultScanner rs = quotaTable.getScanner(createScanForSpaceSnapshotSizes())) { final Map<String,Long> snapshotSizes = new HashMap<>(); for (Result r : rs) { CellScanner cs = r.cellScanner(); while (cs.advance()) { Cell c = cs.current(); final String snapshot = extractSnapshotNameFromSizeCell(c); final long size = parseSnapshotSize(c); snapshotSizes.put(snapshot, size); } } return snapshotSizes; } }
private static void assertShadowCells(Connection conn, String fullTableName, String fullIndexName, boolean exists) throws Exception { PTable ptable = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, fullTableName)); int nTableKVColumns = ptable.getColumns().size() - ptable.getPKColumns().size(); Table hTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(fullTableName)); ResultScanner tableScanner = hTable.getScanner(new Scan()); Result tableResult; PTable pindex = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, fullIndexName)); int nIndexKVColumns = pindex.getColumns().size() - pindex.getPKColumns().size(); Table hIndex = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(fullIndexName)); ResultScanner indexScanner = hIndex.getScanner(new Scan()); Result indexResult; while ((indexResult = indexScanner.next()) != null) { int nColumns = 0; CellScanner scanner = indexResult.cellScanner(); while (scanner.advance()) { nColumns++; } assertEquals(exists, nColumns > nIndexKVColumns * 2); assertNotNull(tableResult = tableScanner.next()); nColumns = 0; scanner = tableResult.cellScanner(); while (scanner.advance()) { nColumns++; } assertEquals(exists, nColumns > nTableKVColumns * 2); } assertNull(tableScanner.next()); }
@Override public boolean postScannerNext(ObserverContext<RegionCoprocessorEnvironment> e, InternalScanner s, List<Result> results, int limit, boolean hasMore) throws IOException { if (checkTagPresence) { if (results.size() > 0) { // Check tag presence in the 1st cell in 1st Result Result result = results.get(0); CellScanner cellScanner = result.cellScanner(); if (cellScanner.advance()) { Cell cell = cellScanner.current(); tags = PrivateCellUtil.getTags(cell); } } } return hasMore; } }
CellScanner cs = result.cellScanner(); while (cs.advance()) { Cell current = cs.current(); try { long snapshotSize = QuotaTableUtil.parseSnapshotSize(current);
void updateValueSize(final Result r) throws IOException { if (r == null || !isRandomValueSize()) return; int size = 0; for (CellScanner scanner = r.cellScanner(); scanner.advance();) { size += scanner.current().getValueLength(); } updateValueSize(size); }
@Test public void testResultIteration() throws IOException { Cell [] cells = new Cell[COUNT]; for(int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); cells[i] = new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes); } Result r = Result.create(Arrays.asList(cells)); int index = 0; for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes)); } assertEquals(COUNT, index); } }
private static void verifyRow(Result result) throws IOException { byte[] row = result.getRow(); CellScanner scanner = result.cellScanner(); while (scanner.advance()) { Cell cell = scanner.current(); //assert that all Cells in the Result have the same key Assert.assertEquals(0, Bytes.compareTo(row, 0, row.length, cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); } for (int j = 0; j < FAMILIES.length; j++) { byte[] actual = result.getValue(FAMILIES[j], FAMILIES[j]); Assert.assertArrayEquals("Row in snapshot does not match, expected:" + Bytes.toString(row) + " ,actual:" + Bytes.toString(actual), row, actual); } }
private void verifyRecordPresentInQuotaTable(ThrottleType type, long limit, TimeUnit tu) throws Exception { // Verify the RPC Quotas in the table try (Table quotaTable = TEST_UTIL.getConnection().getTable(QuotaTableUtil.QUOTA_TABLE_NAME); ResultScanner scanner = quotaTable.getScanner(new Scan())) { Result r = Iterables.getOnlyElement(scanner); CellScanner cells = r.cellScanner(); assertTrue("Expected to find a cell", cells.advance()); assertRPCQuota(type, limit, tu, cells.current()); } }
protected static void verifyRowFromMap(ImmutableBytesWritable key, Result result) throws IOException { byte[] row = key.get(); CellScanner scanner = result.cellScanner(); while (scanner.advance()) { Cell cell = scanner.current(); //assert that all Cells in the Result have the same key Assert.assertEquals(0, Bytes.compareTo(row, 0, row.length, cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); } for (int j = 0; j < FAMILIES.length; j++) { byte[] actual = result.getValue(FAMILIES[j], FAMILIES[j]); Assert.assertArrayEquals("Row in snapshot does not match, expected:" + Bytes.toString(row) + " ,actual:" + Bytes.toString(actual), row, actual); } }
Result r = scanner.cache.poll(); assertNotNull(r); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv1, cs.current()); assertFalse(cs.advance());
Result r = scanner.cache.poll(); assertNotNull(r); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv1, cs.current()); assertFalse(cs.advance());
Result r = scanner.cache.poll(); assertNotNull(r); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv1, cs.current()); assertFalse(cs.advance()); cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv2, cs.current()); assertFalse(cs.advance()); cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv3, cs.current()); assertFalse(cs.advance());
Result r = scanner.cache.poll(); assertNotNull(r); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv1, cs.current()); assertFalse(cs.advance());
Result r = scanner.cache.poll(); assertNotNull(r); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv1, cs.current()); assertFalse(cs.advance()); cs = r.cellScanner(); assertTrue(cs.advance()); assertEquals(kv2, cs.current()); assertFalse(cs.advance());
private long extractSnapshotSize( Table quotaTable, TableName tn, String snapshot) throws IOException { Get g = QuotaTableUtil.makeGetForSnapshotSize(tn, snapshot); Result r = quotaTable.get(g); assertNotNull(r); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); Cell c = cs.current(); assertNotNull(c); return QuotaTableUtil.extractSnapshotSize( c.getValueArray(), c.getValueOffset(), c.getValueLength()); }
private void verifyTableSnapshotSize( Table quotaTable, TableName tn, String snapshotName, long expectedSize) throws IOException { Result r = quotaTable.get(QuotaTableUtil.makeGetForSnapshotSize(tn, snapshotName)); CellScanner cs = r.cellScanner(); assertTrue(cs.advance()); Cell c = cs.current(); assertEquals(expectedSize, QuotaProtos.SpaceQuotaSnapshot.parseFrom( UnsafeByteOperations.unsafeWrap( c.getValueArray(), c.getValueOffset(), c.getValueLength())).getQuotaUsage()); assertFalse(cs.advance()); } }
@Test public void testSimpleVisibilityLabels() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL, PRIVATE + "|" + CONFIDENTIAL)) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 2); CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); } }
@Test public void testVisibilityLabelsWithComplexLabels() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET, "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")")) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(TOPSECRET, CONFIDENTIAL, PRIVATE, PUBLIC, SECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(4); assertEquals(3, next.length); CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row3, 0, row3.length)); cellScanner = next[2].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row4, 0, row4.length)); } }
Result r = ht.get(new Get(row)); int i = 0; for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] f = fs[i++]; assertTrue(Bytes.toString(f),
Result[] next = scanner.next(3); for (Result result : next) { CellScanner cellScanner = result.cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertEquals(0, current.getTagsLength()); Result[] next = scanner.next(3); for (Result result : next) { CellScanner cellScanner = result.cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertEquals(0, current.getTagsLength());