Merge pull request #4474 from hashicorp/b-4463

scheduler: fixed nil panic and clearer error handling
This commit is contained in:
Nick Ethier 2018-07-10 21:30:09 -04:00 committed by GitHub
commit 2f202e20b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -592,14 +592,18 @@ func updateRescheduleTracker(alloc *structs.Allocation, prev *structs.Allocation
} }
// findPreferredNode finds the preferred node for an allocation // findPreferredNode finds the preferred node for an allocation
func (s *GenericScheduler) findPreferredNode(place placementResult) (node *structs.Node, err error) { func (s *GenericScheduler) findPreferredNode(place placementResult) (*structs.Node, error) {
if prev := place.PreviousAllocation(); prev != nil && place.TaskGroup().EphemeralDisk.Sticky == true { if prev := place.PreviousAllocation(); prev != nil && place.TaskGroup().EphemeralDisk.Sticky == true {
var preferredNode *structs.Node var preferredNode *structs.Node
ws := memdb.NewWatchSet() ws := memdb.NewWatchSet()
preferredNode, err = s.state.NodeByID(ws, prev.NodeID) preferredNode, err = s.state.NodeByID(ws, prev.NodeID)
if preferredNode.Ready() { if err != nil {
node = preferredNode return nil, err
}
if preferredNode != nil && preferredNode.Ready() {
return preferredNode, nil
} }
} }
return return nil, nil
} }