Commit eac0cc3
[ML] Fix race condition between job open, close and kill (elastic#75113)
This is a followup to elastic#74976.
The changes of elastic#74976 reverted many of the changes of elastic#71656
because elastic#74415 made them redundant. elastic#74415 did this by making
killed jobs as closing so that the standard "job closed immediately
after open" functionality was used instead of reissuing the kill
immediately after opening. However, it turns out that this
"job closed immediately after open" functionality is not
perfect for the case of a job that is killed while it is opening.
It causes AutodetectCommunicator.close() to be called instead
of AutodetectCommunicator.killProcess(). Both do a lot of the
same things, but AutodetectCommunicator.close() finalizes
the job, and this can cause problems if the job is being killed
as part of a feature reset.
This change reinstates some of the functionality of elastic#71656
but in a different place that hopefully won't reintroduce the
problems that led to elastic#74415.
We can detect that a kill has happened early on during an
open or close operation by checking if the task's allocation
ID has been removed from the map after ProcessContext.setDying()
returns true. If ProcessContext.setDying() returns true this
means the job has not been previously closed, so it must have
been killed. Then we can call AutodetectCommunicator.killProcess()
instead of AutodetectCommunicator.close() during the cleanup
that happens when we detect that a recently started process is
no longer wanted.
Relates elastic#750691 parent 73bbc68 commit eac0cc3
File tree
1 file changed
+32
-9
lines changed- x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect
1 file changed
+32
-9
lines changedLines changed: 32 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
691 | | - | |
692 | 691 | | |
693 | 692 | | |
694 | 693 | | |
| |||
735 | 734 | | |
736 | 735 | | |
737 | 736 | | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
738 | 743 | | |
739 | 744 | | |
740 | 745 | | |
| |||
744 | 749 | | |
745 | 750 | | |
746 | 751 | | |
747 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
748 | 758 | | |
749 | 759 | | |
750 | 760 | | |
751 | 761 | | |
752 | 762 | | |
753 | 763 | | |
754 | 764 | | |
| 765 | + | |
| 766 | + | |
755 | 767 | | |
756 | 768 | | |
| 769 | + | |
757 | 770 | | |
758 | | - | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
759 | 780 | | |
760 | | - | |
761 | | - | |
762 | 781 | | |
763 | | - | |
| 782 | + | |
| 783 | + | |
764 | 784 | | |
765 | | - | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
766 | 788 | | |
767 | | - | |
| 789 | + | |
| 790 | + | |
768 | 791 | | |
769 | | - | |
| 792 | + | |
770 | 793 | | |
771 | 794 | | |
772 | 795 | | |
| |||
0 commit comments