Skip to content

Commit

Permalink
scheduler: fix panic in system jobs when nodes filtered by class
Browse files Browse the repository at this point in the history
In the system scheduler, if a subset of clients are filtered by class,
we hit a code path where the `AllocMetric` has been copied, but the
`Copy` method does not instantiate the various maps. This leads to an
assignment to a nil map. This changeset ensures that the maps are
non-nil before continuing.

The `Copy` method relies on functions in the `helper` package that all
return nil slices or maps when passed zero-length inputs. This
changeset to fix the panic bug intentionally defers updating those
functions because it'll have potential impact on memory usage. See
#11564 for more details.
  • Loading branch information
tgross committed Nov 24, 2021
1 parent e784378 commit a6ea5be
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scheduler/scheduler_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,16 @@ func mergeNodeFiltered(acc, curr *structs.AllocMetric) *structs.AllocMetric {

acc.NodesEvaluated += curr.NodesEvaluated
acc.NodesFiltered += curr.NodesFiltered

if acc.ClassFiltered == nil {
acc.ClassFiltered = make(map[string]int)
}
for k, v := range curr.ClassFiltered {
acc.ClassFiltered[k] += v
}
if acc.ConstraintFiltered == nil {
acc.ConstraintFiltered = make(map[string]int)
}
for k, v := range curr.ConstraintFiltered {
acc.ConstraintFiltered[k] += v
}
Expand Down

0 comments on commit a6ea5be

Please sign in to comment.