fix: reverse potentialVictims order to reprieve higher priority pods first#5214
fix: reverse potentialVictims order to reprieve higher priority pods first#5214dengaosong wants to merge 2 commits intovolcano-sh:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @dengaosong! It looks like this is your first PR to volcano-sh/volcano 🎉 |
There was a problem hiding this comment.
Code Review
This pull request refactors the preemption logic in pkg/scheduler/actions/preempt/preempt.go by removing the explicit sorting of all potential victims. Instead, it implements a manual reversal of the potentialVictims slice to maintain the correct priority order for reprieving pods, as the priority queue returns them in ascending order of priority. I have no feedback to provide.
There was a problem hiding this comment.
Pull request overview
Fixes victim reprieve ordering in SelectVictimsOnNode so that when attempting to add back (“reprieve”) potential victims, higher-priority pods are considered first (aligning behavior with the intended priority semantics described in #5208).
Changes:
- Removes the misleading/ineffective pre-sort of victims (and the associated
k8sutildependency). - Reverses
potentialVictimsprior to the reprieve loop so reprieve proceeds from higher → lower priority.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Reverse potentialVictims to reprieve higher priority pods first. | ||
| // potentialVictims is collected from victimsQueue.Pop() which returns lower priority first, | ||
| // so we need to reverse it to ensure higher priority pods are reprieved first. | ||
| for i, j := 0, len(potentialVictims)-1; i < j; i, j = i+1, j-1 { | ||
| potentialVictims[i], potentialVictims[j] = potentialVictims[j], potentialVictims[i] | ||
| } |
There was a problem hiding this comment.
The newly added reversal block is not gofmt-formatted (uses spaces instead of tabs and has inconsistent indentation vs the surrounding code). Please run gofmt (or adjust indentation) so the comment and for-loop align with the file’s standard formatting; this will also remove the trailing whitespace on the closing brace line.
| // Reverse potentialVictims to reprieve higher priority pods first. | |
| // potentialVictims is collected from victimsQueue.Pop() which returns lower priority first, | |
| // so we need to reverse it to ensure higher priority pods are reprieved first. | |
| for i, j := 0, len(potentialVictims)-1; i < j; i, j = i+1, j-1 { | |
| potentialVictims[i], potentialVictims[j] = potentialVictims[j], potentialVictims[i] | |
| } | |
| // Reverse potentialVictims to reprieve higher priority pods first. | |
| // potentialVictims is collected from victimsQueue.Pop() which returns lower priority first, | |
| // so we need to reverse it to ensure higher priority pods are reprieved first. | |
| for i, j := 0, len(potentialVictims)-1; i < j; i, j = i+1, j-1 { | |
| potentialVictims[i], potentialVictims[j] = potentialVictims[j], potentialVictims[i] | |
| } |
c61fe72 to
4698b3a
Compare
4698b3a to
f5f8495
Compare
|
/ok-to-test |
|
You are right, but please resolve the go fmt error please @dengaosong |
|
Also commits should not contain like |
0d3d33e to
3d4b6b3
Compare
3d4b6b3 to
3d934f1
Compare
…first In SelectVictimsOnNode, potentialVictims was collected from victimsQueue.Pop() which returns lower priority pods first. This caused lower priority pods to be reprieved first, contradicting the expected behavior. This fix reverses potentialVictims before the reprieve loop to ensure higher priority pods are reprieved first, as intended by the code comment. Signed-off-by: Deng Aosong <dengaosong@gamil.com> Signed-off-by: Deng Aosong <dengaosong@gmail.com>
Changed spaces to tabs for proper Go formatting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Deng Aosong <dengaosong@gmail.com>
3d934f1 to
fc6ce37
Compare
|
Hi, I have resolved the issues:
All checks are passing now. Please take another look when you get a chance. Thanks! |
What type of PR is this?
/kind bug
What this PR does / why we need it:
In
SelectVictimsOnNode,potentialVictimswas collected fromvictimsQueue.Pop()which returns lower priority pods first. This caused lower priority pods to be reprieved first, contradicting the expected behavior described in the code comment.This fix reverses
potentialVictimsbefore the reprieve loop to ensure higher priority pods are reprieved first.Which issue(s) this PR fixes:
Fixes #5208
Special notes for your reviewer:
The root cause is that
BuildVictimsPriorityQueueuses!ssn.TaskOrderFnwith negation, soPop()returns pods in [low→high] priority order, which is opposite to thesort.Sliceorder [high→low].Does this PR introduce a user-facing change?
None