Skip to content

Commit f398265

Browse files
authored
Fix project lookup in ILM task executor (#129506)
Since #129366 we obtain a `ProjectState` by using the `Index` to look up the project from the cluster state. However, when an index is deleted, that statement fails. Since we have no guaranteed way of determining which project a deleted index was from, we need to explicitly pass the `ProjectID` in the `IndexLifecycleClusterStateUpdateTask`s. Incidentally, we have to make parts of the `IndexLifecycleService` and `IndexLifecycleRunner` project-aware - but they'll likely need a follow-up PR to finish them. Fixes #129489 Fixes #129490 Fixes #129491 Fixes #129510
1 parent d3d10c2 commit f398265

15 files changed

+245
-127
lines changed

muted-tests.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -547,21 +547,9 @@ tests:
547547
- class: org.elasticsearch.xpack.profiling.action.GetStatusActionIT
548548
method: testWaitsUntilResourcesAreCreated
549549
issue: https://github.com/elastic/elasticsearch/issues/129486
550-
- class: org.elasticsearch.xpack.ilm.TimeseriesMoveToStepIT
551-
method: testMoveToRolloverStep
552-
issue: https://github.com/elastic/elasticsearch/issues/129489
553-
- class: org.elasticsearch.xpack.ilm.TimeseriesMoveToStepIT
554-
method: testMoveToAllocateStep
555-
issue: https://github.com/elastic/elasticsearch/issues/129490
556-
- class: org.elasticsearch.xpack.ilm.actions.ShrinkActionIT
557-
method: testShrinkDuringSnapshot
558-
issue: https://github.com/elastic/elasticsearch/issues/129491
559550
- class: org.elasticsearch.xpack.security.PermissionsIT
560551
method: testWhenUserLimitedByOnlyAliasOfIndexCanWriteToIndexWhichWasRolledoverByILMPolicy
561552
issue: https://github.com/elastic/elasticsearch/issues/129481
562-
- class: org.elasticsearch.xpack.ilm.TimeSeriesLifecycleActionsIT
563-
method: testFullPolicy
564-
issue: https://github.com/elastic/elasticsearch/issues/129510
565553
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
566554
method: test {knn-function.KnnSearchWithKOption SYNC}
567555
issue: https://github.com/elastic/elasticsearch/issues/129512

x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,17 @@ public void testWaitInShrunkShardsAllocatedExceedsThreshold() throws Exception {
141141
clusterService.submitUnbatchedStateUpdateTask("testing-move-to-step-to-manipulate-step-time", new ClusterStateUpdateTask() {
142142
@Override
143143
public ClusterState execute(ClusterState currentState) throws Exception {
144+
final var projectState = currentState.projectState();
144145
return new MoveToNextStepUpdateTask(
146+
projectState.projectId(),
145147
managedIndexMetadata.getIndex(),
146148
policy,
147149
currentStepKey,
148150
currentStepKey,
149151
nowWayBackInThePastSupplier,
150152
indexLifecycleService.getPolicyRegistry(),
151153
state -> {}
152-
).execute(currentState.projectState());
154+
).execute(projectState);
153155
}
154156

155157
@Override

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTask.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.cluster.ProjectState;
1515
import org.elasticsearch.cluster.metadata.IndexMetadata;
1616
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
17+
import org.elasticsearch.cluster.metadata.ProjectId;
1718
import org.elasticsearch.common.Strings;
1819
import org.elasticsearch.index.Index;
1920
import org.elasticsearch.xcontent.ToXContentObject;
@@ -45,14 +46,15 @@ public class ExecuteStepsUpdateTask extends IndexLifecycleClusterStateUpdateTask
4546
private Exception failure = null;
4647

4748
public ExecuteStepsUpdateTask(
49+
ProjectId projectId,
4850
String policy,
4951
Index index,
5052
Step startStep,
5153
PolicyStepsRegistry policyStepsRegistry,
5254
IndexLifecycleRunner lifecycleRunner,
5355
LongSupplier nowSupplier
5456
) {
55-
super(index, startStep.getKey());
57+
super(projectId, index, startStep.getKey());
5658
this.policy = policy;
5759
this.startStep = startStep;
5860
this.policyStepsRegistry = policyStepsRegistry;
@@ -234,7 +236,7 @@ public void onClusterStateProcessed(ProjectState newState) {
234236
// After the cluster state has been processed and we have moved
235237
// to a new step, we need to conditionally execute the step iff
236238
// it is an `AsyncAction` so that it is executed exactly once.
237-
lifecycleRunner.maybeRunAsyncAction(newState.cluster(), indexMetadata, policy, nextStepKey);
239+
lifecycleRunner.maybeRunAsyncAction(newState, indexMetadata, policy, nextStepKey);
238240
}
239241
}
240242
assert indexToStepKeysForAsyncActions.size() <= 1 : "we expect a maximum of one single spawned index currently";
@@ -253,7 +255,7 @@ public void onClusterStateProcessed(ProjectState newState) {
253255
nextStep
254256
);
255257
final String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMeta.getSettings());
256-
lifecycleRunner.maybeRunAsyncAction(newState.cluster(), indexMeta, policyName, nextStep);
258+
lifecycleRunner.maybeRunAsyncAction(newState, indexMeta, policyName, nextStep);
257259
}
258260
}
259261
}

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.cluster.ClusterStateTaskListener;
1313
import org.elasticsearch.cluster.ClusterStateUpdateTask;
1414
import org.elasticsearch.cluster.ProjectState;
15+
import org.elasticsearch.cluster.metadata.ProjectId;
1516
import org.elasticsearch.common.util.concurrent.ListenableFuture;
1617
import org.elasticsearch.index.Index;
1718
import org.elasticsearch.xpack.core.ilm.Step;
@@ -24,11 +25,13 @@ public abstract class IndexLifecycleClusterStateUpdateTask implements ClusterSta
2425

2526
private final ListenableFuture<Void> listener = new ListenableFuture<>();
2627

28+
/** We need to store the project ID along with the index because an index might get deleted, but we still want to run the step */
29+
protected final ProjectId projectId;
2730
protected final Index index;
28-
2931
protected final Step.StepKey currentStepKey;
3032

31-
protected IndexLifecycleClusterStateUpdateTask(Index index, Step.StepKey currentStepKey) {
33+
protected IndexLifecycleClusterStateUpdateTask(ProjectId projectId, Index index, Step.StepKey currentStepKey) {
34+
this.projectId = projectId;
3235
this.index = index;
3336
this.currentStepKey = currentStepKey;
3437
}

0 commit comments

Comments
 (0)