ignite-224 review

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

Branch: refs/heads/ignite-224
Commit: a6e5181d3d9628f6fec06bb242502390786f98b8
Parents: 2ad2337
Author: Yakov Zhdanov <yzhda...@gridgain.com>
Authored: Wed Feb 18 18:42:47 2015 +0300
Committer: Yakov Zhdanov <yzhda...@gridgain.com>
Committed: Wed Feb 18 18:42:47 2015 +0300

----------------------------------------------------------------------
 .../distributed/dht/GridDhtCacheEntry.java      | 25 +++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6e5181d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
index c591c33..24c97cc 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
@@ -578,8 +578,18 @@ public class GridDhtCacheEntry<K, V> extends 
GridDistributedCacheEntry<K, V> {
      * @return Collection of readers after check.
      * @throws GridCacheEntryRemovedException If removed.
      */
-    @SuppressWarnings("unchecked")
     public synchronized Collection<ReaderId<K, V>> checkReaders() throws 
GridCacheEntryRemovedException {
+        return checkReadersLocked();
+    }
+
+    /**
+     * @return Collection of readers after check.
+     * @throws GridCacheEntryRemovedException If removed.
+     */
+    @SuppressWarnings("unchecked")
+    protected Collection<ReaderId<K, V>> checkReadersLocked() throws 
GridCacheEntryRemovedException {
+        assert Thread.holdsLock(this);
+
         checkObsolete();
 
         ReaderId<K, V>[] rdrs = this.rdrs;
@@ -591,6 +601,8 @@ public class GridDhtCacheEntry<K, V> extends 
GridDistributedCacheEntry<K, V> {
 
         for (int i = 0; i < rdrs.length; i++) {
             if (!cctx.discovery().alive(rdrs[i].nodeId())) {
+                // Node has left and if new list has already been created, 
just skip.
+                // Otherwise, create new list and add alive nodes.
                 if (newRdrs == null) {
                     newRdrs = new ArrayList<>(rdrs.length);
 
@@ -598,10 +610,11 @@ public class GridDhtCacheEntry<K, V> extends 
GridDistributedCacheEntry<K, V> {
                         newRdrs.add(rdrs[i]);
                 }
             }
-            else {
-                if (newRdrs != null)
-                    newRdrs.add(rdrs[i]);
-            }
+            // If node is still alive and no failed nodes
+            // found yet, simply go to next iteration.
+            else if (newRdrs != null)
+                // Some of the nodes has left. Add to list.
+                newRdrs.add(rdrs[i]);
         }
 
         if (newRdrs != null) {
@@ -615,7 +628,7 @@ public class GridDhtCacheEntry<K, V> extends 
GridDistributedCacheEntry<K, V> {
 
     /** {@inheritDoc} */
     @Override protected synchronized boolean hasReaders() throws 
GridCacheEntryRemovedException {
-        checkReaders();
+        checkReadersLocked();
 
         return rdrs.length > 0;
     }

Reply via email to