saintstack 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_r291392359
 
 

 ##########
 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:
   *8 seems like a lot of threads. What you thinking? Should this method be 
synchronized?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to