Skip to content

Commit

Permalink
fix: required affinity (#812)
Browse files Browse the repository at this point in the history
* fix: required affinity

* chore: rm dead code
  • Loading branch information
grutt authored Aug 23, 2024
1 parent 53be615 commit ee5d867
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
7 changes: 7 additions & 0 deletions pkg/scheduling/affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func TestComputeWeight(t *testing.T) {
{
name: "No match for a required returns -1",
desiredLabels: []*dbsqlc.GetDesiredLabelsRow{
{
Key: "memory",
Comparator: dbsqlc.WorkerLabelComparatorEQUAL,
StrValue: sqlchelpers.TextFromStr("100"),
Weight: 15,
Required: false,
},
{
Key: "region",
Comparator: dbsqlc.WorkerLabelComparatorEQUAL,
Expand Down
21 changes: 21 additions & 0 deletions pkg/scheduling/fixtures/affinity_hard.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
"tenantId": "707d0855-80ab-4e1f-a156-f1c4546cbf52",
"queue": "child:process2",
"Order": 0
},
{
"id": 152260,
"stepRunId": "064e787a-6cfd-4f82-8b6d-d8031459fdef",
"stepId": "e2c744b8-bebb-4b05-8292-d2ce36f27929",
"actionId": "child:process2",
"scheduleTimeoutAt": "2024-08-07T21:12:49.56Z",
"stepTimeout": "60s",
"isQueued": true,
"tenantId": "707d0855-80ab-4e1f-a156-f1c4546cbf52",
"queue": "child:process2",
"Order": 0
}
],
"WorkerLabels": {
Expand Down Expand Up @@ -86,6 +98,15 @@
"Required": true,
"Weight": 1
}
],
"e2c744b8-bebb-4b05-8292-d2ce36f27929": [
{
"Key": "MODEL",
"Comparator": "EQUAL",
"StrValue": "C",
"Required": true,
"Weight": 1
}
]
}
}
45 changes: 45 additions & 0 deletions pkg/scheduling/fixtures/affinity_hard_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"StepRunIds": [
"16fa711e-c03e-435c-88d9-62adf1591d98",
"064e787a-6cfd-4f82-8b6d-d8031459fdee"
],
"StepRunTimeouts": [
"60s",
"60s"
],
"SlotIds": [
"8cf68f09-b914-4f31-9777-8082b751a2d4",
"aed946be-43db-4b5f-876a-c6c71f4d52aa"
],
"WorkerIds": [
"aaaaaaaa-43db-4b5f-876a-c6c71f4d52aa",
"bbbbbbbb-43db-4b5f-876a-c6c71f4d52aa"
],
"UnassignedStepRunIds": [
"064e787a-6cfd-4f82-8b6d-d8031459fdef"
],
"QueuedStepRuns": [
{
"StepRunId": "16fa711e-c03e-435c-88d9-62adf1591d98",
"WorkerId": "aaaaaaaa-43db-4b5f-876a-c6c71f4d52aa",
"DispatcherId": "9994a9eb-430d-46da-934d-d9dd953cfd21"
},
{
"StepRunId": "064e787a-6cfd-4f82-8b6d-d8031459fdee",
"WorkerId": "bbbbbbbb-43db-4b5f-876a-c6c71f4d52aa",
"DispatcherId": "9994a9eb-430d-46da-934d-d9dd953cfd21"
}
],
"TimedOutStepRuns": [],
"RateLimitedStepRuns": [],
"RateLimitedQueues": {},
"QueuedItems": [
137295,
152259
],
"ShouldContinue": false,
"MinQueuedIds": {
"child:process2": 0
},
"RateLimitUnitsConsumed": {}
}
4 changes: 2 additions & 2 deletions pkg/scheduling/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestGeneratePlan(t *testing.T) {
name: "GeneratePlan_Affinity_Soft",
args: args{
fixtureArgs: "./fixtures/affinity_soft.json",
fixtureResult: "./fixtures/affinity_output.json",
fixtureResult: "./fixtures/affinity_soft_output.json",
noTimeout: true,
},
want: func(s SchedulePlan, fixtureResult string) bool {
Expand All @@ -175,7 +175,7 @@ func TestGeneratePlan(t *testing.T) {
name: "GeneratePlan_Affinity_Hard",
args: args{
fixtureArgs: "./fixtures/affinity_hard.json",
fixtureResult: "./fixtures/affinity_output.json",
fixtureResult: "./fixtures/affinity_hard_output.json",
noTimeout: true,
},
want: func(s SchedulePlan, fixtureResult string) bool {
Expand Down
5 changes: 0 additions & 5 deletions pkg/scheduling/worker_state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func NewWorkerStateManager(
for workerId, worker := range workers {
weight := ComputeWeight(desired, worker.labels)

// skip workers that are not a match (i.e. required)
if weight < 0 {
continue
}

// cache the weight on the worker
workers[workerId].AddStepWeight(stepId, weight)

Expand Down

0 comments on commit ee5d867

Please sign in to comment.