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 0975289d5164..92239355ea8b 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 @@ private static RegionLocations transformMetaRegionLocations(GetMetaRegionLocatio @Override public CompletableFuture getMetaRegionLocations() { - return this. call((c, s, d) -> s.getMetaRegionLocations(c, - GetMetaRegionLocationsRequest.getDefaultInstance(), d), r -> r.getMetaLocationsCount() != 0, - "getMetaLocationsCount").thenApply(MasterRegistry::transformMetaRegionLocations); + return tracedFuture( + () -> this + . call( + (c, s, d) -> s.getMetaRegionLocations(c, + GetMetaRegionLocationsRequest.getDefaultInstance(), d), + r -> r.getMetaLocationsCount() != 0, "getMetaLocationsCount") + .thenApply(MasterRegistry::transformMetaRegionLocations), + "MasterRegistry.getMetaRegionLocations"); } @Override public CompletableFuture getClusterId() { - return this + return tracedFuture(() -> this . 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 @@ private static ServerName filterActiveMaster(GetMastersResponse resp) throws IOE @Override public CompletableFuture getActiveMaster() { - CompletableFuture 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 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 transformServerNames(GetMastersResponse resp) { @@ -335,11 +344,13 @@ Set getParsedMasterServers() { @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 4b31c7a6c8a6..3918dbc6d9cb 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.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 @@ private static String getClusterId(byte[] data) throws DeserializationException @Override public CompletableFuture getClusterId() { - return getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId); + return tracedFuture( + () -> getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId), + "ZKConnectionRegistry.getClusterId"); } ReadOnlyZKClient getZKClient() { @@ -192,19 +195,20 @@ private void getMetaRegionLocation(CompletableFuture future, @Override public CompletableFuture getMetaRegionLocations() { - CompletableFuture future = new CompletableFuture<>(); - addListener( - zk.list(znodePaths.baseZNode) - .thenApply(children -> children.stream() + return tracedFuture(() -> { + CompletableFuture 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 @@ private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOExcep @Override public CompletableFuture 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 @@ public CompletableFuture getActiveMaster() { HBaseProtos.ServerName snProto = proto.getMaster(); return ServerName.valueOf(snProto.getHostName(), snProto.getPort(), snProto.getStartCode()); - }); + }), + "ZKConnectionRegistry.getActiveMaster"); } @Override