Skip to content

Commit

Permalink
HBASE-12839 Remove synchronization in ServerStatisticsTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
apurtell committed Jan 13, 2015
1 parent 8816fa0 commit c32a2c0
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@
@InterfaceAudience.Private
public class ServerStatisticTracker {

private final Map<ServerName, ServerStatistics> stats =
private final ConcurrentHashMap<ServerName, ServerStatistics> stats =
new ConcurrentHashMap<ServerName, ServerStatistics>();

public void updateRegionStats(ServerName server, byte[] region, ClientProtos.RegionLoadStats
currentStats) {
ServerStatistics stat = stats.get(server);

if (stat == null) {
// create a stats object and update the stats
synchronized (this) {
stat = stats.get(server);
// we don't have stats for that server yet, so we need to make some
if (stat == null) {
stat = new ServerStatistics();
stats.put(server, stat);
}
stat = stats.get(server);
// We don't have stats for that server yet, so we need to make an entry.
// If we race with another thread it's a harmless unnecessary allocation.
if (stat == null) {
stat = new ServerStatistics();
ServerStatistics old = stats.putIfAbsent(server, stat);
if (old != null) {
stat = old;
}
}
}
stat.update(region, currentStats);
Expand All @@ -71,4 +72,4 @@ public static ServerStatisticTracker create(Configuration conf) {
ServerStatistics getServerStatsForTesting(ServerName server) {
return stats.get(server);
}
}
}

0 comments on commit c32a2c0

Please sign in to comment.