Skip to content

Commit 1fe2705

Browse files
authored
Skip daily maintenance activity if upgrade mode is enabled (#54565) (#54571)
1 parent 1cff689 commit 1fe2705

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
1919
import org.elasticsearch.threadpool.Scheduler;
2020
import org.elasticsearch.threadpool.ThreadPool;
21+
import org.elasticsearch.xpack.core.ml.MlMetadata;
2122
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
2223

2324
import java.time.Clock;
@@ -123,6 +124,10 @@ private synchronized void scheduleNext() {
123124

124125
private void triggerTasks() {
125126
try {
127+
if (MlMetadata.getMlMetadata(clusterService.state()).isUpgradeMode()) {
128+
LOGGER.warn("skipping scheduled [ML] maintenance tasks because upgrade mode is enabled");
129+
return;
130+
}
126131
LOGGER.info("triggering scheduled [ML] maintenance tasks");
127132
executeAsyncWithOrigin(client, ML_ORIGIN, DeleteExpiredDataAction.INSTANCE, new DeleteExpiredDataAction.Request(),
128133
ActionListener.wrap(

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceServiceTests.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.test.ESTestCase;
1717
import org.elasticsearch.threadpool.TestThreadPool;
1818
import org.elasticsearch.threadpool.ThreadPool;
19+
import org.elasticsearch.xpack.core.ml.MlMetadata;
1920
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
2021
import org.junit.After;
2122
import org.junit.Before;
@@ -28,6 +29,8 @@
2829
import static org.mockito.Matchers.any;
2930
import static org.mockito.Matchers.same;
3031
import static org.mockito.Mockito.mock;
32+
import static org.mockito.Mockito.times;
33+
import static org.mockito.Mockito.verifyNoMoreInteractions;
3134
import static org.mockito.Mockito.when;
3235

3336
public class MlDailyMaintenanceServiceTests extends ESTestCase {
@@ -43,11 +46,6 @@ public void setUpTests() {
4346
client = mock(Client.class);
4447
when(client.threadPool()).thenReturn(threadPool);
4548
clusterService = mock(ClusterService.class);
46-
ClusterState state = ClusterState.builder(new ClusterName("MlDailyMaintenanceServiceTests"))
47-
.metadata(Metadata.builder().putCustom(PersistentTasksCustomMetadata.TYPE, PersistentTasksCustomMetadata.builder().build()))
48-
.nodes(DiscoveryNodes.builder().build())
49-
.build();
50-
when(clusterService.state()).thenReturn(state);
5149
mlAssignmentNotifier = mock(MlAssignmentNotifier.class);
5250
}
5351

@@ -57,6 +55,8 @@ public void stop() {
5755
}
5856

5957
public void testScheduledTriggering() throws InterruptedException {
58+
when(clusterService.state()).thenReturn(createClusterState(false));
59+
6060
int triggerCount = randomIntBetween(2, 4);
6161
CountDownLatch latch = new CountDownLatch(triggerCount);
6262
try (MlDailyMaintenanceService service = createService(latch, client)) {
@@ -68,10 +68,33 @@ public void testScheduledTriggering() throws InterruptedException {
6868
verify(mlAssignmentNotifier, Mockito.atLeast(triggerCount - 1)).auditUnassignedMlTasks(any(), any());
6969
}
7070

71+
public void testScheduledTriggeringWhileUpgradeModeIsEnabled() throws InterruptedException {
72+
when(clusterService.state()).thenReturn(createClusterState(true));
73+
74+
int triggerCount = randomIntBetween(2, 4);
75+
CountDownLatch latch = new CountDownLatch(triggerCount);
76+
try (MlDailyMaintenanceService service = createService(latch, client)) {
77+
service.start();
78+
latch.await(5, TimeUnit.SECONDS);
79+
}
80+
81+
verify(clusterService, times(triggerCount - 1)).state();
82+
verifyNoMoreInteractions(client, clusterService, mlAssignmentNotifier);
83+
}
84+
7185
private MlDailyMaintenanceService createService(CountDownLatch latch, Client client) {
7286
return new MlDailyMaintenanceService(threadPool, client, clusterService, mlAssignmentNotifier, () -> {
7387
latch.countDown();
7488
return TimeValue.timeValueMillis(100);
7589
});
7690
}
91+
92+
private static ClusterState createClusterState(boolean isUpgradeMode) {
93+
return ClusterState.builder(new ClusterName("MlDailyMaintenanceServiceTests"))
94+
.metadata(Metadata.builder()
95+
.putCustom(PersistentTasksCustomMetadata.TYPE, PersistentTasksCustomMetadata.builder().build())
96+
.putCustom(MlMetadata.TYPE, new MlMetadata.Builder().isUpgradeMode(isUpgradeMode).build()))
97+
.nodes(DiscoveryNodes.builder().build())
98+
.build();
99+
}
77100
}

0 commit comments

Comments
 (0)