IGNITE-4060: Fixed a bug in RoundRobinLoadBalancing API causing exception when 
running closures after client node reconnect. This closes #1157.


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

Branch: refs/heads/ignite-ssl-hotfix
Commit: 7adfbcf1ee7bbe0beb95fa82749a2e04449de8fa
Parents: 447e07c
Author: tledkov-gridgain <tled...@gridgain.com>
Authored: Fri Oct 14 17:48:14 2016 +0300
Committer: vozerov-gridgain <voze...@gridgain.com>
Committed: Fri Oct 14 17:48:14 2016 +0300

----------------------------------------------------------------------
 .../RoundRobinGlobalLoadBalancer.java           | 16 +++-
 ...RoundRobinErrorAfterClientReconnectTest.java | 99 ++++++++++++++++++++
 .../testsuites/IgniteComputeGridTestSuite.java  |  2 +
 3 files changed, 114 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7adfbcf1/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinGlobalLoadBalancer.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinGlobalLoadBalancer.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinGlobalLoadBalancer.java
index c48b819..9ce854f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinGlobalLoadBalancer.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinGlobalLoadBalancer.java
@@ -26,7 +26,6 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cluster.ClusterNode;
@@ -38,6 +37,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.IgniteSpiContext;
 
+import static org.apache.ignite.events.EventType.EVT_CLIENT_NODE_RECONNECTED;
 import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
 import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
 import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
@@ -101,6 +101,16 @@ class RoundRobinGlobalLoadBalancer {
                                 nodeList = new GridNodeList(0, newNodes);
                             }
                         }
+                        else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
+                            Collection<ClusterNode> nodes = 
((DiscoveryEvent)evt).topologyNodes();
+
+                            List<UUID> newNodes = new 
ArrayList<>(nodes.size());
+
+                            for (ClusterNode node : nodes)
+                                newNodes.add(node.id());
+
+                            nodeList = new GridNodeList(0, newNodes);
+                        }
                         else {
                             assert evt.type() == EVT_NODE_LEFT || evt.type() 
== EVT_NODE_FAILED;
 
@@ -119,7 +129,7 @@ class RoundRobinGlobalLoadBalancer {
                     }
                 }
             },
-            EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT
+            EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT, 
EVT_CLIENT_NODE_RECONNECTED
         );
 
         synchronized (mux) {
@@ -147,7 +157,7 @@ class RoundRobinGlobalLoadBalancer {
      *
      * @param top Topology to pick from.
      * @return Best balanced node.
-     * @throws IgniteCheckedException Thrown in case of any error.
+     * @throws IgniteException Thrown in case of any error.
      */
     ClusterNode getBalancedNode(Collection<ClusterNode> top) throws 
IgniteException {
         assert !F.isEmpty(top);

http://git-wip-us.apache.org/repos/asf/ignite/blob/7adfbcf1/modules/core/src/test/java/org/apache/ignite/internal/IgniteRoundRobinErrorAfterClientReconnectTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/IgniteRoundRobinErrorAfterClientReconnectTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/IgniteRoundRobinErrorAfterClientReconnectTest.java
new file mode 100644
index 0000000..0ec3b6b
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/IgniteRoundRobinErrorAfterClientReconnectTest.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test to reproduce IGNITE-4060.
+ */
+public class IgniteRoundRobinErrorAfterClientReconnectTest extends 
GridCommonAbstractTest {
+    /** Server index. */
+    private static final int SRV_IDX = 0;
+
+    /** Client index. */
+    private static final int CLI_IDX = 1;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGrid(SRV_IDX);
+        startGrid(CLI_IDX);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (gridName.endsWith("1"))
+            cfg.setClientMode(true);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 60000;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientReconnect() throws Exception {
+        final Ignite cli = grid(CLI_IDX);
+
+        final GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
+
+        cli.events().localListen(new IgnitePredicate<Event>() {
+            @Override public boolean apply(Event event) {
+                try {
+                    cli.compute().apply(new IgniteClosure<String, Void>() {
+                        @Override public Void apply(String arg) {
+                            return null;
+                        }
+                    }, "Hello!");
+
+                    fut.onDone(true);
+
+                    return true;
+                }
+                catch (Exception e) {
+                    fut.onDone(e);
+
+                    return false;
+                }
+            }
+        }, EventType.EVT_CLIENT_NODE_RECONNECTED);
+
+        stopGrid(SRV_IDX);
+        startGrid(SRV_IDX);
+
+        assert fut.get();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7adfbcf1/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
index 699ad0c..a1a75f8 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java
@@ -66,6 +66,7 @@ import 
org.apache.ignite.internal.IgniteComputeEmptyClusterGroupTest;
 import org.apache.ignite.internal.IgniteComputeTopologyExceptionTest;
 import org.apache.ignite.internal.IgniteExecutorServiceTest;
 import org.apache.ignite.internal.IgniteExplicitImplicitDeploymentSelfTest;
+import 
org.apache.ignite.internal.IgniteRoundRobinErrorAfterClientReconnectTest;
 import org.apache.ignite.internal.TaskNodeRestartTest;
 import 
org.apache.ignite.internal.managers.checkpoint.GridCheckpointManagerSelfTest;
 import 
org.apache.ignite.internal.managers.checkpoint.GridCheckpointTaskSelfTest;
@@ -148,6 +149,7 @@ public class IgniteComputeGridTestSuite {
         suite.addTestSuite(IgniteComputeTopologyExceptionTest.class);
         suite.addTestSuite(GridTaskFailoverAffinityRunTest.class);
         suite.addTestSuite(TaskNodeRestartTest.class);
+        
suite.addTestSuite(IgniteRoundRobinErrorAfterClientReconnectTest.class);
 
         return suite;
     }

Reply via email to