HBASE-25454 Add trace support for connection registry (#2828)
Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
805b2ae2ad
commit
dcb78bd4bd
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue