Skip to content

Commit 16d4b91

Browse files
authored
Make TransportRetryAction project-aware (#129346)
Updates the ILM retry action to resolve the correct project. Running the async action currently isn't project-aware yet, but that will be handled when that action class is made project-aware.
1 parent 12521fb commit 16d4b91

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ public IndexLifecycleService(
131131
.addSettingsUpdateConsumer(LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING, this::updatePollInterval);
132132
}
133133

134-
public void maybeRunAsyncAction(ClusterState clusterState, IndexMetadata indexMetadata, StepKey nextStepKey) {
135-
final var state = clusterState.projectState();
134+
public void maybeRunAsyncAction(ProjectState state, IndexMetadata indexMetadata, StepKey nextStepKey) {
136135
lifecycleRunner.maybeRunAsyncAction(state, indexMetadata, indexMetadata.getLifecyclePolicyName(), nextStepKey);
137136
}
138137

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState)
177177
);
178178
return;
179179
}
180-
indexLifecycleService.maybeRunAsyncAction(newState, newIndexMetadata, concreteTargetKey.get());
180+
indexLifecycleService.maybeRunAsyncAction(newProjectState, newIndexMetadata, concreteTargetKey.get());
181181
}
182182
}
183183
);

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
1717
import org.elasticsearch.cluster.ClusterState;
1818
import org.elasticsearch.cluster.ClusterStateUpdateTask;
19+
import org.elasticsearch.cluster.ProjectState;
1920
import org.elasticsearch.cluster.block.ClusterBlockException;
2021
import org.elasticsearch.cluster.block.ClusterBlockLevel;
2122
import org.elasticsearch.cluster.metadata.IndexMetadata;
2223
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
24+
import org.elasticsearch.cluster.project.ProjectResolver;
2325
import org.elasticsearch.cluster.service.ClusterService;
2426
import org.elasticsearch.common.util.concurrent.EsExecutors;
2527
import org.elasticsearch.core.SuppressForbidden;
@@ -36,15 +38,17 @@ public class TransportRetryAction extends TransportMasterNodeAction<RetryActionR
3638

3739
private static final Logger logger = LogManager.getLogger(TransportRetryAction.class);
3840

39-
IndexLifecycleService indexLifecycleService;
41+
private final IndexLifecycleService indexLifecycleService;
42+
private final ProjectResolver projectResolver;
4043

4144
@Inject
4245
public TransportRetryAction(
4346
TransportService transportService,
4447
ClusterService clusterService,
4548
ThreadPool threadPool,
4649
ActionFilters actionFilters,
47-
IndexLifecycleService indexLifecycleService
50+
IndexLifecycleService indexLifecycleService,
51+
ProjectResolver projectResolver
4852
) {
4953
super(
5054
ILMActions.RETRY.name(),
@@ -57,6 +61,7 @@ public TransportRetryAction(
5761
EsExecutors.DIRECT_EXECUTOR_SERVICE
5862
);
5963
this.indexLifecycleService = indexLifecycleService;
64+
this.projectResolver = projectResolver;
6065
}
6166

6267
@Override
@@ -66,29 +71,30 @@ protected void masterOperation(
6671
ClusterState state,
6772
ActionListener<AcknowledgedResponse> listener
6873
) {
74+
final var projectState = projectResolver.getProjectState(state);
6975
if (request.requireError() == false) {
70-
maybeRunAsyncAction(state, request.indices());
76+
maybeRunAsyncAction(projectState, request.indices());
7177
listener.onResponse(AcknowledgedResponse.TRUE);
7278
return;
7379
}
7480
submitUnbatchedTask("ilm-re-run", new AckedClusterStateUpdateTask(request, listener) {
7581
@Override
7682
public ClusterState execute(ClusterState currentState) {
77-
final var project = state.metadata().getProject();
83+
final var project = state.metadata().getProject(projectState.projectId());
7884
final var updatedProject = indexLifecycleService.moveIndicesToPreviouslyFailedStep(project, request.indices());
7985
return ClusterState.builder(currentState).putProjectMetadata(updatedProject).build();
8086
}
8187

8288
@Override
8389
public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
84-
maybeRunAsyncAction(newState, request.indices());
90+
maybeRunAsyncAction(newState.projectState(projectState.projectId()), request.indices());
8591
}
8692
});
8793
}
8894

89-
private void maybeRunAsyncAction(ClusterState state, String[] indices) {
95+
private void maybeRunAsyncAction(ProjectState state, String[] indices) {
9096
for (String index : indices) {
91-
IndexMetadata idxMeta = state.metadata().getProject().index(index);
97+
IndexMetadata idxMeta = state.metadata().index(index);
9298
if (idxMeta == null) {
9399
// The index has somehow been deleted - there shouldn't be any opportunity for this to happen, but just in case.
94100
logger.debug("index [" + index + "] has been deleted, skipping async action check");

0 commit comments

Comments
 (0)