This is an automated email from the ASF dual-hosted git repository.
pbacsko pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/branch-1.7 by this push:
new d01d1921 [YUNIKORN-3084] Fix Inconsistency in Allocation Removal from
sortedRequests (#1022)
d01d1921 is described below
commit d01d1921a33bd886f6e21d330ed7e53ae44b8ab6
Author: Mit Desai <[email protected]>
AuthorDate: Thu Jun 12 13:34:09 2025 +0200
[YUNIKORN-3084] Fix Inconsistency in Allocation Removal from sortedRequests
(#1022)
Closes: #1022
Signed-off-by: Peter Bacsko <[email protected]>
(cherry picked from commit a5b865c7a5bfb4518a5861210e5bf44df95abb4e)
---
pkg/scheduler/objects/sorted_asks.go | 11 +++---
pkg/scheduler/objects/sorted_asks_test.go | 59 +++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/pkg/scheduler/objects/sorted_asks.go
b/pkg/scheduler/objects/sorted_asks.go
index 355d5c49..5b388de0 100644
--- a/pkg/scheduler/objects/sorted_asks.go
+++ b/pkg/scheduler/objects/sorted_asks.go
@@ -50,13 +50,12 @@ func (s *sortedRequests) insertAt(index int, ask
*Allocation) {
}
func (s *sortedRequests) remove(ask *Allocation) {
- idx := sort.Search(len(*s), func(i int) bool {
- return (*s)[i].LessThan(ask)
- })
- if idx == len(*s) || (*s)[idx].allocationKey != ask.allocationKey {
- return
+ for i, a := range *s {
+ if a.allocationKey == ask.allocationKey {
+ s.removeAt(i)
+ return
+ }
}
- s.removeAt(idx)
}
func (s *sortedRequests) removeAt(index int) {
diff --git a/pkg/scheduler/objects/sorted_asks_test.go
b/pkg/scheduler/objects/sorted_asks_test.go
index a2fc64da..0a128f85 100644
--- a/pkg/scheduler/objects/sorted_asks_test.go
+++ b/pkg/scheduler/objects/sorted_asks_test.go
@@ -98,6 +98,65 @@ func TestInsertRemove(t *testing.T) {
assert.Equal(t, 99, len(sorted))
}
+func TestRemoveWithSamePriorityAndTime(t *testing.T) {
+ // Create a sorted requests list
+ sorted := sortedRequests{}
+
+ // Create allocations with same priority and creation time
+ // but different allocation keys
+ baseTime := time.Now()
+ alloc1 := &Allocation{
+ createTime: baseTime,
+ priority: 10,
+ allocationKey: "alloc-1",
+ }
+ alloc2 := &Allocation{
+ createTime: baseTime,
+ priority: 10,
+ allocationKey: "alloc-2",
+ }
+ alloc3 := &Allocation{
+ createTime: baseTime,
+ priority: 10,
+ allocationKey: "alloc-3",
+ }
+
+ // Insert the allocations
+ sorted.insert(alloc1)
+ sorted.insert(alloc2)
+ sorted.insert(alloc3)
+
+ // Verify all allocations are in the list
+ assert.Equal(t, 3, len(sorted))
+ assert.Assert(t, askPresent(alloc1, sorted), "alloc1 should be present")
+ assert.Assert(t, askPresent(alloc2, sorted), "alloc2 should be present")
+ assert.Assert(t, askPresent(alloc3, sorted), "alloc3 should be present")
+
+ // Try to remove alloc2
+ sorted.remove(alloc2)
+
+ // Verify alloc2 is removed but alloc1 and alloc3 are still there
+ assert.Equal(t, 2, len(sorted))
+ assert.Assert(t, askPresent(alloc1, sorted), "alloc1 should still be
present")
+ assert.Assert(t, !askPresent(alloc2, sorted), "alloc2 should be
removed")
+ assert.Assert(t, askPresent(alloc3, sorted), "alloc3 should still be
present")
+
+ // Try to remove alloc1
+ sorted.remove(alloc1)
+
+ // Verify alloc1 is removed and only alloc3 remains
+ assert.Equal(t, 1, len(sorted))
+ assert.Assert(t, !askPresent(alloc1, sorted), "alloc1 should be
removed")
+ assert.Assert(t, askPresent(alloc3, sorted), "alloc3 should still be
present")
+
+ // Try to remove alloc3
+ sorted.remove(alloc3)
+
+ // Verify all allocations are removed
+ assert.Equal(t, 0, len(sorted))
+ assert.Assert(t, !askPresent(alloc3, sorted), "alloc3 should be
removed")
+}
+
func askPresent(ask *Allocation, asks []*Allocation) bool {
for _, a := range asks {
if a.allocationKey == ask.allocationKey {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]