HBASE-12839 Remove synchronization in ServerStatisticsTracker

This commit is contained in:
Andrew Purtell 2015-01-12 16:06:51 -08:00
parent 8816fa05c2
commit c32a2c0b16
1 changed files with 11 additions and 10 deletions

View File

@ -34,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
@InterfaceAudience.Private @InterfaceAudience.Private
public class ServerStatisticTracker { public class ServerStatisticTracker {
private final Map<ServerName, ServerStatistics> stats = private final ConcurrentHashMap<ServerName, ServerStatistics> stats =
new ConcurrentHashMap<ServerName, ServerStatistics>(); new ConcurrentHashMap<ServerName, ServerStatistics>();
public void updateRegionStats(ServerName server, byte[] region, ClientProtos.RegionLoadStats public void updateRegionStats(ServerName server, byte[] region, ClientProtos.RegionLoadStats
@ -42,13 +42,14 @@ public class ServerStatisticTracker {
ServerStatistics stat = stats.get(server); ServerStatistics stat = stats.get(server);
if (stat == null) { if (stat == null) {
// create a stats object and update the stats
synchronized (this) {
stat = stats.get(server); stat = stats.get(server);
// we don't have stats for that server yet, so we need to make some // 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) { if (stat == null) {
stat = new ServerStatistics(); stat = new ServerStatistics();
stats.put(server, stat); ServerStatistics old = stats.putIfAbsent(server, stat);
if (old != null) {
stat = old;
} }
} }
} }