You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2021/01/01 15:03:55 UTC

[hbase] 05/05: HBASE-25454 Add trace support for connection registry (#2828)

This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch HBASE-22120
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit 10c4212c26b27079172905151087d0f39532ef11
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Fri Jan 1 22:55:03 2021 +0800

    HBASE-25454 Add trace support for connection registry (#2828)
    
    Signed-off-by: stack <st...@apache.org>
---
 .../apache/hadoop/hbase/client/MasterRegistry.java | 63 +++++++++++++---------
 .../hadoop/hbase/client/ZKConnectionRegistry.java  | 36 +++++++------
 2 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MasterRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MasterRegistry.java
index 0975289..9223935 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MasterRegistry.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MasterRegistry.java
@@ -18,6 +18,8 @@
 package org.apache.hadoop.hbase.client;
 
 import static org.apache.hadoop.hbase.HConstants.MASTER_ADDRS_KEY;
+import static org.apache.hadoop.hbase.trace.TraceUtil.trace;
+import static org.apache.hadoop.hbase.trace.TraceUtil.tracedFuture;
 import static org.apache.hadoop.hbase.util.DNS.getHostname;
 import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
 
@@ -266,18 +268,23 @@ public class MasterRegistry implements ConnectionRegistry {
 
   @Override
   public CompletableFuture<RegionLocations> getMetaRegionLocations() {
-    return this.<GetMetaRegionLocationsResponse> call((c, s, d) -> s.getMetaRegionLocations(c,
-      GetMetaRegionLocationsRequest.getDefaultInstance(), d), r -> r.getMetaLocationsCount() != 0,
-      "getMetaLocationsCount").thenApply(MasterRegistry::transformMetaRegionLocations);
+    return tracedFuture(
+      () -> this
+        .<GetMetaRegionLocationsResponse> call(
+          (c, s, d) -> s.getMetaRegionLocations(c,
+            GetMetaRegionLocationsRequest.getDefaultInstance(), d),
+          r -> r.getMetaLocationsCount() != 0, "getMetaLocationsCount")
+        .thenApply(MasterRegistry::transformMetaRegionLocations),
+      "MasterRegistry.getMetaRegionLocations");
   }
 
   @Override
   public CompletableFuture<String> getClusterId() {
-    return this
+    return tracedFuture(() -> this
       .<GetClusterIdResponse> call(
         (c, s, d) -> s.getClusterId(c, GetClusterIdRequest.getDefaultInstance(), d),
         GetClusterIdResponse::hasClusterId, "getClusterId()")
-      .thenApply(GetClusterIdResponse::getClusterId);
+      .thenApply(GetClusterIdResponse::getClusterId), "MasterRegistry.getClusterId");
   }
 
   private static boolean hasActiveMaster(GetMastersResponse resp) {
@@ -300,21 +307,23 @@ public class MasterRegistry implements ConnectionRegistry {
 
   @Override
   public CompletableFuture<ServerName> getActiveMaster() {
-    CompletableFuture<ServerName> future = new CompletableFuture<>();
-    addListener(call((c, s, d) -> s.getMasters(c, GetMastersRequest.getDefaultInstance(), d),
-      MasterRegistry::hasActiveMaster, "getMasters()"), (resp, ex) -> {
-        if (ex != null) {
-          future.completeExceptionally(ex);
-        }
-        ServerName result = null;
-        try {
-          result = filterActiveMaster((GetMastersResponse)resp);
-        } catch (IOException e) {
-          future.completeExceptionally(e);
-        }
-        future.complete(result);
-      });
-    return future;
+    return tracedFuture(() -> {
+      CompletableFuture<ServerName> future = new CompletableFuture<>();
+      addListener(call((c, s, d) -> s.getMasters(c, GetMastersRequest.getDefaultInstance(), d),
+        MasterRegistry::hasActiveMaster, "getMasters()"), (resp, ex) -> {
+          if (ex != null) {
+            future.completeExceptionally(ex);
+          }
+          ServerName result = null;
+          try {
+            result = filterActiveMaster((GetMastersResponse) resp);
+          } catch (IOException e) {
+            future.completeExceptionally(e);
+          }
+          future.complete(result);
+        });
+      return future;
+    }, "MasterRegistry.getActiveMaster");
   }
 
   private static List<ServerName> transformServerNames(GetMastersResponse resp) {
@@ -335,11 +344,13 @@ public class MasterRegistry implements ConnectionRegistry {
 
   @Override
   public void close() {
-    if (masterAddressRefresher != null) {
-      masterAddressRefresher.close();
-    }
-    if (rpcClient != null) {
-      rpcClient.close();
-    }
+    trace(() -> {
+      if (masterAddressRefresher != null) {
+        masterAddressRefresher.close();
+      }
+      if (rpcClient != null) {
+        rpcClient.close();
+      }
+    }, "MasterRegistry.close");
   }
 }
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java
index 4b31c7a..3918dbc 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java
@@ -22,6 +22,7 @@ import static org.apache.hadoop.hbase.client.RegionInfoBuilder.FIRST_META_REGION
 import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForDefaultReplica;
 import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForReplica;
 import static org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.lengthOfPBMagic;
+import static org.apache.hadoop.hbase.trace.TraceUtil.tracedFuture;
 import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
 import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData;
 
@@ -94,7 +95,9 @@ class ZKConnectionRegistry implements ConnectionRegistry {
 
   @Override
   public CompletableFuture<String> getClusterId() {
-    return getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId);
+    return tracedFuture(
+      () -> getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId),
+      "ZKConnectionRegistry.getClusterId");
   }
 
   ReadOnlyZKClient getZKClient() {
@@ -192,19 +195,20 @@ class ZKConnectionRegistry implements ConnectionRegistry {
 
   @Override
   public CompletableFuture<RegionLocations> getMetaRegionLocations() {
-    CompletableFuture<RegionLocations> future = new CompletableFuture<>();
-    addListener(
-      zk.list(znodePaths.baseZNode)
-        .thenApply(children -> children.stream()
+    return tracedFuture(() -> {
+      CompletableFuture<RegionLocations> future = new CompletableFuture<>();
+      addListener(
+        zk.list(znodePaths.baseZNode).thenApply(children -> children.stream()
           .filter(c -> this.znodePaths.isMetaZNodePrefix(c)).collect(Collectors.toList())),
-      (metaReplicaZNodes, error) -> {
-        if (error != null) {
-          future.completeExceptionally(error);
-          return;
-        }
-        getMetaRegionLocation(future, metaReplicaZNodes);
-      });
-    return future;
+        (metaReplicaZNodes, error) -> {
+          if (error != null) {
+            future.completeExceptionally(error);
+            return;
+          }
+          getMetaRegionLocation(future, metaReplicaZNodes);
+        });
+      return future;
+    }, "ZKConnectionRegistry.getMetaRegionLocations");
   }
 
   private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOException {
@@ -218,7 +222,8 @@ class ZKConnectionRegistry implements ConnectionRegistry {
 
   @Override
   public CompletableFuture<ServerName> getActiveMaster() {
-    return getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
+    return tracedFuture(
+      () -> getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
         .thenApply(proto -> {
           if (proto == null) {
             return null;
@@ -226,7 +231,8 @@ class ZKConnectionRegistry implements ConnectionRegistry {
           HBaseProtos.ServerName snProto = proto.getMaster();
           return ServerName.valueOf(snProto.getHostName(), snProto.getPort(),
             snProto.getStartCode());
-        });
+        }),
+      "ZKConnectionRegistry.getActiveMaster");
   }
 
   @Override