You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2022/06/28 08:30:53 UTC
[ignite] branch master updated: IGNITE-17243 Fix durable background task start on node, joined after the activation - Fixes #10113.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new bf54c1b31b7 IGNITE-17243 Fix durable background task start on node, joined after the activation - Fixes #10113.
bf54c1b31b7 is described below
commit bf54c1b31b77068cd318b64fc953f872029c4a22
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Tue Jun 28 13:29:19 2022 +0500
IGNITE-17243 Fix durable background task start on node, joined after the activation - Fixes #10113.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
.../localtask/DurableBackgroundTasksProcessor.java | 42 +++++++++++++---------
.../DurableBackgroundTasksProcessorSelfTest.java | 34 ++++++++++++++++++
2 files changed, 60 insertions(+), 16 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessor.java
index 0561e2701d2..f0adc18c832 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessor.java
@@ -23,7 +23,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
-import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
@@ -231,7 +230,7 @@ public class DurableBackgroundTasksProcessor extends GridProcessorAdapter implem
* @param msg Message for change cluster global state.
*/
public void onStateChangeStarted(ChangeGlobalStateMessage msg) {
- if (msg.state() == ClusterState.INACTIVE)
+ if (!msg.state().active())
cancelTasks();
}
@@ -241,19 +240,14 @@ public class DurableBackgroundTasksProcessor extends GridProcessorAdapter implem
* @param msg Finish message for change cluster global state.
*/
public void onStateChangeFinish(ChangeGlobalStateFinishMessage msg) {
- if (msg.state() != ClusterState.INACTIVE) {
- cancelLock.writeLock().lock();
-
- try {
- prohibitionExecTasks = false;
+ if (msg.state().active())
+ activateTasks();
+ }
- for (DurableBackgroundTaskState<?> taskState : tasks.values())
- executeAsync0(taskState.task());
- }
- finally {
- cancelLock.writeLock().unlock();
- }
- }
+ /** {@inheritDoc} */
+ @Override public void onKernalStart(boolean active) throws IgniteCheckedException {
+ if (active)
+ activateTasks();
}
/**
@@ -380,8 +374,7 @@ public class DurableBackgroundTasksProcessor extends GridProcessorAdapter implem
}
/**
- * Canceling tasks.
- * Prohibiting the execution of tasks.
+ * Prohibit the execution of tasks and cancel tasks.
*/
private void cancelTasks() {
cancelLock.writeLock().lock();
@@ -397,6 +390,23 @@ public class DurableBackgroundTasksProcessor extends GridProcessorAdapter implem
}
}
+ /**
+ * Allow the execution of tasks and activate tasks.
+ */
+ private void activateTasks() {
+ cancelLock.writeLock().lock();
+
+ try {
+ prohibitionExecTasks = false;
+
+ for (DurableBackgroundTaskState<?> taskState : tasks.values())
+ executeAsync0(taskState.task());
+ }
+ finally {
+ cancelLock.writeLock().unlock();
+ }
+ }
+
/**
* Performing an operation on a {@link MetaStorage}.
* Guarded by {@link #metaStorageMux}.
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessorSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessorSelfTest.java
index f5cc13de0b2..8c1df0ee6a5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessorSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/localtask/DurableBackgroundTasksProcessorSelfTest.java
@@ -145,6 +145,40 @@ public class DurableBackgroundTasksProcessorSelfTest extends GridCommonAbstractT
execAsyncFut.get(getTestTimeout());
}
+ /**
+ * Check that the task can be started on the node if it joined after the cluster activation.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testTaskStartOnNodeJoinedAfterActivation() throws Exception {
+ IgniteEx n = startGrid(0);
+ startGrid(1);
+
+ n.cluster().state(ACTIVE);
+
+ stopGrid(1);
+ n = startGrid(1);
+
+ SimpleTask t = new SimpleTask("t");
+ execAsync(n, t, true);
+
+ t.onExecFut.get(getTestTimeout());
+ checkStateAndMetaStorage(n, t, STARTED, true, false);
+
+ stopGrid(1);
+ n = startGrid(1);
+
+ checkStateAndMetaStorage(n, t, STARTED, true, false);
+
+ n.cluster().state(INACTIVE);
+
+ stopGrid(1);
+ n = startGrid(1);
+
+ checkStateAndMetaStorage(n, t, INIT, true, false);
+ }
+
/**
* Check that the task will be restarted after restarting the node.
*