Skip to content

Commit 44b0047

Browse files
authored
Don't stop checking if the HealthNode persistent task is present (#105449)
We assumed that once the `HealthNode` persistent task is registered, we won't need to register it again. However, when, for instance, we restore from a snapshot (including cluster state) that was created in version <= 8.4.3, that task doesn't exist yet, which will result in the task being removed after the restore. By keeping the listener active, we will re-add the task after such a restore (or any other potential situation where the task might get deleted).
1 parent cca2627 commit 44b0047

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

docs/changelog/105449.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 105449
2+
summary: Don't stop checking if the `HealthNode` persistent task is present
3+
area: Health
4+
type: bug
5+
issues:
6+
- 98926

server/src/main/java/org/elasticsearch/health/node/selection/HealthNodeTaskExecutor.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ void startTask(ClusterChangedEvent event) {
159159
if (event.state().clusterRecovered() && featureService.clusterHasFeature(event.state(), HealthFeatures.SUPPORTS_HEALTH)) {
160160
boolean healthNodeTaskExists = HealthNode.findTask(event.state()) != null;
161161
boolean isElectedMaster = event.localNodeMaster();
162-
if (isElectedMaster || healthNodeTaskExists) {
163-
clusterService.removeListener(taskStarter);
164-
}
165162
if (isElectedMaster && healthNodeTaskExists == false) {
166163
persistentTasksService.sendStartRequest(
167164
TASK_NAME,

server/src/test/java/org/elasticsearch/health/node/LocalHealthMonitorTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.health.HealthFeatures;
2828
import org.elasticsearch.health.HealthStatus;
2929
import org.elasticsearch.health.metadata.HealthMetadata;
30-
import org.elasticsearch.health.node.selection.HealthNodeExecutorTests;
3130
import org.elasticsearch.health.node.tracker.HealthTracker;
3231
import org.elasticsearch.test.ESTestCase;
3332
import org.elasticsearch.threadpool.TestThreadPool;
@@ -63,7 +62,7 @@ public class LocalHealthMonitorTests extends ESTestCase {
6362

6463
@BeforeClass
6564
public static void setUpThreadPool() {
66-
threadPool = new TestThreadPool(HealthNodeExecutorTests.class.getSimpleName());
65+
threadPool = new TestThreadPool(LocalHealthMonitorTests.class.getSimpleName());
6766
}
6867

6968
@AfterClass

server/src/test/java/org/elasticsearch/health/node/selection/HealthNodeExecutorTests.java renamed to server/src/test/java/org/elasticsearch/health/node/selection/HealthNodeTaskExecutorTests.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.health.node.selection;
1010

11+
import org.elasticsearch.action.ActionListener;
1112
import org.elasticsearch.cluster.ClusterChangedEvent;
1213
import org.elasticsearch.cluster.ClusterName;
1314
import org.elasticsearch.cluster.ClusterState;
@@ -46,7 +47,7 @@
4647
import static org.mockito.Mockito.times;
4748
import static org.mockito.Mockito.verify;
4849

49-
public class HealthNodeExecutorTests extends ESTestCase {
50+
public class HealthNodeTaskExecutorTests extends ESTestCase {
5051

5152
/** Needed by {@link ClusterService} **/
5253
private static ThreadPool threadPool;
@@ -66,7 +67,7 @@ public class HealthNodeExecutorTests extends ESTestCase {
6667

6768
@BeforeClass
6869
public static void setUpThreadPool() {
69-
threadPool = new TestThreadPool(HealthNodeExecutorTests.class.getSimpleName());
70+
threadPool = new TestThreadPool(HealthNodeTaskExecutorTests.class.getSimpleName());
7071
}
7172

7273
@Before
@@ -91,20 +92,18 @@ public void tearDown() throws Exception {
9192
clusterService.close();
9293
}
9394

94-
public void testTaskCreation() {
95-
HealthNodeTaskExecutor executor = HealthNodeTaskExecutor.create(
96-
clusterService,
97-
persistentTasksService,
98-
featureService,
99-
settings,
100-
clusterSettings
101-
);
102-
executor.startTask(new ClusterChangedEvent("", initialState(), ClusterState.EMPTY_STATE));
103-
verify(persistentTasksService, times(1)).sendStartRequest(
104-
eq("health-node"),
105-
eq("health-node"),
106-
eq(new HealthNodeTaskParams()),
107-
any()
95+
public void testTaskCreation() throws Exception {
96+
HealthNodeTaskExecutor.create(clusterService, persistentTasksService, featureService, settings, clusterSettings);
97+
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, ActionListener.noop());
98+
// Ensure that if the task is gone, it will be recreated.
99+
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, ActionListener.noop());
100+
assertBusy(
101+
() -> verify(persistentTasksService, times(2)).sendStartRequest(
102+
eq("health-node"),
103+
eq("health-node"),
104+
eq(new HealthNodeTaskParams()),
105+
any()
106+
)
108107
);
109108
}
110109

0 commit comments

Comments
 (0)