Skip to content

Commit

Permalink
Merge pull request kubernetes#123609 from veshij/fix
Browse files Browse the repository at this point in the history
[kubernetes/scheduler] use lockless diagnosis collection in findNodes…
  • Loading branch information
k8s-ci-robot committed Mar 4, 2024
2 parents 4ed7f6b + ba52546 commit 6c8dc1d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/scheduler/schedule_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,15 @@ func (sched *Scheduler) findNodesThatPassFilters(
}

errCh := parallelize.NewErrorChannel()
var statusesLock sync.Mutex
var feasibleNodesLen int32
ctx, cancel := context.WithCancel(ctx)
defer cancel()

type nodeStatus struct {
node string
status *framework.Status
}
result := make([]*nodeStatus, numAllNodes)
checkNode := func(i int) {
// We check the nodes starting from where we left off in the previous scheduling cycle,
// this is to make sure all nodes have the same chance of being examined across pods.
Expand All @@ -617,10 +622,7 @@ func (sched *Scheduler) findNodesThatPassFilters(
feasibleNodes[length-1] = nodeInfo
}
} else {
statusesLock.Lock()
diagnosis.NodeToStatusMap[nodeInfo.Node().Name] = status
diagnosis.AddPluginStatus(status)
statusesLock.Unlock()
result[i] = &nodeStatus{node: nodeInfo.Node().Name, status: status}
}
}

Expand All @@ -637,6 +639,13 @@ func (sched *Scheduler) findNodesThatPassFilters(
// are found.
fwk.Parallelizer().Until(ctx, numAllNodes, checkNode, metrics.Filter)
feasibleNodes = feasibleNodes[:feasibleNodesLen]
for _, item := range result {
if item == nil {
continue
}
diagnosis.NodeToStatusMap[item.node] = item.status
diagnosis.AddPluginStatus(item.status)
}
if err := errCh.ReceiveError(); err != nil {
statusCode = framework.Error
return feasibleNodes, err
Expand Down

0 comments on commit 6c8dc1d

Please sign in to comment.