ndimiduk commented on a change in pull request #754: HBASE-22978 : Online slow 
response log
URL: https://github.com/apache/hbase/pull/754#discussion_r371448413
 
 

 ##########
 File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
 ##########
 @@ -3889,4 +3890,72 @@ private void getProcedureResult(long procId, 
CompletableFuture<Void> future, int
         .call();
   }
 
+  @Override
+  public CompletableFuture<List<SlowLogPayload>> 
getSlowLogResponses(List<ServerName> serverNames)
+      throws IOException {
+    CompletableFuture<List<SlowLogPayload>> slowLoadPayloads = null;
+    if (CollectionUtils.isNotEmpty(serverNames)) {
+      for (ServerName serverName : serverNames) {
+        CompletableFuture<List<SlowLogPayload>> slowLogPayloadFromServer =
+          getSlowLogResponseFromServer(serverName);
+        if (slowLoadPayloads == null) {
+          slowLoadPayloads = slowLogPayloadFromServer;
+          continue;
+        }
+        slowLoadPayloads = 
slowLoadPayloads.thenCombine(slowLogPayloadFromServer, (l1, l2) -> {
+          List<SlowLogPayload> finalSlowLogPayloads = new ArrayList<>();
+          finalSlowLogPayloads.addAll(l1);
+          finalSlowLogPayloads.addAll(l2);
+          return finalSlowLogPayloads;
+        });
+      }
+    }
+    return slowLoadPayloads;
+  }
+
+  private CompletableFuture<List<SlowLogPayload>> getSlowLogResponseFromServer(
+      final ServerName serverName) {
+    return this.<List<SlowLogPayload>>newAdminCaller()
+      .action((controller, stub) -> this
+        .adminCall(
+          controller, stub, RequestConverter.buildSlowLogResponseRequest(),
+          AdminService.Interface::getSlowLogResponses,
+          ProtobufUtil::toSlowLogPayloads))
+      .serverName(serverName).call();
+  }
+
+  @Override
+  public CompletableFuture<List<Boolean>> 
clearSlowLogResponses(List<ServerName> serverNames)
+      throws IOException {
+    List<CompletableFuture<Boolean>> clearSlowLogResponseList = new 
ArrayList<>();
+    if (CollectionUtils.isNotEmpty(serverNames)) {
+      for (ServerName serverName : serverNames) {
+        CompletableFuture<Boolean> clearSlowLogResponse = 
clearSlowLogsResponses(serverName);
+        clearSlowLogResponseList.add(clearSlowLogResponse);
+      }
+    }
+    return convertToFutureOfList(clearSlowLogResponseList);
+  }
+
+  private CompletableFuture<Boolean> clearSlowLogsResponses(final ServerName 
serverName) {
+    return this.<Boolean>newAdminCaller()
+      .action(((controller, stub) -> this
+        .adminCall(
+          controller, stub, 
RequestConverter.buildClearSlowLogResponseRequest(),
+          AdminService.Interface::clearSlowLogsResponses,
+          ProtobufUtil::toClearSlowLogPayload))
+      ).serverName(serverName).call();
+  }
+
+  private static <T> CompletableFuture<List<T>> convertToFutureOfList(
+      List<CompletableFuture<T>> futures) {
+    CompletableFuture<Void> allDoneFuture =
+      CompletableFuture.allOf(futures.toArray(new 
CompletableFuture[futures.size()]));
 
 Review comment:
   `futures.toArray(new CompletableFuture[0])`

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

Reply via email to