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 java.util.List;
21 import java.util.Map;
22
23 import org.apache.hadoop.hbase.HRegionLocation;
24 import org.apache.hadoop.hbase.ServerName;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
27 import org.apache.hadoop.hbase.util.Pair;
28
29
30
31
32 @InterfaceAudience.Private
33 public final class ResultStatsUtil {
34
35 private ResultStatsUtil() {
36
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50 public static <T> T updateStats(T r, ServerStatisticTracker serverStats,
51 ServerName server, byte[] regionName) {
52 if (!(r instanceof Result)) {
53 return r;
54 }
55 Result result = (Result) r;
56
57 ClientProtos.RegionLoadStats stats = result.getStats();
58 if (stats == null) {
59 return r;
60 }
61 serverStats.updateRegionStats(server, regionName, stats);
62 return r;
63 }
64
65 public static <T> T updateStats(T r, ServerStatisticTracker stats,
66 HRegionLocation regionLocation) {
67
68 if (r instanceof MultiResponse) {
69 MultiResponse mr = (MultiResponse) r;
70 for (Map.Entry<byte[], List<Pair<Integer, Object>>> e: mr.getResults().entrySet()) {
71 byte[] regionName = e.getKey();
72 for (Pair<Integer, Object> regionResult : e.getValue()) {
73 Object o = regionResult.getSecond();
74 if (o instanceof Result) {
75 Result result = (Result) o;
76 ClientProtos.RegionLoadStats loadStats = result.getStats();
77 if (loadStats != null) {
78 stats.updateRegionStats(regionLocation.getServerName(), regionName, loadStats);
79
80 break;
81 }
82 }
83 }
84 }
85 }
86 return r;
87 }
88 }