fix(scheduling): negative weigths ranks were not excluded from the candidate workers pool (#1941)

Co-authored-by: jbsouvestre <jean-baptiste@ubble.ai>
This commit is contained in:
Jean-Baptiste Souvestre
2025-07-03 15:03:12 +02:00
committed by GitHub
parent 2ccd434ebf
commit f08c348710
2 changed files with 45 additions and 0 deletions
+5
View File
@@ -169,6 +169,11 @@ func (r *rankedValidSlots) order() []*slot {
for i := len(sortedRanks) - 1; i >= 0; i-- {
rank := sortedRanks[i]
if rank < 0 {
// skip negative ranks, as they are not valid for scheduling
continue
}
if r.ranksToSlots[rank] != nil {
nonNegativeSlots = append(nonNegativeSlots, r.ranksToSlots[rank]...)
}
+40
View File
@@ -96,6 +96,46 @@ func TestGetRankedSlots(t *testing.T) {
},
expectedWorker: []string{stableWorkerId2, stableWorkerId1},
},
{
name: "Affinity labels with strict requirements",
qi: &sqlcv1.V1QueueItem{},
labels: []*sqlcv1.GetDesiredLabelsRow{
{
Key: "key1",
Weight: 1,
Required: true,
Comparator: sqlcv1.WorkerLabelComparatorEQUAL,
IntValue: pgtype.Int4{Int32: 1, Valid: true},
},
},
slots: []*slot{
newSlot(&worker{ListActiveWorkersResult: &v1.ListActiveWorkersResult{ID: (stableWorkerId1), Labels: []*sqlcv1.ListManyWorkerLabelsRow{{
Key: "key1",
IntValue: pgtype.Int4{Int32: 1, Valid: true},
}}}}, []string{}),
},
expectedWorker: []string{stableWorkerId1},
},
{
name: "Affinity labels with strict requirements and unsatisfiable conditions",
qi: &sqlcv1.V1QueueItem{},
labels: []*sqlcv1.GetDesiredLabelsRow{
{
Key: "key1",
Weight: 1,
Required: true,
Comparator: sqlcv1.WorkerLabelComparatorEQUAL,
IntValue: pgtype.Int4{Int32: 1, Valid: true},
},
},
slots: []*slot{
newSlot(&worker{ListActiveWorkersResult: &v1.ListActiveWorkersResult{ID: (stableWorkerId2), Labels: []*sqlcv1.ListManyWorkerLabelsRow{{
Key: "key1",
IntValue: pgtype.Int4{Int32: 2, Valid: true},
}}}}, []string{}),
},
expectedWorker: []string{},
},
}
for _, tt := range tests {