1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import org.apache.hadoop.hbase.HRegionLocation;
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22
23 import java.io.IOException;
24
25
26
27
28
29 @InterfaceAudience.Private
30 public class StatsTrackingRpcRetryingCaller<T> extends RpcRetryingCaller<T> {
31 private final ServerStatisticTracker stats;
32
33 public StatsTrackingRpcRetryingCaller(long pause, int retries, int startLogErrorsCnt,
34 ServerStatisticTracker stats) {
35 super(pause, retries, startLogErrorsCnt);
36 this.stats = stats;
37 }
38
39 public StatsTrackingRpcRetryingCaller(long pause, int retries,
40 RetryingCallerInterceptor interceptor, int startLogErrorsCnt,
41 ServerStatisticTracker stats) {
42 super(pause, retries, interceptor, startLogErrorsCnt, 0);
43 this.stats = stats;
44 }
45
46 @Override
47 public T callWithRetries(RetryingCallable<T> callable, int callTimeout)
48 throws IOException, RuntimeException {
49 T result = super.callWithRetries(callable, callTimeout);
50 return updateStatsAndUnwrap(result, callable);
51 }
52
53 @Override
54 public T callWithoutRetries(RetryingCallable<T> callable, int callTimeout)
55 throws IOException, RuntimeException {
56 T result = super.callWithRetries(callable, callTimeout);
57 return updateStatsAndUnwrap(result, callable);
58 }
59
60 private T updateStatsAndUnwrap(T result, RetryingCallable<T> callable) {
61
62 if (!(callable instanceof RegionServerCallable)) {
63 return result;
64 }
65
66
67
68
69 if (callable instanceof MultiServerCallable) {
70 return result;
71 }
72
73
74 RegionServerCallable<T> regionCallable = (RegionServerCallable) callable;
75 HRegionLocation location = regionCallable.getLocation();
76 return ResultStatsUtil.updateStats(result, stats, location);
77 }
78 }