-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ML][Data Frame] responding with 409 status code when failing _stop #44231
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
Changes from 1 commit
1b83d72
b960fd3
143e43e
7741bee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,21 @@ | |
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.discovery.MasterNotDiscoveredException; | ||
import org.elasticsearch.persistent.PersistentTasksCustomMetaData; | ||
import org.elasticsearch.persistent.PersistentTasksService; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.action.util.PageParams; | ||
import org.elasticsearch.xpack.core.dataframe.action.StopDataFrameTransformAction; | ||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState; | ||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState; | ||
import org.elasticsearch.xpack.dataframe.persistence.DataFrameInternalIndex; | ||
import org.elasticsearch.xpack.dataframe.persistence.DataFrameTransformsConfigManager; | ||
import org.elasticsearch.xpack.dataframe.transforms.DataFrameTransformTask; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
@@ -88,8 +91,31 @@ protected void doExecute(Task task, StopDataFrameTransformAction.Request request | |
new PageParams(0, 10_000), | ||
request.isAllowNoMatch(), | ||
ActionListener.wrap(hitsAndIds -> { | ||
if (request.isForce() == false) { | ||
PersistentTasksCustomMetaData tasks = state.metaData().custom(PersistentTasksCustomMetaData.TYPE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is the main change. If you really want to test this code extract it to a static method and it is easily unit testable. |
||
List<String> failedTasks = new ArrayList<>(); | ||
List<String> failedReasons = new ArrayList<>(); | ||
for (String transformId : hitsAndIds.v2()) { | ||
PersistentTasksCustomMetaData.PersistentTask<?> dfTask = tasks.getTask(transformId); | ||
if (dfTask.getState() instanceof DataFrameTransformState | ||
benwtrent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&& ((DataFrameTransformState) dfTask.getState()).getTaskState() == DataFrameTransformTaskState.FAILED) { | ||
failedTasks.add(transformId); | ||
failedReasons.add(((DataFrameTransformState) dfTask.getState()).getReason()); | ||
} | ||
} | ||
if (failedTasks.isEmpty() == false) { | ||
String msg = failedTasks.size() == 1 ? | ||
"Unable to stop data frame transform [" + request.getId() | ||
benwtrent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
+ "] as it is in a failed state with reason [" + failedReasons.get(0) | ||
+ "]. Use force stop to stop the data frame transform." : | ||
"Unable to stop data frame transforms. The following transforms are in a failed state " + | ||
failedTasks + " with reasons " + failedReasons + ". Use force stop to stop the data frame transforms."; | ||
listener.onFailure(new ElasticsearchStatusException(msg, RestStatus.CONFLICT)); | ||
return; | ||
} | ||
} | ||
request.setExpandedIds(new HashSet<>(hitsAndIds.v2())); | ||
request.setNodes(DataFrameNodes.dataFrameTaskNodes(hitsAndIds.v2(), clusterService.state())); | ||
request.setNodes(DataFrameNodes.dataFrameTaskNodes(hitsAndIds.v2(), state)); | ||
super.doExecute(task, request, finalListener); | ||
}, | ||
listener::onFailure | ||
|
@@ -108,6 +134,8 @@ protected void taskOperation(StopDataFrameTransformAction.Request request, DataF | |
} | ||
|
||
if (ids.contains(transformTask.getTransformId())) { | ||
// This should not occur as we validate that none of the tasks are in a failed state earlier | ||
// Keep this check in here for insurance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if (transformTask.getState().getTaskState() == DataFrameTransformTaskState.FAILED && request.isForce() == false) { | ||
listener.onFailure( | ||
new ElasticsearchStatusException("Unable to stop data frame transform [" + request.getId() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Set frequency high" - DYM low? The default is 60s, so 1s is lower?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High frequency => low time between repeats
(Similar to high frequency => short wavelength)
But if it's confusing then maybe bypass this by changing the comment to something like
// Set frequency to 1s to make the test run as fast as possible
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of those pedantic things that annoy me; frequency is measured in Hz not seconds, this is an interval. However, most people will read this and understand that frequency represents the period here and is probably the least confusing naming option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A high frequency in Hz means a short distance between cycles.
A high frequency here means a short time between attempts.