Skip to content

[ML][Data Frame] adding force delete#44590

Merged
benwtrent merged 2 commits intoelastic:masterfrom
benwtrent:feature/ml-df-add-force-delete
Jul 22, 2019
Merged

[ML][Data Frame] adding force delete#44590
benwtrent merged 2 commits intoelastic:masterfrom
benwtrent:feature/ml-df-add-force-delete

Conversation

@benwtrent
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Pinging @elastic/ml-core

"pivot": {
"group_by": { "airline": {"terms": {"field": "airline"}}},
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
},
Copy link
Copy Markdown
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
Copy Markdown

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."

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

@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
Copy Markdown
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