From 8e8a65aae5dec8462189f4a66f85799470a84ff9 Mon Sep 17 00:00:00 2001 From: Dimitris Athanasiou Date: Mon, 9 Sep 2019 17:39:49 +0300 Subject: [PATCH] [ML] No error when datafeed stops during updating to started Investigating the test failure reported in #45518 it appears that the datafeed task was not found during a tast state update. There are only two places where such an update is performed: when we set the state to `started` and when we set it to `stopping`. We handle `ResourceNotFoundException` in the latter but not in the former. Thus the test reveals a rare race condition where the datafeed gets requested to stop before we managed to update its state to `started`. I could not reproduce this scenario but it would be my best guess. This commit catches `ResourceNotFoundException` while updating the state to `started` and lets the task terminate smoothly. Closes #45518 --- .../elasticsearch/xpack/ml/datafeed/DatafeedManager.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java index a60797562d035..457701740e0f6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterChangedEvent; @@ -95,7 +96,12 @@ public void onResponse(PersistentTask persistentTask) { @Override public void onFailure(Exception e) { - finishHandler.accept(e); + if (e instanceof ResourceNotFoundException) { + // The task was stopped in the meantime, no need to do anything + logger.info("[{}] Aborting as datafeed has been stopped", datafeedId); + } else { + finishHandler.accept(e); + } } }); }, finishHandler::accept