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.concurrent.ConcurrentHashMap;
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
29
30
31 @InterfaceAudience.Private
32 public class ServerStatisticTracker implements StatisticTrackable {
33
34 private final ConcurrentHashMap<ServerName, ServerStatistics> stats =
35 new ConcurrentHashMap<ServerName, ServerStatistics>();
36
37 @Override
38 public void updateRegionStats(ServerName server, byte[] region, ClientProtos.RegionLoadStats
39 currentStats) {
40 ServerStatistics stat = stats.get(server);
41
42 if (stat == null) {
43 stat = stats.get(server);
44
45
46 if (stat == null) {
47 stat = new ServerStatistics();
48 ServerStatistics old = stats.putIfAbsent(server, stat);
49 if (old != null) {
50 stat = old;
51 }
52 }
53 }
54 stat.update(region, currentStats);
55 }
56
57 public ServerStatistics getStats(ServerName server) {
58 return this.stats.get(server);
59 }
60
61 public static ServerStatisticTracker create(Configuration conf) {
62 if (!conf.getBoolean(HConstants.ENABLE_CLIENT_BACKPRESSURE,
63 HConstants.DEFAULT_ENABLE_CLIENT_BACKPRESSURE)) {
64 return null;
65 }
66 return new ServerStatisticTracker();
67 }
68
69 ServerStatistics getServerStatsForTesting(ServerName server) {
70 return stats.get(server);
71 }
72 }