HBASE-26128 Backport HBASE-25454 "Add trace support for connection re… (#3561)

5/17 commits of HBASE-22120, original commit dcb78bd4bd and merged conflicts after rebasing on HBASE-26150 with commit 63d4970de4

Co-authored-by: Duo Zhang <zhangduo@apache.org>

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Tak Lon (Stephen) Wu 2021-08-12 12:38:53 -07:00
parent 58b5c007b9
commit 7ecf54f365
2 changed files with 53 additions and 35 deletions

View File

@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.client;
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.FutureUtils.addListener;
import com.google.errorprone.annotations.RestrictedApi;
@ -237,38 +239,48 @@ abstract class AbstractRpcBasedConnectionRegistry implements ConnectionRegistry
@Override
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
return this
.<GetMetaRegionLocationsResponse> call((c, s, d) -> s.getMetaRegionLocations(c,
GetMetaRegionLocationsRequest.getDefaultInstance(), d), r -> r.getMetaLocationsCount() != 0,
return tracedFuture(
() -> this
.<GetMetaRegionLocationsResponse> call(
(c, s, d) -> s.getMetaRegionLocations(c,
GetMetaRegionLocationsRequest.getDefaultInstance(), d),
r -> r.getMetaLocationsCount() != 0,
"getMetaLocationsCount")
.thenApply(AbstractRpcBasedConnectionRegistry::transformMetaRegionLocations);
.thenApply(AbstractRpcBasedConnectionRegistry::transformMetaRegionLocations),
getClass().getSimpleName() + ".getMetaRegionLocations");
}
@Override
public CompletableFuture<String> getClusterId() {
return this
.<GetClusterIdResponse> call(
(c, s, d) -> s.getClusterId(c, GetClusterIdRequest.getDefaultInstance(), d),
GetClusterIdResponse::hasClusterId, "getClusterId()")
.thenApply(GetClusterIdResponse::getClusterId);
return tracedFuture(
() -> this
.<GetClusterIdResponse> call(
(c, s, d) -> s.getClusterId(c, GetClusterIdRequest.getDefaultInstance(), d),
GetClusterIdResponse::hasClusterId, "getClusterId()")
.thenApply(GetClusterIdResponse::getClusterId),
getClass().getSimpleName() + ".getClusterId");
}
@Override
public CompletableFuture<ServerName> getActiveMaster() {
return this
.<GetActiveMasterResponse> call(
(c, s, d) -> s.getActiveMaster(c, GetActiveMasterRequest.getDefaultInstance(), d),
GetActiveMasterResponse::hasServerName, "getActiveMaster()")
.thenApply(resp -> ProtobufUtil.toServerName(resp.getServerName()));
return tracedFuture(
() -> this
.<GetActiveMasterResponse>call(
(c, s, d) -> s.getActiveMaster(c, GetActiveMasterRequest.getDefaultInstance(), d),
GetActiveMasterResponse::hasServerName, "getActiveMaster()")
.thenApply(resp -> ProtobufUtil.toServerName(resp.getServerName())),
getClass().getSimpleName() + ".getActiveMaster");
}
@Override
public void close() {
if (registryEndpointRefresher != null) {
registryEndpointRefresher.stop();
}
if (rpcClient != null) {
rpcClient.close();
}
trace(() -> {
if (registryEndpointRefresher != null) {
registryEndpointRefresher.stop();
}
if (rpcClient != null) {
rpcClient.close();
}
}, getClass().getSimpleName() + ".close");
}
}

View File

@ -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;
@ -99,7 +100,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() {
@ -204,19 +207,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 {
@ -230,7 +234,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;
@ -238,7 +243,8 @@ class ZKConnectionRegistry implements ConnectionRegistry {
HBaseProtos.ServerName snProto = proto.getMaster();
return ServerName.valueOf(snProto.getHostName(), snProto.getPort(),
snProto.getStartCode());
});
}),
"ZKConnectionRegistry.getActiveMaster");
}
@Override