-
Notifications
You must be signed in to change notification settings - Fork 25.5k
[ML] Gracefully shutdown model deployment when node is removed from assignment routing #134673
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
Merged
jonathan-buttner
merged 9 commits into
elastic:main
from
jonathan-buttner:ml-graceful-fix
Sep 25, 2025
+74
−16
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3812493
Initial fix for graceful shutdown for unreferenced nodes
jonathan-buttner 80ce591
Update docs/changelog/134673.yaml
jonathan-buttner 8f7d78f
[CI] Auto commit changes from spotless
f9349eb
Fixing cluster change test and flaky tests
jonathan-buttner 43a6066
Merge branch 'ml-graceful-fix' of github.com:jonathan-buttner/elastic…
jonathan-buttner 96f5496
[CI] Auto commit changes from spotless
3c0386d
Addressing feedback
jonathan-buttner 8cd6086
Merge branch 'main' of github.com:elastic/elasticsearch into ml-grace…
jonathan-buttner bb695e9
Merge branch 'main' into ml-graceful-fix
jonathan-buttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 134673 | ||
summary: Gracefully shutdown model deployment when node is removed from assignment | ||
routing | ||
area: Machine Learning | ||
type: bug | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,8 +380,7 @@ public void testClusterChangedWithResetMode() throws InterruptedException { | |
verifyNoMoreInteractions(deploymentManager, trainedModelAssignmentService); | ||
} | ||
|
||
public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNode_CallsStopAfterCompletingPendingWork() | ||
throws InterruptedException { | ||
public void testClusterChanged_WhenAssignmentIsRoutedToShuttingDownNode_CallsStopAfterCompletingPendingWork() throws Exception { | ||
final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); | ||
final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(DiscoveryNodeUtils.create(NODE_ID, NODE_ID)).build(); | ||
String modelOne = "model-1"; | ||
|
@@ -430,17 +429,19 @@ public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNode_CallsStop | |
fail("Failed waiting for the stop process call to complete"); | ||
} | ||
|
||
verify(deploymentManager, times(1)).stopAfterCompletingPendingWork(stopParamsCapture.capture()); | ||
assertThat(stopParamsCapture.getValue().getModelId(), equalTo(modelOne)); | ||
assertThat(stopParamsCapture.getValue().getDeploymentId(), equalTo(deploymentOne)); | ||
assertBusy(() -> { | ||
verify(deploymentManager, times(1)).stopAfterCompletingPendingWork(stopParamsCapture.capture()); | ||
assertThat(stopParamsCapture.getValue().getModelId(), equalTo(modelOne)); | ||
assertThat(stopParamsCapture.getValue().getDeploymentId(), equalTo(deploymentOne)); | ||
}); | ||
verify(trainedModelAssignmentService, times(1)).updateModelAssignmentState( | ||
any(UpdateTrainedModelAssignmentRoutingInfoAction.Request.class), | ||
any() | ||
); | ||
verifyNoMoreInteractions(deploymentManager, trainedModelAssignmentService); | ||
} | ||
|
||
public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNode_ButOtherAllocationIsNotReady_DoesNotCallStop() { | ||
public void testClusterChanged_WhenAssignmentIsRoutedToShuttingDownNode_ButOtherAllocationIsNotReady_DoesNotCallStop() { | ||
final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); | ||
String node2 = "test-node-2"; | ||
final DiscoveryNodes nodes = DiscoveryNodes.builder() | ||
|
@@ -488,7 +489,7 @@ public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNode_ButOtherA | |
verifyNoMoreInteractions(deploymentManager, trainedModelAssignmentService); | ||
} | ||
|
||
public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNodeButAlreadyRemoved_DoesNotCallStop() { | ||
public void testClusterChanged_WhenAssignmentIsRoutedToShuttingDownNodeButAlreadyRemoved_DoesNotCallStop() { | ||
final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); | ||
final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(DiscoveryNodeUtils.create(NODE_ID, NODE_ID)).build(); | ||
String modelOne = "model-1"; | ||
|
@@ -529,7 +530,7 @@ public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNodeButAlready | |
verifyNoMoreInteractions(deploymentManager, trainedModelAssignmentService); | ||
} | ||
|
||
public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNodeWithStartingState_DoesNotStopTheDeployment() { | ||
public void testClusterChanged_WhenAssignmentIsRoutedToShuttingDownNodeWithStartingState_DoesNotStopTheDeployment() { | ||
final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); | ||
final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(DiscoveryNodeUtils.create(NODE_ID, NODE_ID)).build(); | ||
String modelOne = "model-1"; | ||
|
@@ -571,7 +572,46 @@ public void testClusterChanged_WhenAssigmentIsRoutedToShuttingDownNodeWithStarti | |
verifyNoMoreInteractions(deploymentManager, trainedModelAssignmentService); | ||
} | ||
|
||
public void testClusterChanged_WhenAssigmentIsStopping_DoesNotAddModelToBeLoaded() throws InterruptedException { | ||
public void testClusterChanged_WhenNodeDoesNotExistInAssignmentRoutingTable_DoesGracefullyStopTheDeployment() throws Exception { | ||
final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); | ||
final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(DiscoveryNodeUtils.create(NODE_ID, NODE_ID)).build(); | ||
String modelOne = "model-1"; | ||
String deploymentOne = "deployment-1"; | ||
|
||
var taskParams = newParams(deploymentOne, modelOne); | ||
|
||
ClusterChangedEvent event = new ClusterChangedEvent( | ||
"testClusterChanged", | ||
ClusterState.builder(new ClusterName("testClusterChanged")) | ||
.nodes(nodes) | ||
.metadata( | ||
Metadata.builder() | ||
.putCustom( | ||
TrainedModelAssignmentMetadata.NAME, | ||
TrainedModelAssignmentMetadata.Builder.empty() | ||
.addNewAssignment(deploymentOne, TrainedModelAssignment.Builder.empty(taskParams, null)) | ||
.build() | ||
) | ||
.build() | ||
) | ||
.build(), | ||
ClusterState.EMPTY_STATE | ||
); | ||
|
||
trainedModelAssignmentNodeService.prepareModelToLoad(taskParams); | ||
trainedModelAssignmentNodeService.clusterChanged(event); | ||
|
||
assertBusy(() -> { verify(deploymentManager, times(1)).stopAfterCompletingPendingWork(any()); }); | ||
|
||
// This still shouldn't trigger a cluster state update because the routing entry wasn't in the table so we won't add a new routing | ||
// entry for stopping | ||
verify(trainedModelAssignmentService, never()).updateModelAssignmentState( | ||
any(UpdateTrainedModelAssignmentRoutingInfoAction.Request.class), | ||
any() | ||
); | ||
verifyNoMoreInteractions(deploymentManager, trainedModelAssignmentService); | ||
} | ||
|
||
public void testClusterChanged_WhenAssignmentIsStopping_DoesNotAddModelToBeLoaded() throws InterruptedException { | ||
final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); | ||
final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(DiscoveryNodeUtils.create(NODE_ID, NODE_ID)).build(); | ||
String modelOne = "model-1"; | ||
|
@@ -603,7 +643,6 @@ public void testClusterChanged_WhenAssigmentIsStopping_DoesNotAddModelToBeLoaded | |
ClusterState.EMPTY_STATE | ||
); | ||
|
||
// trainedModelAssignmentNodeService.prepareModelToLoad(taskParams); | ||
trainedModelAssignmentNodeService.clusterChanged(event); | ||
loadQueuedModels(trainedModelAssignmentNodeService); | ||
|
||
|
@@ -724,7 +763,9 @@ public void testClusterChanged() throws Exception { | |
|
||
assertBusy(() -> { | ||
ArgumentCaptor<TrainedModelDeploymentTask> stoppedTaskCapture = ArgumentCaptor.forClass(TrainedModelDeploymentTask.class); | ||
verify(deploymentManager, times(1)).stopDeployment(stoppedTaskCapture.capture()); | ||
// deployment-2 was originally started on node NODE_ID but in the latest cluster event it is no longer on that node so we will | ||
// gracefully stop it | ||
verify(deploymentManager, times(1)).stopAfterCompletingPendingWork(stoppedTaskCapture.capture()); | ||
assertThat(stoppedTaskCapture.getAllValues().get(0).getDeploymentId(), equalTo(deploymentTwo)); | ||
}); | ||
ArgumentCaptor<TrainedModelDeploymentTask> startTaskCapture = ArgumentCaptor.forClass(TrainedModelDeploymentTask.class); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "task does not exist"?