Skip to content

Commit a8dda05

Browse files
author
David Roberts
committed
[ML] Reinstate ML daily maintenance actions (#47103)
A refactoring in 6.6 meant that the ML daily maintenance actions have not been run at all since then. This change installs the local master listener that schedules the ML daily maintenance, and also defends against some subtle race conditions that could occur in the future if a node flipped very quickly between master and non-master. Fixes #47003
1 parent cf4ba4f commit a8dda05

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ private static TimeValue delayToNextTime(ClusterName clusterName) {
7474
return TimeValue.timeValueMillis(next.getMillis() - now.getMillis());
7575
}
7676

77-
public void start() {
77+
public synchronized void start() {
7878
LOGGER.debug("Starting ML daily maintenance service");
7979
scheduleNext();
8080
}
8181

82-
public void stop() {
82+
public synchronized void stop() {
8383
LOGGER.debug("Stopping ML daily maintenance service");
8484
if (cancellable != null && cancellable.isCancelled() == false) {
8585
cancellable.cancel();
@@ -95,7 +95,7 @@ public void close() {
9595
stop();
9696
}
9797

98-
private void scheduleNext() {
98+
private synchronized void scheduleNext() {
9999
try {
100100
cancellable = threadPool.schedule(this::triggerTasks, schedulerProvider.get(), ThreadPool.Names.GENERIC);
101101
} catch (EsRejectedExecutionException e) {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlInitializationService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MlInitializationService implements LocalNodeMasterListener, ClusterStateLi
3939
this.clusterService = clusterService;
4040
this.client = client;
4141
clusterService.addListener(this);
42+
clusterService.addLocalNodeMasterListener(this);
4243
}
4344

4445
@Override
@@ -80,7 +81,7 @@ public String executorName() {
8081
return ThreadPool.Names.GENERIC;
8182
}
8283

83-
private void installDailyMaintenanceService() {
84+
private synchronized void installDailyMaintenanceService() {
8485
if (mlDailyMaintenanceService == null) {
8586
mlDailyMaintenanceService = new MlDailyMaintenanceService(clusterService.getClusterName(), threadPool, client);
8687
mlDailyMaintenanceService.start();
@@ -93,7 +94,7 @@ public void beforeStop() {
9394
}
9495
}
9596

96-
private void uninstallDailyMaintenanceService() {
97+
private synchronized void uninstallDailyMaintenanceService() {
9798
if (mlDailyMaintenanceService != null) {
9899
mlDailyMaintenanceService.stop();
99100
mlDailyMaintenanceService = null;
@@ -106,7 +107,7 @@ MlDailyMaintenanceService getDailyMaintenanceService() {
106107
}
107108

108109
/** For testing */
109-
void setDailyMaintenanceService(MlDailyMaintenanceService service) {
110+
synchronized void setDailyMaintenanceService(MlDailyMaintenanceService service) {
110111
mlDailyMaintenanceService = service;
111112
}
112113
}

0 commit comments

Comments
 (0)