Skip to content

Commit dcb78bd

Browse files
committed
HBASE-25454 Add trace support for connection registry (#2828)
Signed-off-by: stack <[email protected]>
1 parent 805b2ae commit dcb78bd

File tree

2 files changed

+58
-41
lines changed

2 files changed

+58
-41
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/MasterRegistry.java

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import static org.apache.hadoop.hbase.HConstants.MASTER_ADDRS_KEY;
21+
import static org.apache.hadoop.hbase.trace.TraceUtil.trace;
22+
import static org.apache.hadoop.hbase.trace.TraceUtil.tracedFuture;
2123
import static org.apache.hadoop.hbase.util.DNS.getHostname;
2224
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
2325

@@ -266,18 +268,23 @@ private static RegionLocations transformMetaRegionLocations(GetMetaRegionLocatio
266268

267269
@Override
268270
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
269-
return this.<GetMetaRegionLocationsResponse> call((c, s, d) -> s.getMetaRegionLocations(c,
270-
GetMetaRegionLocationsRequest.getDefaultInstance(), d), r -> r.getMetaLocationsCount() != 0,
271-
"getMetaLocationsCount").thenApply(MasterRegistry::transformMetaRegionLocations);
271+
return tracedFuture(
272+
() -> this
273+
.<GetMetaRegionLocationsResponse> call(
274+
(c, s, d) -> s.getMetaRegionLocations(c,
275+
GetMetaRegionLocationsRequest.getDefaultInstance(), d),
276+
r -> r.getMetaLocationsCount() != 0, "getMetaLocationsCount")
277+
.thenApply(MasterRegistry::transformMetaRegionLocations),
278+
"MasterRegistry.getMetaRegionLocations");
272279
}
273280

274281
@Override
275282
public CompletableFuture<String> getClusterId() {
276-
return this
283+
return tracedFuture(() -> this
277284
.<GetClusterIdResponse> call(
278285
(c, s, d) -> s.getClusterId(c, GetClusterIdRequest.getDefaultInstance(), d),
279286
GetClusterIdResponse::hasClusterId, "getClusterId()")
280-
.thenApply(GetClusterIdResponse::getClusterId);
287+
.thenApply(GetClusterIdResponse::getClusterId), "MasterRegistry.getClusterId");
281288
}
282289

283290
private static boolean hasActiveMaster(GetMastersResponse resp) {
@@ -300,21 +307,23 @@ private static ServerName filterActiveMaster(GetMastersResponse resp) throws IOE
300307

301308
@Override
302309
public CompletableFuture<ServerName> getActiveMaster() {
303-
CompletableFuture<ServerName> future = new CompletableFuture<>();
304-
addListener(call((c, s, d) -> s.getMasters(c, GetMastersRequest.getDefaultInstance(), d),
305-
MasterRegistry::hasActiveMaster, "getMasters()"), (resp, ex) -> {
306-
if (ex != null) {
307-
future.completeExceptionally(ex);
308-
}
309-
ServerName result = null;
310-
try {
311-
result = filterActiveMaster((GetMastersResponse)resp);
312-
} catch (IOException e) {
313-
future.completeExceptionally(e);
314-
}
315-
future.complete(result);
316-
});
317-
return future;
310+
return tracedFuture(() -> {
311+
CompletableFuture<ServerName> future = new CompletableFuture<>();
312+
addListener(call((c, s, d) -> s.getMasters(c, GetMastersRequest.getDefaultInstance(), d),
313+
MasterRegistry::hasActiveMaster, "getMasters()"), (resp, ex) -> {
314+
if (ex != null) {
315+
future.completeExceptionally(ex);
316+
}
317+
ServerName result = null;
318+
try {
319+
result = filterActiveMaster((GetMastersResponse) resp);
320+
} catch (IOException e) {
321+
future.completeExceptionally(e);
322+
}
323+
future.complete(result);
324+
});
325+
return future;
326+
}, "MasterRegistry.getActiveMaster");
318327
}
319328

320329
private static List<ServerName> transformServerNames(GetMastersResponse resp) {
@@ -335,11 +344,13 @@ Set<ServerName> getParsedMasterServers() {
335344

336345
@Override
337346
public void close() {
338-
if (masterAddressRefresher != null) {
339-
masterAddressRefresher.close();
340-
}
341-
if (rpcClient != null) {
342-
rpcClient.close();
343-
}
347+
trace(() -> {
348+
if (masterAddressRefresher != null) {
349+
masterAddressRefresher.close();
350+
}
351+
if (rpcClient != null) {
352+
rpcClient.close();
353+
}
354+
}, "MasterRegistry.close");
344355
}
345356
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZKConnectionRegistry.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForDefaultReplica;
2323
import static org.apache.hadoop.hbase.client.RegionReplicaUtil.getRegionInfoForReplica;
2424
import static org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.lengthOfPBMagic;
25+
import static org.apache.hadoop.hbase.trace.TraceUtil.tracedFuture;
2526
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
2627
import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData;
2728

@@ -94,7 +95,9 @@ private static String getClusterId(byte[] data) throws DeserializationException
9495

9596
@Override
9697
public CompletableFuture<String> getClusterId() {
97-
return getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId);
98+
return tracedFuture(
99+
() -> getAndConvert(znodePaths.clusterIdZNode, ZKConnectionRegistry::getClusterId),
100+
"ZKConnectionRegistry.getClusterId");
98101
}
99102

100103
ReadOnlyZKClient getZKClient() {
@@ -192,19 +195,20 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
192195

193196
@Override
194197
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
195-
CompletableFuture<RegionLocations> future = new CompletableFuture<>();
196-
addListener(
197-
zk.list(znodePaths.baseZNode)
198-
.thenApply(children -> children.stream()
198+
return tracedFuture(() -> {
199+
CompletableFuture<RegionLocations> future = new CompletableFuture<>();
200+
addListener(
201+
zk.list(znodePaths.baseZNode).thenApply(children -> children.stream()
199202
.filter(c -> this.znodePaths.isMetaZNodePrefix(c)).collect(Collectors.toList())),
200-
(metaReplicaZNodes, error) -> {
201-
if (error != null) {
202-
future.completeExceptionally(error);
203-
return;
204-
}
205-
getMetaRegionLocation(future, metaReplicaZNodes);
206-
});
207-
return future;
203+
(metaReplicaZNodes, error) -> {
204+
if (error != null) {
205+
future.completeExceptionally(error);
206+
return;
207+
}
208+
getMetaRegionLocation(future, metaReplicaZNodes);
209+
});
210+
return future;
211+
}, "ZKConnectionRegistry.getMetaRegionLocations");
208212
}
209213

210214
private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOException {
@@ -218,15 +222,17 @@ private static ZooKeeperProtos.Master getMasterProto(byte[] data) throws IOExcep
218222

219223
@Override
220224
public CompletableFuture<ServerName> getActiveMaster() {
221-
return getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
225+
return tracedFuture(
226+
() -> getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
222227
.thenApply(proto -> {
223228
if (proto == null) {
224229
return null;
225230
}
226231
HBaseProtos.ServerName snProto = proto.getMaster();
227232
return ServerName.valueOf(snProto.getHostName(), snProto.getPort(),
228233
snProto.getStartCode());
229-
});
234+
}),
235+
"ZKConnectionRegistry.getActiveMaster");
230236
}
231237

232238
@Override

0 commit comments

Comments
 (0)