@Override public Configuration getConfiguration() { return conn.getConfiguration(); }
@Override public CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, int replicaId, boolean reload) { return conn.getLocator().getRegionLocation(tableName, row, replicaId, RegionLocateType.CURRENT, reload, -1L); }
@Override public CompletableFuture<Void> split(TableName tableName, byte[] splitPoint) { CompletableFuture<Void> result = new CompletableFuture<>(); if (splitPoint == null) { return failedFuture(new IllegalArgumentException("splitPoint can not be null.")); } addListener(connection.getRegionLocator(tableName).getRegionLocation(splitPoint), (loc, err) -> { if (err != null) { result.completeExceptionally(err); } else if (loc == null || loc.getRegion() == null) { result.completeExceptionally(new IllegalArgumentException( "Region does not found: rowKey=" + Bytes.toStringBinary(splitPoint))); } else { addListener(splitRegion(loc.getRegion().getRegionName(), splitPoint), (ret, err2) -> { if (err2 != null) { result.completeExceptionally(err2); } else { result.complete(ret); } }); } }); return result; }
MasterService.Interface stub = createMasterStub(sn); HBaseRpcController controller = getRpcController(); stub.isMasterRunning(controller, RequestConverter.buildIsMasterRunningRequest(), new RpcCallback<IsMasterRunningResponse>() {
private void call(HRegionLocation loc) { ClientService.Interface stub; try { stub = conn.getRegionServerStub(loc.getServerName()); } catch (IOException e) { onError(e, () -> "Get async stub to " + loc.getServerName() + " for '" + Bytes.toStringBinary(row) + "' in " + loc.getRegion().getEncodedName() + " of " + tableName + " failed", err -> conn.getLocator().updateCachedLocationOnError(loc, err)); return; } resetCallTimeout(); callable.call(controller, loc, stub).whenComplete((result, error) -> { if (error != null) { onError(error, () -> "Call to " + loc.getServerName() + " for '" + Bytes.toStringBinary(row) + "' in " + loc.getRegion().getEncodedName() + " of " + tableName + " failed", err -> conn.getLocator().updateCachedLocationOnError(loc, err)); return; } future.complete(result); }); }
AtomicBoolean errorTriggered = new AtomicBoolean(false); AtomicInteger count = new AtomicInteger(0); HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get(); AsyncRegionLocator mockedLocator = new AsyncRegionLocator(CONN, AsyncConnectionImpl.RETRY_TIMER) { try (AsyncConnectionImpl mockedConn = new AsyncConnectionImpl(CONN.getConfiguration(), CONN.registry, CONN.registry.getClusterId().get(), User.getCurrent()) { AsyncTable<?> table = mockedConn.getTableBuilder(TABLE_NAME) .setRetryPause(100, TimeUnit.MILLISECONDS).setMaxRetries(5).build(); table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get();
@Override public AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName, ExecutorService pool) { return new AsyncBufferedMutatorBuilderImpl(connConf, getTableBuilder(tableName, pool), RETRY_TIMER); }
@Test public void testRegionMove() throws InterruptedException, ExecutionException, IOException { // This will leave a cached entry in location cache HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get(); int index = TEST_UTIL.getHBaseCluster().getServerWith(loc.getRegion().getRegionName()); TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes( TEST_UTIL.getHBaseCluster().getRegionServer(1 - index).getServerName().getServerName())); AsyncTable<?> table = CONN.getTableBuilder(TABLE_NAME).setRetryPause(100, TimeUnit.MILLISECONDS) .setMaxRetries(30).build(); table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get(); // move back TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes(loc.getServerName().getServerName())); Result result = table.get(new Get(ROW).addColumn(FAMILY, QUALIFIER)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); }
@BeforeClass public static void setUp() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); conf.set(REGION_COPROCESSOR_CONF_KEY, SleepRegionObserver.class.getName()); conf.setLong(HBASE_CLIENT_META_OPERATION_TIMEOUT, 2000); TEST_UTIL.startMiniCluster(1); TEST_UTIL.createTable(TABLE_NAME, FAMILY); TEST_UTIL.waitTableAvailable(TABLE_NAME); AsyncRegistry registry = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration()); CONN = new AsyncConnectionImpl(TEST_UTIL.getConfiguration(), registry, registry.getClusterId().get(), User.getCurrent()); LOCATOR = CONN.getLocator(); }
ClientService.Interface getRegionServerStub(ServerName serverName) throws IOException { ServerName vhostSN = detectVServerName(serverName); return CollectionUtils.computeIfAbsentEx(rsStubs, getStubKey(ClientService.Interface.class.getSimpleName(), vhostSN, hostnameCanChange), () -> createRegionServerStub(vhostSN)); }
AdminService.Interface getAdminStub(ServerName serverName) throws IOException { ServerName vhostSN = detectVServerName(serverName); return CollectionUtils.computeIfAbsentEx(adminSubs, getStubKey(AdminService.Interface.class.getSimpleName(), vhostSN, hostnameCanChange), () -> createAdminServerStub(vhostSN)); }
@Override protected void doCall() { conn.getMasterStub().whenComplete((stub, error) -> { if (error != null) { onError(error, () -> "Get async master stub failed", err -> { }); return; } resetCallTimeout(); callable.call(controller, stub).whenComplete((result, error2) -> { if (error2 != null) { onError(error2, () -> "Call to master failed", err -> { }); return; } future.complete(result); }); }); } }
@Override protected void doCall() { AdminService.Interface adminStub; try { adminStub = this.conn.getAdminStub(serverName); } catch (IOException e) { onError(e, () -> "Get async admin stub to " + serverName + " failed", err -> { }); return; } resetCallTimeout(); callable.call(controller, adminStub).whenComplete((result, error) -> { if (error != null) { onError(error, () -> "Call to admin stub failed", err -> { }); return; } future.complete(result); }); } }
AdminService.Interface getAdminStub(ServerName serverName) throws IOException { return ConcurrentMapUtils.computeIfAbsentEx(adminSubs, getStubKey(AdminService.Interface.class.getSimpleName(), serverName, hostnameCanChange), () -> createAdminServerStub(serverName)); }
ClientService.Interface getRegionServerStub(ServerName serverName) throws IOException { return ConcurrentMapUtils.computeIfAbsentEx(rsStubs, getStubKey(ClientService.Interface.class.getSimpleName(), serverName, hostnameCanChange), () -> createRegionServerStub(serverName)); }
Optional<TableName> tableName = getTableName(); if (tableName.isPresent()) { FutureUtils.addListener(conn.getAdmin().isTableDisabled(tableName.get()), (disabled, e) -> { if (e != null) { if (e instanceof TableNotFoundException) {
AtomicBoolean errorTriggered = new AtomicBoolean(false); AtomicInteger count = new AtomicInteger(0); HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get(); AsyncRegionLocator mockedLocator = new AsyncRegionLocator(CONN, AsyncConnectionImpl.RETRY_TIMER) { try (AsyncConnectionImpl mockedConn = new AsyncConnectionImpl(CONN.getConfiguration(), CONN.registry, CONN.registry.getClusterId().get(), User.getCurrent()) { AsyncTable<?> table = mockedConn.getTableBuilder(TABLE_NAME) .setRetryPause(100, TimeUnit.MILLISECONDS).setMaxRetries(5).build(); table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get();
@Override public AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName) { return new AsyncBufferedMutatorBuilderImpl(connConf, getTableBuilder(tableName), RETRY_TIMER); }
private void call(HRegionLocation loc) { ClientService.Interface stub; try { stub = conn.getRegionServerStub(loc.getServerName()); } catch (IOException e) { onError(e, () -> "Get async stub to " + loc.getServerName() + " for '" + Bytes.toStringBinary(row) + "' in " + loc.getRegion().getEncodedName() + " of " + tableName + " failed", err -> conn.getLocator().updateCachedLocation(loc, err)); return; } resetCallTimeout(); callable.call(controller, loc, stub).whenComplete( (result, error) -> { if (error != null) { onError(error, () -> "Call to " + loc.getServerName() + " for '" + Bytes.toStringBinary(row) + "' in " + loc.getRegion().getEncodedName() + " of " + tableName + " failed", err -> conn.getLocator().updateCachedLocation(loc, err)); return; } future.complete(result); }); }
@Test public void testRegionMove() throws InterruptedException, ExecutionException, IOException { // This will leave a cached entry in location cache HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get(); int index = TEST_UTIL.getHBaseCluster().getServerWith(loc.getRegion().getRegionName()); TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes( TEST_UTIL.getHBaseCluster().getRegionServer(1 - index).getServerName().getServerName())); AsyncTable<?> table = CONN.getTableBuilder(TABLE_NAME) .setRetryPause(100, TimeUnit.MILLISECONDS).setMaxRetries(30).build(); table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get(); // move back TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes(loc.getServerName().getServerName())); Result result = table.get(new Get(ROW).addColumn(FAMILY, QUALIFIER)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); }