You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/08/21 08:40:16 UTC

[07/50] [abbrv] ignite git commit: IGNITE-6052 request cluster state from daemon node via compute grid - Fixes #2439.

IGNITE-6052 request cluster state from daemon node via compute grid - Fixes #2439.

Signed-off-by: Alexey Goncharuk <al...@gmail.com>


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

Branch: refs/heads/ignite-5578
Commit: 523c5e5d616967bc39f3ca4aa7fec582e230af60
Parents: 5cb5dca
Author: Dmitriy Govorukhin <dm...@gmail.com>
Authored: Mon Aug 14 17:47:11 2017 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Mon Aug 14 17:47:11 2017 +0300

----------------------------------------------------------------------
 .../cluster/GridClusterStateProcessor.java      | 64 +++++++++++++++++---
 .../IgniteStandByClusterTest.java               | 48 ++++++++++++---
 2 files changed, 94 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/523c5e5d/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
index 283a58f..13a889c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java
@@ -55,6 +55,7 @@ import org.apache.ignite.internal.util.typedef.CI2;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteCallable;
 import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.lang.IgniteRunnable;
 import org.apache.ignite.resources.IgniteInstanceResource;
@@ -119,6 +120,9 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
      * @return Cluster state to be used on public API.
      */
     public boolean publicApiActiveState() {
+        if (ctx.isDaemon())
+            return sendComputeCheckGlobalState();
+
         DiscoveryDataClusterState globalState = this.globalState;
 
         assert globalState != null;
@@ -407,7 +411,7 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
         if (ctx.isDaemon() || ctx.clientNode()) {
             GridFutureAdapter<Void> fut = new GridFutureAdapter<>();
 
-            sendCompute(activate, fut);
+            sendComputeChangeGlobalState(activate, fut);
 
             return fut;
         }
@@ -490,11 +494,9 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
      * @param activate New cluster state.
      * @param resFut State change future.
      */
-    private void sendCompute(boolean activate, final GridFutureAdapter<Void> resFut) {
+    private void sendComputeChangeGlobalState(boolean activate, final GridFutureAdapter<Void> resFut) {
         AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
 
-        IgniteCompute comp = ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute();
-
         if (log.isInfoEnabled()) {
             log.info("Sending " + prettyStr(activate) + " request from node [id=" + ctx.localNodeId() +
                 ", topVer=" + topVer +
@@ -502,7 +504,9 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
                 ", daemon" + ctx.isDaemon() + "]");
         }
 
-        IgniteFuture<Void> fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate));
+        IgniteCompute comp = ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute();
+
+        IgniteFuture<Void> fut = comp.runAsync(new ChangeGlobalStateComputeRequest(activate));
 
         fut.listen(new CI1<IgniteFuture>() {
             @Override public void apply(IgniteFuture fut) {
@@ -519,6 +523,32 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
     }
 
     /**
+     *  Check cluster state.
+     *
+     *  @return Cluster state, {@code True} if cluster active, {@code False} if inactive.
+     */
+    private boolean sendComputeCheckGlobalState() {
+        AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
+
+        if (log.isInfoEnabled()) {
+            log.info("Sending check cluster state request from node [id=" + ctx.localNodeId() +
+                ", topVer=" + topVer +
+                ", client=" + ctx.clientNode() +
+                ", daemon" + ctx.isDaemon() + "]");
+        }
+        IgniteCompute comp = ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute();
+
+        return comp.call(new IgniteCallable<Boolean>() {
+            @IgniteInstanceResource
+            private Ignite ig;
+
+            @Override public Boolean call() throws Exception {
+                return ig.active();
+            }
+        });
+    }
+
+    /**
      * @param errs Errors.
      * @param req State change request.
      */
@@ -854,7 +884,7 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
     /**
      *
      */
-    private static class ClientChangeGlobalStateComputeRequest implements IgniteRunnable {
+    private static class ChangeGlobalStateComputeRequest implements IgniteRunnable {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -863,18 +893,34 @@ public class GridClusterStateProcessor extends GridProcessorAdapter {
 
         /** Ignite. */
         @IgniteInstanceResource
-        private Ignite ignite;
+        private Ignite ig;
 
         /**
          * @param activate New cluster state.
          */
-        private ClientChangeGlobalStateComputeRequest(boolean activate) {
+        private ChangeGlobalStateComputeRequest(boolean activate) {
             this.activate = activate;
         }
 
         /** {@inheritDoc} */
         @Override public void run() {
-            ignite.active(activate);
+            ig.active(activate);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class CheckGlobalStateComputeRequest implements IgniteCallable<Boolean> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Ignite. */
+        @IgniteInstanceResource
+        private Ignite ig;
+
+        @Override public Boolean call() throws Exception {
+            return ig.active();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/523c5e5d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java
index 30fff08..c2bece0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/IgniteStandByClusterTest.java
@@ -252,6 +252,36 @@ public class IgniteStandByClusterTest extends GridCommonAbstractTest {
     /**
      * @throws Exception if fail.
      */
+    public void testCheckStatusFromDaemon() throws Exception {
+        IgniteEx ig = startGrid(0);
+
+        assertFalse(ig.active());
+
+        ig.active(true);
+
+        IgniteEx daemon = startGrid(
+            getConfiguration("daemon")
+                .setDaemon(true)
+                .setClientMode(true)
+        );
+
+        assertTrue(ig.active());
+        assertTrue(daemon.active());
+
+        daemon.active(false);
+
+        assertFalse(ig.active());
+        assertFalse(daemon.active());
+
+        daemon.active(true);
+
+        assertTrue(ig.active());
+        assertTrue(daemon.active());
+    }
+
+    /**
+     * @throws Exception if fail.
+     */
     public void testRestartCluster() throws Exception {
         IgniteEx ig1 = startGrid(getConfiguration("node1"));
         IgniteEx ig2 = startGrid(getConfiguration("node2"));
@@ -298,25 +328,25 @@ public class IgniteStandByClusterTest extends GridCommonAbstractTest {
 
         ig1.active(true);
 
-        checkPlugin(ig1,1,0);
-        checkPlugin(ig2,1,0);
-        checkPlugin(ig3,1,0);
+        checkPlugin(ig1, 1, 0);
+        checkPlugin(ig2, 1, 0);
+        checkPlugin(ig3, 1, 0);
 
         ig2.active(false);
 
         ig3.active(true);
 
-        checkPlugin(ig1,2,1);
-        checkPlugin(ig2,2,1);
-        checkPlugin(ig3,2,1);
+        checkPlugin(ig1, 2, 1);
+        checkPlugin(ig2, 2, 1);
+        checkPlugin(ig3, 2, 1);
 
         ig1.active(false);
 
         ig2.active(true);
 
-        checkPlugin(ig1,3,2);
-        checkPlugin(ig2,3,2);
-        checkPlugin(ig3,3,2);
+        checkPlugin(ig1, 3, 2);
+        checkPlugin(ig2, 3, 2);
+        checkPlugin(ig3, 3, 2);
 
     }