OpenSearch/docs/reference/rollup/apis/delete-job.asciidoc
Zachary Tong 4dbf498721
[Rollup] Job deletion should be invoked on the allocated task (#34574)
We should delete a job by directly talking to the allocated 
task and telling it to shutdown. Today we shut down a job 
via the persistent task framework. This is not ideal because, 
while the job has been removed from the persistent task 
CS, the allocated task continues to live until it gets the 
shutdown message.

This means a user can delete a job, immediately delete 
the rollup index, and then see new documents appear in
 the just-deleted index. This happens because the indexer
 in the allocated task is still running and indexes a few 
more documents before getting the shutdown command.

In this PR, the transport action is changed to a TransportTasksAction, 
and we invoke onCancelled() directly on the matching job. 
The race condition still exists after this PR (albeit less likely), 
but this was a precursor to fixing the issue and a self-contained
chunk of code. A second PR will followup to fix the race itself.
2018-10-23 12:23:22 -04:00

114 lines
3.0 KiB
Plaintext

[role="xpack"]
[testenv="basic"]
[[rollup-delete-job]]
=== Delete Job API
++++
<titleabbrev>Delete Job</titleabbrev>
++++
experimental[]
This API deletes an existing rollup job. A job must be *stopped* first before it can be deleted. Attempting to delete
a started job will result in an error. Similarly, attempting to delete a nonexistent job will throw an exception.
.Deleting the job does not delete rolled up data
**********************************
When a job is deleted, that only removes the process that is actively monitoring and rolling up data.
It does not delete any previously rolled up data. This is by design; a user may wish to roll up a static dataset. Because
the dataset is static, once it has been fully rolled up there is no need to keep the indexing Rollup job around (as there
will be no new data). So the job may be deleted, leaving behind the rolled up data for analysis.
If you wish to also remove the rollup data, and the rollup index only contains the data for a single job, you can simply
delete the whole rollup index. If the rollup index stores data from several jobs, you must issue a Delete-By-Query that
targets the Rollup job's ID in the rollup index:
[source,js]
--------------------------------------------------
POST my_rollup_index/_delete_by_query
{
"query": {
"term": {
"_rollup.id": "the_rollup_job_id"
}
}
}
--------------------------------------------------
// NOTCONSOLE
**********************************
==== Request
`DELETE _xpack/rollup/job/<job_id>`
//===== Description
==== Path Parameters
`job_id` (required)::
(string) Identifier for the job
==== Request Body
There is no request body for the Delete Job API.
==== Authorization
You must have `manage` or `manage_rollup` cluster privileges to use this API.
For more information, see
{xpack-ref}/security-privileges.html[Security Privileges].
==== Examples
If we have a rollup job named `sensor`, it can be deleted with:
[source,js]
--------------------------------------------------
DELETE _xpack/rollup/job/sensor
--------------------------------------------------
// CONSOLE
// TEST[setup:sensor_rollup_job]
Which will return the response:
[source,js]
----
{
"acknowledged": true
}
----
// TESTRESPONSE
If however we try to delete a job which doesn't exist:
[source,js]
--------------------------------------------------
DELETE _xpack/rollup/job/does_not_exist
--------------------------------------------------
// CONSOLE
// TEST[catch:missing]
A 404 `resource_not_found` exception will be thrown:
[source,js]
----
{
"error" : {
"root_cause" : [
{
"type" : "resource_not_found_exception",
"reason" : "the task with id [does_not_exist] doesn't exist",
"stack_trace": ...
}
],
"type" : "resource_not_found_exception",
"reason" : "the task with id [does_not_exist] doesn't exist",
"stack_trace": ...
},
"status": 404
}
----
// TESTRESPONSE[s/"stack_trace": .../"stack_trace": $body.$_path/]