-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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][Data Frame] adding force delete #44590
[ML][Data Frame] adding force delete #44590
Conversation
Pinging @elastic/ml-core |
@@ -141,6 +141,12 @@ teardown: | |||
"pivot": { | |||
"group_by": { "airline": {"terms": {"field": "airline"}}}, | |||
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}} | |||
}, |
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.
I changed this config on purpose. I noticed while writing the yaml
test for this PR, that this particular test was saying that its transform was continuous, but it actually wasn't. So, I just fixed it.
`force`:: | ||
(Optional, boolean) When `true`, the {dataframe-transform} is deleted regardless of its | ||
current state. The default value is `false`, meaning that the {dataframe-transform} must be | ||
`stopped`. |
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.
Maybe extend the last sentence to: "...must be stopped
before it can be deleted."
if (pTasksMeta != null && pTasksMeta.getTask(request.getId()) != null) { | ||
ActionListener<AcknowledgedResponse> listener) { | ||
final PersistentTasksCustomMetaData pTasksMeta = state.getMetaData().custom(PersistentTasksCustomMetaData.TYPE); | ||
if (pTasksMeta != null && pTasksMeta.getTask(request.getId()) != null && request.isForce() == false) { | ||
listener.onFailure(new ElasticsearchStatusException("Cannot delete data frame [" + request.getId() + | ||
"] as the task is running. Stop the task first", RestStatus.CONFLICT)); |
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.
Adding "return;" after this line and getting rid of the "else" branch in line 72 would benefit readability IMO.
listener.onResponse(new AcknowledgedResponse(r)); | ||
}, | ||
listener::onFailure)); | ||
ActionListener<Void> stopTransformActionListener = ActionListener.wrap( |
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.
[optional] IMO more readable code could be achieved by:
CheckedRunnable deleteTransform = () -> transformsConfigManager.deleteTransform(..., ...);
if (pTasksMeta != null && pTasksMeta.getTask(request.getId()) != null) {
executeAsyncWithOrigin(
...,
ActionListener.wrap(r -> deleteTransform.run(), listener::onFailure));
} else {
deleteTransform.run();
}
I see 2 advantages here:
- variable "deleteTransform" clearly describes what it does and is not tied to some other action's listener.
- no need to pass unused parameters to it
WDYT?
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.
I prefer to try and keep callbacks uniformed. Our callback stacks can get very complicated and to me its just easier to reason about if they are ActionListener
+ and always within the flow (if 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.
LGTM
* [ML][Data Frame] adding force delete * Update delete-transform.asciidoc
Documentation LGTM, thanks! |
Adds an optional boolean flag of
force
toDELETE
.force=true
allows for a data frame transform to be deleted no matter what its running state. Essentially, it adds a branch onif(forced)
that will stop the data frame being deleted if it is running. Then, once it is stopped, it will be deleted.closes #43961