use of org.apache.hadoop.hbase.client.AsyncTable in project hbase by apache.
the class ClientMetaTableAccessor method getRegionLocation.
/**
* Returns the HRegionLocation from meta for the given region
* @param metaTable
* @param regionName region we're looking for
* @return HRegionLocation for the given region
*/
public static CompletableFuture<Optional<HRegionLocation>> getRegionLocation(AsyncTable<?> metaTable, byte[] regionName) {
CompletableFuture<Optional<HRegionLocation>> future = new CompletableFuture<>();
try {
RegionInfo parsedRegionInfo = CatalogFamilyFormat.parseRegionInfoFromRegionName(regionName);
addListener(metaTable.get(new Get(CatalogFamilyFormat.getMetaKeyForRegion(parsedRegionInfo)).addFamily(HConstants.CATALOG_FAMILY)), (r, err) -> {
if (err != null) {
future.completeExceptionally(err);
return;
}
future.complete(getRegionLocations(r).map(locations -> locations.getRegionLocation(parsedRegionInfo.getReplicaId())));
});
} catch (IOException parseEx) {
LOG.warn("Failed to parse the passed region name: " + Bytes.toStringBinary(regionName));
future.completeExceptionally(parseEx);
}
return future;
}
use of org.apache.hadoop.hbase.client.AsyncTable in project hbase by apache.
the class TestMasterRepairMode method testExistingCluster.
@Test
public void testExistingCluster() throws Exception {
TableName testRepairMode = TableName.valueOf(name.getMethodName());
TEST_UTIL.startMiniCluster();
Table t = TEST_UTIL.createTable(testRepairMode, FAMILYNAME);
Put p = new Put(Bytes.toBytes("r"));
p.addColumn(FAMILYNAME, Bytes.toBytes("c"), new byte[0]);
t.put(p);
TEST_UTIL.shutdownMiniHBaseCluster();
LOG.info("Starting master-only");
enableMaintenanceMode();
TEST_UTIL.startMiniHBaseCluster(StartTestingClusterOption.builder().numRegionServers(0).createRootDir(false).build());
Connection conn = TEST_UTIL.getConnection();
assertTrue(conn.getAdmin().isMasterInMaintenanceMode());
try (Table table = conn.getTable(TableName.META_TABLE_NAME);
ResultScanner scanner = table.getScanner(HConstants.TABLE_FAMILY);
Stream<Result> results = StreamSupport.stream(scanner.spliterator(), false)) {
assertTrue("Did not find user table records while reading hbase:meta", results.anyMatch(r -> Arrays.equals(r.getRow(), testRepairMode.getName())));
}
// use async table so we can set the timeout and retry value to let the operation fail fast
AsyncTable<?> table = conn.toAsyncConnection().getTableBuilder(testRepairMode).setScanTimeout(5, TimeUnit.SECONDS).setMaxRetries(2).build();
assertThrows("Should not be able to access user-space tables in repair mode.", Exception.class, () -> {
try (ResultScanner scanner = table.getScanner(new Scan())) {
scanner.next();
}
});
}
Aggregations