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 @Override
40 public T callWithRetries(RetryingCallable<T> callable, int callTimeout)
41 throws IOException, RuntimeException {
42 T result = super.callWithRetries(callable, callTimeout);
43 return updateStatsAndUnwrap(result, callable);
44 }
45
46 @Override
47 public T callWithoutRetries(RetryingCallable<T> callable, int callTimeout)
48 throws IOException, RuntimeException {
49 T result = super.callWithRetries(callable, callTimeout);
50 return updateStatsAndUnwrap(result, callable);
51 }
52
53 private T updateStatsAndUnwrap(T result, RetryingCallable<T> callable) {
54
55 if (!(callable instanceof RegionServerCallable)) {
56 return result;
57 }
58
59 RegionServerCallable<T> regionCallable = (RegionServerCallable) callable;
60 HRegionLocation location = regionCallable.getLocation();
61 return ResultStatsUtil.updateStats(result, stats, location);
62 }
63 }