1818package org .apache .hadoop .hbase .client ;
1919
2020import 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 ;
2123import static org .apache .hadoop .hbase .util .DNS .getHostname ;
2224import 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}
0 commit comments