public static Get makeGetForUserQuotas(final String user, final Iterable<TableName> tables, final Iterable<String> namespaces) { Get get = new Get(getUserRowKey(user)); get.addColumn(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS); for (final TableName table: tables) { get.addColumn(QUOTA_FAMILY_INFO, getSettingsQualifierForUserTable(table)); } for (final String ns: namespaces) { get.addColumn(QUOTA_FAMILY_INFO, getSettingsQualifierForUserNamespace(ns)); } return get; }
/** * Creates a {@link Get} for the HBase snapshot's size against the given table. */ static Get makeGetForSnapshotSize(TableName tn, String snapshot) { Get g = new Get(Bytes.add(QUOTA_TABLE_ROW_KEY_PREFIX, Bytes.toBytes(tn.toString()))); g.addColumn( QUOTA_FAMILY_USAGE, Bytes.add(QUOTA_SNAPSHOT_SIZE_QUALIFIER, Bytes.toBytes(snapshot))); return g; }
@Test public void testIncrement() throws InterruptedException, ExecutionException { AsyncTable<?> table = getTable.get(); int count = 100; CountDownLatch latch = new CountDownLatch(count); AtomicLong sum = new AtomicLong(0L); IntStream.range(0, count) .forEach(i -> table.incrementColumnValue(row, FAMILY, QUALIFIER, 1).thenAccept(x -> { sum.addAndGet(x); latch.countDown(); })); latch.await(); assertEquals(count, Bytes.toLong( table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER))); assertEquals((1 + count) * count / 2, sum.get()); }
@Test public void testDisableAndEnableTable() throws IOException { final byte [] row = Bytes.toBytes("row"); final byte [] qualifier = Bytes.toBytes("qualifier"); final byte [] value = Bytes.toBytes("value"); final TableName table = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(table, HConstants.CATALOG_FAMILY); Put put = new Put(row); put.addColumn(HConstants.CATALOG_FAMILY, qualifier, value); ht.put(put); Get get = new Get(row); get.addColumn(HConstants.CATALOG_FAMILY, qualifier); ht.get(get); get = new Get(row); get.addColumn(HConstants.CATALOG_FAMILY, qualifier); boolean ok = false; try { ht.get(get); } catch (TableNotEnabledException e) { ok = true; ht.get(get); } catch (RetriesExhaustedException e) { ok = false;
public void doTestDelete_AndPostInsert(Delete delete) throws IOException, InterruptedException { this.region = initHRegion(tableName, method, CONF, fam1); EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge()); Put put = new Put(row); put.addColumn(fam1, qual1, value1); region.put(put); put = new Put(row); put.addColumn(fam1, qual1, value2); region.put(put); Get get = new Get(row); get.addColumn(fam1, qual1);
/** * Ensure the optimize Scan method in StoreScanner does not get in the way of a Get doing minimum * work... seeking to start of block and then SKIPPING until we find the wanted Cell. * This 'simple' scenario mimics case of all Cells fitting inside a single HFileBlock. * See HBASE-15392. This test is a little cryptic. Takes a bit of staring to figure what it up to. * @throws IOException */ @Test public void testOptimizeAndGet() throws IOException { // First test a Get of two columns in the row R2. Every Get is a Scan. Get columns named // R2 and R3. Get get = new Get(TWO); get.addColumn(CF, TWO); get.addColumn(CF, THREE); Scan scan = new Scan(get); try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); // For a Get there should be no more next's after the first call. assertEquals(false, scanner.next(results)); // Should be one result only. assertEquals(2, results.size()); // And we should have gone through optimize twice only. assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", 3, scanner.count.get()); } }
private void get(ChannelHandlerContext ctx, FullHttpRequest req) { Params params = parse(req); conn.getTable(TableName.valueOf(params.table)).get(new Get(Bytes.toBytes(params.row)) .addColumn(Bytes.toBytes(params.family), Bytes.toBytes(params.qualifier))) .whenComplete((r, e) -> { if (e != null) { exceptionCaught(ctx, e); } else { byte[] value = r.getValue(Bytes.toBytes(params.family), Bytes.toBytes(params.qualifier)); if (value != null) { write(ctx, HttpResponseStatus.OK, Optional.of(Bytes.toStringBinary(value))); } else { write(ctx, HttpResponseStatus.NOT_FOUND, Optional.empty()); } } }); }
/** * Ensure that optimize does not cause the Get to do more seeking than required. Optimize * (see HBASE-15392) was causing us to seek all Cells in a block when a Get Scan if the next block * index/start key was a different row to the current one. A bug. We'd call next too often * because we had to exhaust all Cells in the current row making us load the next block just to * discard what we read there. This test is a little cryptic. Takes a bit of staring to figure * what it up to. * @throws IOException */ @Test public void testOptimizeAndGetWithFakedNextBlockIndexStart() throws IOException { // First test a Get of second column in the row R2. Every Get is a Scan. Second column has a // qualifier of R2. Get get = new Get(THREE); get.addColumn(CF, TWO); Scan scan = new Scan(get); try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); // For a Get there should be no more next's after the first call. assertEquals(false, scanner.next(results)); // Should be one result only. assertEquals(1, results.size()); // And we should have gone through optimize twice only. assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", 2, scanner.count.get()); } }
public static long[] getReplicationBarrier(Connection conn, byte[] regionName) throws IOException { try (Table table = getMetaHTable(conn)) { Result result = table.get(new Get(regionName) .addColumn(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER) .readAllVersions()); return getReplicationBarriers(result); } }
@Before public void setUp() throws Exception { this.conf = HBaseConfiguration.create(); row1 = Bytes.toBytes("row1"); row2 = Bytes.toBytes("row2"); row3 = Bytes.toBytes("row3"); fam1 = Bytes.toBytes("fam1"); fam2 = Bytes.toBytes("fam2"); col1 = Bytes.toBytes("col1"); col2 = Bytes.toBytes("col2"); col3 = Bytes.toBytes("col3"); col4 = Bytes.toBytes("col4"); col5 = Bytes.toBytes("col5"); data = Bytes.toBytes("data"); // Create Get get = new Get(row1); get.addFamily(fam1); get.addColumn(fam2, col2); get.addColumn(fam2, col4); get.addColumn(fam2, col5); this.scan = new Scan(get); rowComparator = CellComparator.getInstance(); } }
private static Quotas getQuotas(final Connection connection, final byte[] rowKey, final byte[] qualifier) throws IOException { Get get = new Get(rowKey); get.addColumn(QUOTA_FAMILY_INFO, qualifier); Result result = doGet(connection, get); if (result.isEmpty()) { return null; } return quotasFromData(result.getValue(QUOTA_FAMILY_INFO, qualifier)); }
@Test public void testSimple() throws Exception { AsyncTable<?> table = getTable.get(); table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).get(); assertTrue(table.exists(new Get(row).addColumn(FAMILY, QUALIFIER)).get()); Result result = table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); table.delete(new Delete(row)).get(); result = table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get(); assertTrue(result.isEmpty()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, QUALIFIER)).get()); }
@Test public void testHTableDeleteWithList() throws Exception { LOG.info("test=testHTableDeleteWithList"); Table table = UTIL.getConnection().getTable(TEST_TABLE); // Load some data List<Put> puts = constructPutRequests(); Object[] results = new Object[puts.size()]; table.batch(puts, results); validateSizeAndEmpty(results, KEYS.length); // Deletes ArrayList<Delete> deletes = new ArrayList<>(); for (int i = 0; i < KEYS.length; i++) { Delete delete = new Delete(KEYS[i]); delete.addFamily(BYTES_FAMILY); deletes.add(delete); } table.delete(deletes); Assert.assertTrue(deletes.isEmpty()); // Get to make sure ... for (byte[] k : KEYS) { Get get = new Get(k); get.addColumn(BYTES_FAMILY, QUALIFIER); Assert.assertFalse(table.exists(get)); } table.close(); }
private Result internalGetFromHTable(Table table, String path, boolean fetchContent, boolean fetchTimestamp) throws IOException { byte[] rowkey = Bytes.toBytes(path); Get get = new Get(rowkey); if (!fetchContent && !fetchTimestamp) { get.setCheckExistenceOnly(true); } else { if (fetchContent) get.addColumn(B_FAMILY, B_COLUMN); if (fetchTimestamp) get.addColumn(B_FAMILY, B_COLUMN_TS); } Result result = table.get(get); boolean exists = result != null && (!result.isEmpty() || (result.getExists() != null && result.getExists())); return exists ? result : null; }