Repository: hbase Updated Branches: refs/heads/master 8816fa05c -> c32a2c0b1
HBASE-12839 Remove synchronization in ServerStatisticsTracker Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c32a2c0b Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c32a2c0b Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c32a2c0b Branch: refs/heads/master Commit: c32a2c0b16b1d7e41fd0ad4a2737b7f0f2806c82 Parents: 8816fa0 Author: Andrew Purtell <[email protected]> Authored: Mon Jan 12 16:06:51 2015 -0800 Committer: Andrew Purtell <[email protected]> Committed: Mon Jan 12 16:06:51 2015 -0800 ---------------------------------------------------------------------- .../hbase/client/ServerStatisticTracker.java | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/c32a2c0b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java index 0c7b683..42da0b3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java @@ -34,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; @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 @@ -42,14 +42,15 @@ public class ServerStatisticTracker { 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); @@ -71,4 +72,4 @@ public class ServerStatisticTracker { ServerStatistics getServerStatsForTesting(ServerName server) { return stats.get(server); } -} \ No newline at end of file +}
