Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a race in the scheduler. #70892

Merged
merged 1 commit into from
Nov 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 21 additions & 16 deletions pkg/scheduler/core/generic_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,33 +653,38 @@ func PrioritizeNodes(

results := make([]schedulerapi.HostPriorityList, len(priorityConfigs), len(priorityConfigs))

for i := range priorityConfigs {
results[i] = make(schedulerapi.HostPriorityList, len(nodes))
}
// DEPRECATED: we can remove this when all priorityConfigs implement the
// Map-Reduce pattern.
workqueue.ParallelizeUntil(context.TODO(), 16, len(priorityConfigs), func(i int) {
priorityConfig := priorityConfigs[i]
if priorityConfig.Function == nil {
results[i] = make(schedulerapi.HostPriorityList, len(nodes))
return
mikedanese marked this conversation as resolved.
Show resolved Hide resolved
}

processNode := func(index int) {
nodeInfo := nodeNameToInfo[nodes[index].Name]
var err error
results[i], err = priorityConfig.Function(pod, nodeNameToInfo, nodes)
if err != nil {
appendError(err)
}
})

workqueue.ParallelizeUntil(context.TODO(), 16, len(nodes), func(index int) {
nodeInfo := nodeNameToInfo[nodes[index].Name]
for i, priorityConfig := range priorityConfigs {
// DEPRECATED when ALL priorityConfigs have Map-Reduce pattern.
if priorityConfigs[i].Function != nil {
// Make sure that the old-style priority function only runs once.
if results[i][0].Host == "" {
results[i], err = priorityConfig.Function(pod, nodeNameToInfo, nodes)
if err != nil {
appendError(err)
}
}
if priorityConfig.Function != nil {
continue
}

var err error
results[i][index], err = priorityConfigs[i].Map(pod, meta, nodeInfo)
if err != nil {
appendError(err)
results[i][index].Host = nodes[index].Name
}
}
}
workqueue.ParallelizeUntil(context.TODO(), 16, len(nodes), processNode)
})

for i, priorityConfig := range priorityConfigs {
if priorityConfig.Reduce == nil {
continue
Expand Down