[ML] Reject put datafeed for job that is marked as deleted (elastic/x-pack-elasticsearch#1537)

Deleting a job issues 2 cluster state updates.
The first marks the job as deleted.
The second actually removes the job.
Both check that there is no datafeed referring to the job.
If a put datafeed request arrives between those 2 cluster
state updates, the datafeed gets created and the final
job cluster state update fails. This means we end up with
both the job and the datafeed, but the job's results and
state have been deleted.

This commit changes the behaviour so that the put
datafeed request fails for a job that is marked as deleted
as this scenario is avoiding partially executing an action.

relates elastic/x-pack-elasticsearch#1510 

Original commit: elastic/x-pack-elasticsearch@76fa0f0b1a
This commit is contained in:
Dimitris Athanasiou 2017-05-24 18:34:03 +01:00 committed by GitHub
parent ccf3fa2579
commit d7e528f7f7
2 changed files with 10 additions and 1 deletions

View File

@ -276,7 +276,7 @@ public class MlMetadata implements MetaData.Custom {
private void checkJobIsAvailableForDatafeed(String jobId) { private void checkJobIsAvailableForDatafeed(String jobId) {
Job job = jobs.get(jobId); Job job = jobs.get(jobId);
if (job == null) { if (job == null || job.isDeleted()) {
throw ExceptionsHelper.missingJobException(jobId); throw ExceptionsHelper.missingJobException(jobId);
} }
Optional<DatafeedConfig> existingDatafeed = getDatafeedByJobId(jobId); Optional<DatafeedConfig> existingDatafeed = getDatafeedByJobId(jobId);

View File

@ -203,6 +203,15 @@ public class MlMetadataTests extends AbstractSerializingTestCase<MlMetadata> {
expectThrows(ResourceNotFoundException.class, () -> builder.putDatafeed(datafeedConfig1)); expectThrows(ResourceNotFoundException.class, () -> builder.putDatafeed(datafeedConfig1));
} }
public void testPutDatafeed_failBecauseJobIsBeingDeleted() {
Job job1 = createDatafeedJob().setDeleted(true).build(new Date());
DatafeedConfig datafeedConfig1 = createDatafeedConfig("datafeed1", job1.getId()).build();
MlMetadata.Builder builder = new MlMetadata.Builder();
builder.putJob(job1, false);
expectThrows(ResourceNotFoundException.class, () -> builder.putDatafeed(datafeedConfig1));
}
public void testPutDatafeed_failBecauseDatafeedIdIsAlreadyTaken() { public void testPutDatafeed_failBecauseDatafeedIdIsAlreadyTaken() {
Job job1 = createDatafeedJob().build(new Date()); Job job1 = createDatafeedJob().build(new Date());
DatafeedConfig datafeedConfig1 = createDatafeedConfig("datafeed1", job1.getId()).build(); DatafeedConfig datafeedConfig1 = createDatafeedConfig("datafeed1", job1.getId()).build();