storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [03/47] storm git commit: STORM-497: don't modify the mapping while the someone could be reading it.
Date Wed, 12 Nov 2014 16:45:04 GMT
STORM-497: don't modify the mapping while the someone could be reading it.


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/f259f1da
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/f259f1da
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/f259f1da

Branch: refs/heads/security
Commit: f259f1da288171a9393fb500150d034ccca0d146
Parents: 5aae768
Author: Robert (Bobby) Evans <evans@yahoo-inc.com>
Authored: Wed Sep 17 13:07:42 2014 +0000
Committer: Robert (Bobby) Evans <evans@yahoo-inc.com>
Committed: Wed Sep 17 13:07:42 2014 +0000

----------------------------------------------------------------------
 .../jvm/backtype/storm/messaging/netty/Server.java    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/f259f1da/storm-core/src/jvm/backtype/storm/messaging/netty/Server.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/messaging/netty/Server.java b/storm-core/src/jvm/backtype/storm/messaging/netty/Server.java
index 20a147d..2499e65 100644
--- a/storm-core/src/jvm/backtype/storm/messaging/netty/Server.java
+++ b/storm-core/src/jvm/backtype/storm/messaging/netty/Server.java
@@ -56,7 +56,7 @@ class Server implements IConnection {
     final ServerBootstrap bootstrap;
     
     private int queueCount;
-    HashMap<Integer, Integer> taskToQueueId = null;
+    private volatile HashMap<Integer, Integer> taskToQueueId = null;
     int roundRobinQueueId;
 	
     boolean closing = false;
@@ -131,18 +131,18 @@ class Server implements IConnection {
     
     private Integer getMessageQueueId(int task) {
       // try to construct the map from taskId -> queueId in round robin manner.
-      
       Integer queueId = taskToQueueId.get(task);
       if (null == queueId) {
-        synchronized(taskToQueueId) {
-          //assgin task to queue in round-robin manner
-          if (null == taskToQueueId.get(task)) {
+        synchronized (this) {
+          queueId = taskToQueueId.get(task);
+          if (queueId == null) {
             queueId = roundRobinQueueId++;
-            
-            taskToQueueId.put(task, queueId);
             if (roundRobinQueueId == queueCount) {
               roundRobinQueueId = 0;
             }
+            HashMap<Integer, Integer> newRef = new HashMap<Integer, Integer>(taskToQueueId);
+            newRef.put(task, queueId);
+            taskToQueueId = newRef;
           }
         }
       }


Mime
View raw message