|
@@ -10,11 +10,7 @@ package org.elasticsearch.xpack.ilm.action;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.elasticsearch.action.ActionListener;
|
|
import org.elasticsearch.action.ActionListener;
|
|
-import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
|
-import org.elasticsearch.action.IndicesRequest;
|
|
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
-import org.elasticsearch.action.support.IndicesOptions;
|
|
|
|
-import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
|
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
|
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
|
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
|
|
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
|
|
@@ -25,24 +21,18 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
|
|
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
|
|
import org.elasticsearch.cluster.service.ClusterService;
|
|
import org.elasticsearch.cluster.service.ClusterService;
|
|
-import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
|
-import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
|
import org.elasticsearch.common.util.concurrent.EsExecutors;
|
|
import org.elasticsearch.common.util.concurrent.EsExecutors;
|
|
import org.elasticsearch.core.SuppressForbidden;
|
|
import org.elasticsearch.core.SuppressForbidden;
|
|
-import org.elasticsearch.core.TimeValue;
|
|
|
|
import org.elasticsearch.injection.guice.Inject;
|
|
import org.elasticsearch.injection.guice.Inject;
|
|
import org.elasticsearch.tasks.Task;
|
|
import org.elasticsearch.tasks.Task;
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
import org.elasticsearch.transport.TransportService;
|
|
import org.elasticsearch.transport.TransportService;
|
|
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
|
|
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
|
|
import org.elasticsearch.xpack.core.ilm.action.ILMActions;
|
|
import org.elasticsearch.xpack.core.ilm.action.ILMActions;
|
|
|
|
+import org.elasticsearch.xpack.core.ilm.action.RetryActionRequest;
|
|
import org.elasticsearch.xpack.ilm.IndexLifecycleService;
|
|
import org.elasticsearch.xpack.ilm.IndexLifecycleService;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-
|
|
|
|
-public class TransportRetryAction extends TransportMasterNodeAction<TransportRetryAction.Request, AcknowledgedResponse> {
|
|
|
|
|
|
+public class TransportRetryAction extends TransportMasterNodeAction<RetryActionRequest, AcknowledgedResponse> {
|
|
|
|
|
|
private static final Logger logger = LogManager.getLogger(TransportRetryAction.class);
|
|
private static final Logger logger = LogManager.getLogger(TransportRetryAction.class);
|
|
|
|
|
|
@@ -62,7 +52,7 @@ public class TransportRetryAction extends TransportMasterNodeAction<TransportRet
|
|
clusterService,
|
|
clusterService,
|
|
threadPool,
|
|
threadPool,
|
|
actionFilters,
|
|
actionFilters,
|
|
- Request::new,
|
|
|
|
|
|
+ RetryActionRequest::new,
|
|
AcknowledgedResponse::readFrom,
|
|
AcknowledgedResponse::readFrom,
|
|
EsExecutors.DIRECT_EXECUTOR_SERVICE
|
|
EsExecutors.DIRECT_EXECUTOR_SERVICE
|
|
);
|
|
);
|
|
@@ -70,7 +60,17 @@ public class TransportRetryAction extends TransportMasterNodeAction<TransportRet
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void masterOperation(Task task, Request request, ClusterState state, ActionListener<AcknowledgedResponse> listener) {
|
|
|
|
|
|
+ protected void masterOperation(
|
|
|
|
+ Task task,
|
|
|
|
+ RetryActionRequest request,
|
|
|
|
+ ClusterState state,
|
|
|
|
+ ActionListener<AcknowledgedResponse> listener
|
|
|
|
+ ) {
|
|
|
|
+ if (request.requireError() == false) {
|
|
|
|
+ maybeRunAsyncAction(state, request.indices());
|
|
|
|
+ listener.onResponse(AcknowledgedResponse.TRUE);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
submitUnbatchedTask("ilm-re-run", new AckedClusterStateUpdateTask(request, listener) {
|
|
submitUnbatchedTask("ilm-re-run", new AckedClusterStateUpdateTask(request, listener) {
|
|
@Override
|
|
@Override
|
|
public ClusterState execute(ClusterState currentState) {
|
|
public ClusterState execute(ClusterState currentState) {
|
|
@@ -79,101 +79,33 @@ public class TransportRetryAction extends TransportMasterNodeAction<TransportRet
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
|
|
public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
|
|
- for (String index : request.indices()) {
|
|
|
|
- IndexMetadata idxMeta = newState.metadata().getProject().index(index);
|
|
|
|
- LifecycleExecutionState lifecycleState = idxMeta.getLifecycleExecutionState();
|
|
|
|
- StepKey retryStep = new StepKey(lifecycleState.phase(), lifecycleState.action(), lifecycleState.step());
|
|
|
|
- if (idxMeta == null) {
|
|
|
|
- // The index has somehow been deleted - there shouldn't be any opportunity for this to happen, but just in case.
|
|
|
|
- logger.debug(
|
|
|
|
- "index ["
|
|
|
|
- + index
|
|
|
|
- + "] has been deleted after moving to step ["
|
|
|
|
- + lifecycleState.step()
|
|
|
|
- + "], skipping async action check"
|
|
|
|
- );
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- indexLifecycleService.maybeRunAsyncAction(newState, idxMeta, retryStep);
|
|
|
|
- }
|
|
|
|
|
|
+ maybeRunAsyncAction(newState, request.indices());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void maybeRunAsyncAction(ClusterState state, String[] indices) {
|
|
|
|
+ for (String index : indices) {
|
|
|
|
+ IndexMetadata idxMeta = state.metadata().getProject().index(index);
|
|
|
|
+ if (idxMeta == null) {
|
|
|
|
+ // The index has somehow been deleted - there shouldn't be any opportunity for this to happen, but just in case.
|
|
|
|
+ logger.debug("index [" + index + "] has been deleted, skipping async action check");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ LifecycleExecutionState lifecycleState = idxMeta.getLifecycleExecutionState();
|
|
|
|
+ StepKey retryStep = new StepKey(lifecycleState.phase(), lifecycleState.action(), lifecycleState.step());
|
|
|
|
+ indexLifecycleService.maybeRunAsyncAction(state, idxMeta, retryStep);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@SuppressForbidden(reason = "legacy usage of unbatched task") // TODO add support for batching here
|
|
@SuppressForbidden(reason = "legacy usage of unbatched task") // TODO add support for batching here
|
|
private void submitUnbatchedTask(@SuppressWarnings("SameParameterValue") String source, ClusterStateUpdateTask task) {
|
|
private void submitUnbatchedTask(@SuppressWarnings("SameParameterValue") String source, ClusterStateUpdateTask task) {
|
|
clusterService.submitUnbatchedStateUpdateTask(source, task);
|
|
clusterService.submitUnbatchedStateUpdateTask(source, task);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected ClusterBlockException checkBlock(Request request, ClusterState state) {
|
|
|
|
|
|
+ protected ClusterBlockException checkBlock(RetryActionRequest request, ClusterState state) {
|
|
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
|
|
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
|
|
}
|
|
}
|
|
|
|
|
|
- public static class Request extends AcknowledgedRequest<Request> implements IndicesRequest.Replaceable {
|
|
|
|
- private String[] indices;
|
|
|
|
- private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
|
|
|
|
-
|
|
|
|
- public Request(TimeValue masterNodeTimeout, TimeValue ackTimeout, String... indices) {
|
|
|
|
- super(masterNodeTimeout, ackTimeout);
|
|
|
|
- this.indices = indices;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Request(StreamInput in) throws IOException {
|
|
|
|
- super(in);
|
|
|
|
- this.indices = in.readStringArray();
|
|
|
|
- this.indicesOptions = IndicesOptions.readIndicesOptions(in);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Request indices(String... indices) {
|
|
|
|
- this.indices = indices;
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public String[] indices() {
|
|
|
|
- return indices;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public IndicesOptions indicesOptions() {
|
|
|
|
- return indicesOptions;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Request indicesOptions(IndicesOptions indicesOptions) {
|
|
|
|
- this.indicesOptions = indicesOptions;
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public ActionRequestValidationException validate() {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void writeTo(StreamOutput out) throws IOException {
|
|
|
|
- super.writeTo(out);
|
|
|
|
- out.writeStringArray(indices);
|
|
|
|
- indicesOptions.writeIndicesOptions(out);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public int hashCode() {
|
|
|
|
- return Objects.hash(Arrays.hashCode(indices), indicesOptions);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public boolean equals(Object obj) {
|
|
|
|
- if (obj == null) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- if (obj.getClass() != getClass()) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- Request other = (Request) obj;
|
|
|
|
- return Objects.deepEquals(indices, other.indices) && Objects.equals(indicesOptions, other.indicesOptions);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|