Skip to content

Commit 50450b5

Browse files
committed
polish code
1 parent 0348e74 commit 50450b5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AssignmentPlan.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,28 @@ private Quality computeQuality() {
314314
return new Quality(isSatisfyingPreviousAssignments, weighedAllocationsScore, memoryScore);
315315
}
316316

317-
public AssignmentPlan withDeploymentsWithZeroAllocations(Collection<Deployment> deploymentsWithZeroAllocations) {
317+
/**
318+
* Adds deployments with zero allocations to this plan. These deployments
319+
* are preserved in the plan but have no node assignments. This ensures
320+
* that deployments configured with zero allocations are not lost during
321+
* planning.
322+
*
323+
* Deployments with zero allocations are filtered out during the planning
324+
* process (since they don't require assignment), but they need to be preserved
325+
* in the final plan so that deployment state is maintained correctly.
326+
*
327+
* @param zeroAllocationDeployments deployments to add with empty assignments
328+
* @return a new plan containing the original assignments plus the zero-allocation deployments
329+
*/
330+
public AssignmentPlan withZeroAllocationDeployments(Collection<Deployment> zeroAllocationDeployments) {
318331
Map<Deployment, Map<Node, Integer>> newAssignments = new HashMap<>(assignments);
319-
for (Deployment deployment : deploymentsWithZeroAllocations) {
332+
Map<Deployment, Integer> newRemainingModelAllocations = new HashMap<>(remainingModelAllocations);
333+
for (Deployment deployment : zeroAllocationDeployments) {
334+
assert newAssignments.containsKey(deployment) == false;
320335
newAssignments.put(deployment, Collections.emptyMap());
336+
newRemainingModelAllocations.put(deployment, 0);
321337
}
322-
return new AssignmentPlan(newAssignments, remainingNodeMemory, remainingNodeCores, remainingModelAllocations);
338+
return new AssignmentPlan(newAssignments, remainingNodeMemory, remainingNodeCores, newRemainingModelAllocations);
323339
}
324340

325341
public String prettyPrint() {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AssignmentPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public AssignmentPlan computePlan(boolean tryAssigningAllPreviouslyAllocatedMode
105105
logger.debug(() -> "Best plan =\n" + bestPlan.prettyPrint());
106106
logger.debug(() -> prettyPrintOverallStats(bestPlan));
107107

108-
return bestPlan.withDeploymentsWithZeroAllocations(deploymentsWithZeroAllocations);
108+
return bestPlan.withZeroAllocationDeployments(deploymentsWithZeroAllocations);
109109
}
110110

111111
/**

0 commit comments

Comments
 (0)