Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Fix simultaneous stop and force stop datafeed #49367

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.AtomicArray;
Expand Down Expand Up @@ -259,17 +258,18 @@ protected void taskOperation(StopDatafeedAction.Request request, TransportStartD
threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME).execute(new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
if ((e instanceof ResourceNotFoundException &&
Strings.isAllOrWildcard(new String[]{request.getDatafeedId()}))) {
datafeedTask.stop("stop_datafeed (api)", request.getStopTimeout());
// We validated that the datafeed names supplied in the request existed when we started processing the action.
// If the related task for one of them doesn't exist at this point then it must have been removed by a
// simultaneous force stop request. This is not an error.
if (ExceptionsHelper.unwrapCause(e) instanceof ResourceNotFoundException) {
listener.onResponse(new StopDatafeedAction.Response(true));
} else {
listener.onFailure(e);
}
}

@Override
protected void doRun() throws Exception {
protected void doRun() {
datafeedTask.stop("stop_datafeed (api)", request.getStopTimeout());
listener.onResponse(new StopDatafeedAction.Response(true));
}
Expand Down Expand Up @@ -343,7 +343,7 @@ protected StopDatafeedAction.Response newResponse(StopDatafeedAction.Request req
throw org.elasticsearch.ExceptionsHelper
.convertToElastic(failedNodeExceptions.get(0));
} else {
// This can happen we the actual task in the node no longer exists,
// This can happen when the actual task in the node no longer exists,
// which means the datafeed(s) have already been stopped.
return new StopDatafeedAction.Response(true);
}
Expand Down