Skip to content

Commit d25dd27

Browse files
committed
Make TransportRetryAction project-aware
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 4cda8c2 commit d25dd27

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 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,37 +71,38 @@ 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");
95101
return;
96102
}
97103
LifecycleExecutionState lifecycleState = idxMeta.getLifecycleExecutionState();
98104
StepKey retryStep = new StepKey(lifecycleState.phase(), lifecycleState.action(), lifecycleState.step());
99-
indexLifecycleService.maybeRunAsyncAction(state, idxMeta, retryStep);
105+
indexLifecycleService.maybeRunAsyncAction(state.cluster(), idxMeta, retryStep);
100106
}
101107
}
102108

0 commit comments

Comments
 (0)