/** * Test for the existence of columns in the table, as specified by the Gets. * This will return an array of booleans. Each value will be true if the related Get matches * one or more keys, false if not. * This is a server-side call so it prevents any data from being transferred to * the client. * * @param gets the Gets * @return Array of boolean. True if the specified Get matches one or more keys, false if not. * @throws IOException e * @deprecated since 2.0 version and will be removed in 3.0 version. * use {@link #exists(List)} */ @Deprecated default boolean[] existsAll(List<Get> gets) throws IOException { return exists(gets); }
public void testCheckAndDelete(Connection connection, String tableName) throws IOException { createTable(thriftAdmin, tableName); try (Table table = connection.getTable(TableName.valueOf(tableName))){ Get get = new Get(ROW_1); Result result = table.get(get); byte[] value1 = result.getValue(FAMILYA, QUALIFIER_1); byte[] value2 = result.getValue(FAMILYB, QUALIFIER_2); assertNotNull(value1); assertTrue(Bytes.equals(VALUE_1, value1)); assertNull(value2); assertTrue(table.exists(get)); assertEquals(1, table.existsAll(Collections.singletonList(get)).length); Delete delete = new Delete(ROW_1); table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenDelete(delete); assertFalse(table.exists(get)); Put put = new Put(ROW_1); put.addColumn(FAMILYA, QUALIFIER_1, VALUE_1); table.put(put); assertTrue(table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenPut(put)); assertFalse(table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1) .ifEquals(VALUE_2).thenPut(put)); } }
/** * Test for the existence of columns in the table, as specified by the Get. * <p> * * This will return true if the Get matches one or more keys, false if not. * <p> * * This is a server-side call so it prevents any data from being transfered to * the client. * * @param get the Get * @return true if the specified Get matches one or more keys, false if not * @throws IOException e */ default boolean exists(Get get) throws IOException { return exists(Collections.singletonList(get))[0]; }
private void assertNotExists(int start, int end) throws IOException { for (int i = start; i < end; i++) { assertFalse(TABLE.exists(new Get(Bytes.toBytes(i)))); } }
@Override public boolean evaluate() throws Exception { try (Table table = UTIL1.getConnection().getTable(TABLE_NAME)) { return table.exists(new Get(Bytes.toBytes(0))); } }
@Override public boolean exists(ByteBuffer table, TGet get) throws TIOError, TException { Table htable = getTable(table); try { return htable.exists(getFromThrift(get)); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public boolean contains(String key) { try { Get get = new Get(row(key)); get.addColumn(FAMILY, QUALIFIER); return hbaseTable.exists(get); } catch (IOException e) { throw UserException .dataReadError(e) .message("Caught error while checking row existence '%s' for table '%s'", key, hbaseTableName) .build(logger); } }
@Test public void testHTableExistsMethodMultipleRegionsSingleGet() throws Exception { Table table = TEST_UTIL.createTable( TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY }, 1, new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 255); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); Get get = new Get(ROW); boolean exist = table.exists(get); assertFalse(exist); table.put(put); exist = table.exists(get); assertTrue(exist); }
@Test public void testHTableExistsMethodSingleRegionMultipleGets() throws Exception { Table table = TEST_UTIL.createTable(TableName.valueOf( name.getMethodName()), new byte[][] { FAMILY }); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); List<Get> gets = new ArrayList<>(); gets.add(new Get(ROW)); gets.add(new Get(ANOTHERROW)); boolean[] results = table.exists(gets); assertTrue(results[0]); assertFalse(results[1]); }
@Test public void testHTableExistsMethodSingleRegionSingleGet() throws Exception { // Test with a single region table. Table table = TEST_UTIL.createTable( TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY }); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); Get get = new Get(ROW); boolean exist = table.exists(get); assertFalse(exist); table.put(put); exist = table.exists(get); assertTrue(exist); }
try { table.exists(new Get(Bytes.toBytes("abc"))); } catch (SocketTimeoutException e) {
try { table.exists(new Get(Bytes.toBytes("abc"))); } catch (SocketTimeoutException e) {
@Test public void testBatchWithDelete() throws Exception { LOG.info("test=testBatchWithDelete"); 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 List<Row> deletes = new ArrayList<>(); for (int i = 0; i < KEYS.length; i++) { Delete delete = new Delete(KEYS[i]); delete.addFamily(BYTES_FAMILY); deletes.add(delete); } results= new Object[deletes.size()]; table.batch(deletes, results); validateSizeAndEmpty(results, KEYS.length); // 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(); }
@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(); }
@Test public void testTableExistsGetThrottle() throws Exception { final Admin admin = TEST_UTIL.getAdmin(); // Add throttle quota admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 100, TimeUnit.MINUTES)); triggerTableCacheRefresh(false, TABLE_NAMES[0]); Table table = TEST_UTIL.getConnection().getTable(TABLE_NAMES[0]); // An exists call when having throttle quota table.exists(new Get(Bytes.toBytes("abc"))); admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); triggerTableCacheRefresh(true, TABLE_NAMES[0]); }
@Test public void testHTableExistsBeforeGet() throws Exception { Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY }); try { Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); Get get = new Get(ROW); boolean exist = table.exists(get); assertEquals(true, exist); Result result = table.get(get); assertEquals(false, result.isEmpty()); assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER))); } finally { table.close(); } }
assertTrue(table.exists(g));
@Test public void testDeleteRowForDeletedRegion() throws IOException, ReplicationException { TableName tableName = TableName.valueOf(name.getMethodName()); RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build(); addBarrier(region, 40, 50, 60); fillCatalogFamily(region); String peerId = "1"; ReplicationQueueStorage queueStorage = create(59L); @SuppressWarnings("unchecked") ReplicationPeerManager peerManager = create(queueStorage, Lists.newArrayList(peerId)); ReplicationBarrierCleaner cleaner = create(peerManager); // we have something in catalog family, so only delete 40 cleaner.chore(); assertArrayEquals(new long[] { 50, 60 }, MetaTableAccessor.getReplicationBarrier(UTIL.getConnection(), region.getRegionName())); verify(queueStorage, never()).removeLastSequenceIds(anyString(), anyList()); // No catalog family, then we should remove the whole row clearCatalogFamily(region); cleaner.chore(); try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) { assertFalse(table .exists(new Get(region.getRegionName()).addFamily(HConstants.REPLICATION_BARRIER_FAMILY))); } verify(queueStorage, times(1)).removeLastSequenceIds(peerId, Arrays.asList(region.getEncodedName())); }