This is an automated email from the ASF dual-hosted git repository.
manirajv06 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new 8bb5250e [YUNIKORN-3445] Fix victim selection polarity in
SortAllocationsBasedOnAsk (#1153)
8bb5250e is described below
commit 8bb5250e2b794fadcd4a7afba50a0727e064fcdc
Author: PoiBlackTea <[email protected]>
AuthorDate: Thu Sep 10 21:18:19 2026 +0530
[YUNIKORN-3445] Fix victim selection polarity in SortAllocationsBasedOnAsk
(#1153)
Correct scoring polarity so unprotected allocations are prioritized for
preemption over opted-out and originator allocations. Add unit tests.
Closes: #1153
Signed-off-by: mani <[email protected]>
---
pkg/scheduler/objects/preemption_utilities.go | 18 ++++++++++------
pkg/scheduler/objects/preemption_utilities_test.go | 25 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/pkg/scheduler/objects/preemption_utilities.go
b/pkg/scheduler/objects/preemption_utilities.go
index 660102c6..cfd4d421 100644
--- a/pkg/scheduler/objects/preemption_utilities.go
+++ b/pkg/scheduler/objects/preemption_utilities.go
@@ -25,6 +25,11 @@ import (
"github.com/apache/yunikorn-core/pkg/common/resources"
)
+var (
+ scoreNonOriginator uint64 = 1 << 34
+ scoreAllowPreempt uint64 = 1 << 33
+)
+
// SortAllocations Sort allocations based on the following criteria in the
specified order:
// 1. By type (regular pods, opted out pods, driver/owner pods),
// 2. By priority (least priority ask placed first),
@@ -123,16 +128,15 @@ func SortAllocationsBasedOnAsk(allocations []*Allocation,
total, ask *resources.
})
}
-// scoreAllocation generates a relative score for an allocation. Lower-scored
allocations are considered more likely
-// preemption candidates. Tasks which have opted into preemption are
considered first, then tasks which are not
-// application originators.
+// scoreAllocationBasedOnAsk generates a relative score for an allocation
based on ask. Higher-scored allocations are considered more likely
+// preemption candidates. Opted out pods are considered before originator pods.
func scoreAllocationBasedOnAsk(allocation *Allocation, ask
*resources.Resource) uint64 {
var score uint64 = 0
- if allocation.IsOriginator() {
- score |= scoreOriginator
+ if !allocation.IsOriginator() {
+ score |= scoreNonOriginator
}
- if !allocation.IsAllowPreemptSelf() {
- score |= scoreNoPreempt
+ if allocation.IsAllowPreemptSelf() {
+ score |= scoreAllowPreempt
}
score += allocation.GetAllocatedResource().TypeMatching(ask)
return score
diff --git a/pkg/scheduler/objects/preemption_utilities_test.go
b/pkg/scheduler/objects/preemption_utilities_test.go
index 37e3f539..3f549d05 100644
--- a/pkg/scheduler/objects/preemption_utilities_test.go
+++ b/pkg/scheduler/objects/preemption_utilities_test.go
@@ -295,3 +295,28 @@ func TestSortAllocationsBasedOnAsk(t *testing.T) {
})
}
}
+
+func TestSortAllocationsBasedOnAsk_PreemptionOrdering(t *testing.T) {
+ node := NewNode(&si.NodeInfo{
+ NodeID: "node1",
+ SchedulableResource: &si.Resource{
+ Resources: map[string]*si.Quantity{"first": {Value:
100}},
+ },
+ })
+ res :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
+ total :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 100})
+ ask :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
+
+ regularPod := createAllocation("regularPod", "app1", node.NodeID, true,
false, 10, false, res)
+ originatorPod := createAllocation("originatorPod", "app1", node.NodeID,
true, true, 10, false, res)
+ optedOutPod := createAllocation("optedOutPod", "app1", node.NodeID,
false, false, 10, false, res)
+ optedOutOriginatorPod := createAllocation("optedOutOriginatorPod",
"app1", node.NodeID, false, true, 10, false, res)
+
+ allocations := []*Allocation{optedOutOriginatorPod, optedOutPod,
originatorPod, regularPod}
+ SortAllocationsBasedOnAsk(allocations, total, ask)
+
+ assert.Equal(t, allocations[0].GetAllocationKey(), "regularPod")
+ assert.Equal(t, allocations[1].GetAllocationKey(), "optedOutPod")
+ assert.Equal(t, allocations[2].GetAllocationKey(), "originatorPod")
+ assert.Equal(t, allocations[3].GetAllocationKey(),
"optedOutOriginatorPod")
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]