Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Schurter <mschurter@hashicorp.com>
  • Loading branch information
tgross and schmichael committed Feb 8, 2022
1 parent 66f943c commit c68c778
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .changelog/12008.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:improvement
scheduler: Seed the shuffling of nodes with the evaluation ID to improve debuggability
scheduler: Seed node shuffling with the evaluation ID to make the order reproducible
```
9 changes: 3 additions & 6 deletions scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func taintedNodes(state State, allocs []*structs.Allocation) (map[string]*struct

// shuffleNodes randomizes the slice order with the Fisher-Yates
// algorithm. We seed the random source with the eval ID (which is
// random) to aid in postmortem debuggging of specific evaluations and
// random) to aid in postmortem debugging of specific evaluations and
// state snapshots.
func shuffleNodes(plan *structs.Plan, nodes []*structs.Node) {

Expand All @@ -388,12 +388,9 @@ func shuffleNodes(plan *structs.Plan, nodes []*structs.Node) {
buf := []byte(plan.EvalID)
seed := int64(binary.BigEndian.Uint32(buf[len(buf)-4:]))

// include the plan progress so that we don't retry with
// include the plan result's RefreshIndex so that we don't retry with
// the exact same shuffle
seed = seed |
int64(len(plan.NodeAllocation)) |
int64(len(plan.NodeUpdate)) |
int64(len(plan.DeploymentUpdates))
seed |= planResult.RefreshIndex

r := rand.New(rand.NewSource(seed))

Expand Down

0 comments on commit c68c778

Please sign in to comment.