Apache9 commented on a change in pull request #287: HBASE-21512 Reimplement
sync client based on async client
URL: https://github.com/apache/hbase/pull/287#discussion_r291518834
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
##########
@@ -695,4 +606,94 @@ static void updateStats(Optional<ServerStatisticTracker>
optStats,
metrics -> ResultStatsUtil.updateStats(metrics, serverName,
regionName, regionLoadStats));
});
}
+
+ @FunctionalInterface
+ interface Converter<D, I, S> {
+ D convert(I info, S src) throws IOException;
+ }
+
+ @FunctionalInterface
+ interface RpcCall<RESP, REQ> {
+ void call(ClientService.Interface stub, HBaseRpcController controller, REQ
req,
+ RpcCallback<RESP> done);
+ }
+
+ static <REQ, PREQ, PRESP, RESP> CompletableFuture<RESP>
call(HBaseRpcController controller,
+ HRegionLocation loc, ClientService.Interface stub, REQ req,
+ Converter<PREQ, byte[], REQ> reqConvert, RpcCall<PRESP, PREQ> rpcCall,
+ Converter<RESP, HBaseRpcController, PRESP> respConverter) {
+ CompletableFuture<RESP> future = new CompletableFuture<>();
+ try {
+ rpcCall.call(stub, controller,
reqConvert.convert(loc.getRegion().getRegionName(), req),
+ new RpcCallback<PRESP>() {
+
+ @Override
+ public void run(PRESP resp) {
+ if (controller.failed()) {
+ future.completeExceptionally(controller.getFailed());
+ } else {
+ try {
+ future.complete(respConverter.convert(controller, resp));
+ } catch (IOException e) {
+ future.completeExceptionally(e);
+ }
+ }
+ }
+ });
+ } catch (IOException e) {
+ future.completeExceptionally(e);
+ }
+ return future;
+ }
+
+ static ThreadPoolExecutor getThreadPool(Configuration conf, int maxThreads,
int coreThreads,
+ Supplier<String> threadName, BlockingQueue<Runnable> passedWorkQueue) {
+ // shared HTable thread executor not yet initialized
+ if (maxThreads == 0) {
+ maxThreads = Runtime.getRuntime().availableProcessors() * 8;
Review comment:
I think this is just copied from the old code in HTable or
ConnectionImplementation... And this is a utility class, we will synchronize in
the methods which call this method.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services