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][Data Frame] adding force delete #44590

Merged
merged 2 commits into from
Jul 22, 2019

Conversation

benwtrent
Copy link
Member

Adds an optional boolean flag of force to DELETE. force=true allows for a data frame transform to be deleted no matter what its running state. Essentially, it adds a branch on if(forced) that will stop the data frame being deleted if it is running. Then, once it is stopped, it will be deleted.

closes #43961

@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core

@@ -141,6 +141,12 @@ teardown:
"pivot": {
"group_by": { "airline": {"terms": {"field": "airline"}}},
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
},
Copy link
Member Author

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`.
Copy link
Contributor

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));
Copy link
Contributor

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(
Copy link
Contributor

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:

  1. variable "deleteTransform" clearly describes what it does and is not tied to some other action's listener.
  2. no need to pass unused parameters to it
    WDYT?

Copy link
Member Author

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)

Copy link
Contributor

@przemekwitek przemekwitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@benwtrent benwtrent merged commit 40fccba into elastic:master Jul 22, 2019
@benwtrent benwtrent deleted the feature/ml-df-add-force-delete branch July 22, 2019 12:32
benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Jul 22, 2019
* [ML][Data Frame] adding force delete

* Update delete-transform.asciidoc
@lcawl
Copy link
Contributor

lcawl commented Jul 22, 2019

Documentation LGTM, thanks!

benwtrent added a commit that referenced this pull request Jul 22, 2019
* [ML][Data Frame] adding force delete (#44590)

* [ML][Data Frame] adding force delete

* Update delete-transform.asciidoc

* adjusting for backport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Allow force delete for a data frame transform
5 participants