ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [01/18] ignite git commit: IGNITE-2263: DANGEROUS! Removed F.view() from TcpDiscoveryNodesRing.
Date Fri, 01 Jan 2016 21:07:28 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2263 e4c49bbdd -> 41fe31365


IGNITE-2263: DANGEROUS! Removed F.view() from TcpDiscoveryNodesRing.


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

Branch: refs/heads/ignite-2263
Commit: 31e2b1302632129f44f4cf01a245c6afbdaf3ddc
Parents: e4c49bb
Author: thatcoach <ppozerov@list.ru>
Authored: Fri Jan 1 15:55:50 2016 +0300
Committer: thatcoach <ppozerov@list.ru>
Committed: Fri Jan 1 15:55:50 2016 +0300

----------------------------------------------------------------------
 .../tcp/internal/TcpDiscoveryNodesRing.java     | 64 ++++++++++----------
 1 file changed, 33 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/31e2b130/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNodesRing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNodesRing.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNodesRing.java
index eb0f74a..d2ac46f 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNodesRing.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNodesRing.java
@@ -32,7 +32,6 @@ import org.jetbrains.annotations.Nullable;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableSet;
@@ -431,16 +430,27 @@ public class TcpDiscoveryNodesRing {
      * @param excluded Nodes to exclude from the search (optional).
      * @return Coordinator node among remaining nodes or {@code null} if all nodes are excluded.
      */
+    @SuppressWarnings("ConstantConditions")
     @Nullable public TcpDiscoveryNode coordinator(@Nullable Collection<TcpDiscoveryNode>
excluded) {
         rwLock.readLock().lock();
 
         try {
-            Collection<TcpDiscoveryNode> filtered = serverNodes(excluded);
+            boolean excludedEmpty = F.isEmpty(excluded);
 
-            if (F.isEmpty(filtered))
-                return null;
+            TcpDiscoveryNode res = null;
+
+            for (TcpDiscoveryNode node : nodes) {
+                if (!node.isClient() && (excludedEmpty || !excluded.contains(node)))
{
+                    if (res == null)
+                        res = node;
+                    else {
+                        if (node.compareTo(res) < 0)
+                            res = node;
+                    }
+                }
+            }
 
-            return Collections.min(filtered);
+            return res;
         }
         finally {
             rwLock.readLock().unlock();
@@ -476,6 +486,7 @@ public class TcpDiscoveryNodesRing {
      * @return Next node or {@code null} if all nodes were filtered out or
      * topology contains less than two nodes.
      */
+    @SuppressWarnings("ConstantConditions")
     @Nullable public TcpDiscoveryNode nextNode(@Nullable Collection<TcpDiscoveryNode>
excluded) {
         assert locNode.internalOrder() > 0 : locNode;
         assert excluded == null || excluded.isEmpty() || !excluded.contains(locNode) : excluded;
@@ -483,21 +494,28 @@ public class TcpDiscoveryNodesRing {
         rwLock.readLock().lock();
 
         try {
-            Collection<TcpDiscoveryNode> filtered = serverNodes(excluded);
+            boolean excludedEmpty = F.isEmpty(excluded);
 
-            if (filtered.size() < 2)
-                return null;
-
-            Iterator<TcpDiscoveryNode> iter = filtered.iterator();
+            TcpDiscoveryNode first = null;
 
-            while (iter.hasNext()) {
-                TcpDiscoveryNode node = iter.next();
+            boolean pickNext = false;
 
-                if (locNode.equals(node))
-                    break;
+            for (TcpDiscoveryNode node : nodes) {
+                if (!node.isClient() && (excludedEmpty || !excluded.contains(node)))
{
+                    if (pickNext)
+                        return node;
+                    else {
+                        if (locNode.equals(node))
+                            pickNext = true;
+                        else {
+                            if (first == null)
+                                first = node;
+                        }
+                    }
+                }
             }
 
-            return iter.hasNext() ? iter.next() : F.first(filtered);
+            return first;
         }
         finally {
             rwLock.readLock().unlock();
@@ -596,22 +614,6 @@ public class TcpDiscoveryNodesRing {
     }
 
     /**
-     * Gets server nodes from topology.
-     *
-     * @param excluded Nodes to exclude from the search (optional).
-     * @return Collection of server nodes.
-     */
-    private Collection<TcpDiscoveryNode> serverNodes(@Nullable final Collection<TcpDiscoveryNode>
excluded) {
-        final boolean excludedEmpty = F.isEmpty(excluded);
-
-        return F.view(nodes, new P1<TcpDiscoveryNode>() {
-            @Override public boolean apply(TcpDiscoveryNode node) {
-                return !node.isClient() && (excludedEmpty || !excluded.contains(node));
-            }
-        });
-    }
-
-    /**
      *
      */
     private void initializeMinimumVersion() {


Mime
View raw message