Search in sources :

Example 11 with AsyncTable

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;
}
Also used : ReadType(org.apache.hadoop.hbase.client.Scan.ReadType) AdvancedScanResultConsumer(org.apache.hadoop.hbase.client.AdvancedScanResultConsumer) Logger(org.slf4j.Logger) FutureUtils.addListener(org.apache.hadoop.hbase.util.FutureUtils.addListener) Result(org.apache.hadoop.hbase.client.Result) Get(org.apache.hadoop.hbase.client.Get) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) TableState(org.apache.hadoop.hbase.client.TableState) Collectors(java.util.stream.Collectors) Scan(org.apache.hadoop.hbase.client.Scan) ArrayList(java.util.ArrayList) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Closeable(java.io.Closeable) Optional(java.util.Optional) AsyncTable(org.apache.hadoop.hbase.client.AsyncTable) Consistency(org.apache.hadoop.hbase.client.Consistency) Collections(java.util.Collections) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Bytes(org.apache.hadoop.hbase.util.Bytes) Pair(org.apache.hadoop.hbase.util.Pair) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) Get(org.apache.hadoop.hbase.client.Get) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException)

Example 12 with AsyncTable

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();
        }
    });
}
Also used : Arrays(java.util.Arrays) Result(org.apache.hadoop.hbase.client.Result) Assert.assertThrows(org.junit.Assert.assertThrows) LoggerFactory(org.slf4j.LoggerFactory) HConstants(org.apache.hadoop.hbase.HConstants) TestName(org.junit.rules.TestName) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) StreamSupport(java.util.stream.StreamSupport) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) TableName(org.apache.hadoop.hbase.TableName) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Put(org.apache.hadoop.hbase.client.Put) Assert.assertTrue(org.junit.Assert.assertTrue) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Scan(org.apache.hadoop.hbase.client.Scan) TimeUnit(java.util.concurrent.TimeUnit) Stream(java.util.stream.Stream) Rule(org.junit.Rule) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Connection(org.apache.hadoop.hbase.client.Connection) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) AsyncTable(org.apache.hadoop.hbase.client.AsyncTable) Table(org.apache.hadoop.hbase.client.Table) TableName(org.apache.hadoop.hbase.TableName) AsyncTable(org.apache.hadoop.hbase.client.AsyncTable) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Connection(org.apache.hadoop.hbase.client.Connection) Scan(org.apache.hadoop.hbase.client.Scan) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

AsyncTable (org.apache.hadoop.hbase.client.AsyncTable)12 Result (org.apache.hadoop.hbase.client.Result)10 Bytes (org.apache.hadoop.hbase.util.Bytes)10 IOException (java.io.IOException)9 HConstants (org.apache.hadoop.hbase.HConstants)9 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)9 Scan (org.apache.hadoop.hbase.client.Scan)9 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)9 Map (java.util.Map)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 AdvancedScanResultConsumer (org.apache.hadoop.hbase.client.AdvancedScanResultConsumer)8 FutureUtils.addListener (org.apache.hadoop.hbase.util.FutureUtils.addListener)8 NavigableMap (java.util.NavigableMap)7 NavigableSet (java.util.NavigableSet)7 NoSuchElementException (java.util.NoSuchElementException)7 TreeMap (java.util.TreeMap)7 Cell (org.apache.hadoop.hbase.Cell)7 CoprocessorCallback (org.apache.hadoop.hbase.client.AsyncTable.CoprocessorCallback)7 AggregationHelper.getParsedGenericInstance (org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.getParsedGenericInstance)7 AggregationHelper.validateArgAndGetPB (org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.validateArgAndGetPB)7