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 com.google.common.annotations.VisibleForTesting;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.HConstants;
23 import org.apache.hadoop.hbase.ServerName;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.client.backoff.ServerStatistics;
26 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
27
28 import java.util.Map;
29 import java.util.concurrent.ConcurrentHashMap;
30
31
32
33
34 @InterfaceAudience.Private
35 public class ServerStatisticTracker implements StatisticTrackable {
36
37 private final ConcurrentHashMap<ServerName, ServerStatistics> stats =
38 new ConcurrentHashMap<ServerName, ServerStatistics>();
39
40 @Override
41 public void updateRegionStats(ServerName server, byte[] region, ClientProtos.RegionLoadStats
42 currentStats) {
43 ServerStatistics stat = stats.get(server);
44
45 if (stat == null) {
46 stat = stats.get(server);
47
48
49 if (stat == null) {
50 stat = new ServerStatistics();
51 ServerStatistics old = stats.putIfAbsent(server, stat);
52 if (old != null) {
53 stat = old;
54 }
55 }
56 }
57 stat.update(region, currentStats);
58 }
59
60 public ServerStatistics getStats(ServerName server) {
61 return this.stats.get(server);
62 }
63
64 public static ServerStatisticTracker create(Configuration conf) {
65 if (!conf.getBoolean(HConstants.ENABLE_CLIENT_BACKPRESSURE,
66 HConstants.DEFAULT_ENABLE_CLIENT_BACKPRESSURE)) {
67 return null;
68 }
69 return new ServerStatisticTracker();
70 }
71
72 @VisibleForTesting
73 ServerStatistics getServerStatsForTesting(ServerName server) {
74 return stats.get(server);
75 }
76 }