diffResult stores values not pointers

This commit is contained in:
Alex Dadgar 2015-10-16 11:43:09 -07:00
parent 406e135ce8
commit ab9acb9edf
3 changed files with 12 additions and 11 deletions

View File

@ -243,7 +243,7 @@ func (s *GenericScheduler) computeJobAllocs() error {
} }
// computePlacements computes placements for allocations // computePlacements computes placements for allocations
func (s *GenericScheduler) computePlacements(place []*allocTuple) error { func (s *GenericScheduler) computePlacements(place []allocTuple) error {
// Get the base nodes // Get the base nodes
nodes, err := readyNodesInDCs(s.state, s.job.Datacenters) nodes, err := readyNodesInDCs(s.state, s.job.Datacenters)
if err != nil { if err != nil {

View File

@ -202,7 +202,7 @@ func (s *SystemScheduler) computeJobAllocs() error {
} }
// computePlacements computes placements for allocations // computePlacements computes placements for allocations
func (s *SystemScheduler) computePlacements(place []*allocTuple) error { func (s *SystemScheduler) computePlacements(place []allocTuple) error {
nodeByID := make(map[string]*structs.Node, len(s.nodes)) nodeByID := make(map[string]*structs.Node, len(s.nodes))
for _, node := range s.nodes { for _, node := range s.nodes {
nodeByID[node.ID] = node nodeByID[node.ID] = node

View File

@ -35,7 +35,7 @@ func materializeTaskGroups(job *structs.Job) map[string]*structs.TaskGroup {
// diffResult is used to return the sets that result from the diff // diffResult is used to return the sets that result from the diff
type diffResult struct { type diffResult struct {
place, update, migrate, stop, ignore []*allocTuple place, update, migrate, stop, ignore []allocTuple
} }
func (d *diffResult) GoString() string { func (d *diffResult) GoString() string {
@ -73,7 +73,7 @@ func diffAllocs(job *structs.Job, taintedNodes map[string]bool,
// If not required, we stop the alloc // If not required, we stop the alloc
if !ok { if !ok {
result.stop = append(result.stop, &allocTuple{ result.stop = append(result.stop, allocTuple{
Name: name, Name: name,
TaskGroup: tg, TaskGroup: tg,
Alloc: exist, Alloc: exist,
@ -83,7 +83,7 @@ func diffAllocs(job *structs.Job, taintedNodes map[string]bool,
// If we are on a tainted node, we must migrate // If we are on a tainted node, we must migrate
if taintedNodes[exist.NodeID] { if taintedNodes[exist.NodeID] {
result.migrate = append(result.migrate, &allocTuple{ result.migrate = append(result.migrate, allocTuple{
Name: name, Name: name,
TaskGroup: tg, TaskGroup: tg,
Alloc: exist, Alloc: exist,
@ -96,7 +96,7 @@ func diffAllocs(job *structs.Job, taintedNodes map[string]bool,
// if the job definition has changed in a way that affects // if the job definition has changed in a way that affects
// this allocation and potentially ignore it. // this allocation and potentially ignore it.
if job.ModifyIndex != exist.Job.ModifyIndex { if job.ModifyIndex != exist.Job.ModifyIndex {
result.update = append(result.update, &allocTuple{ result.update = append(result.update, allocTuple{
Name: name, Name: name,
TaskGroup: tg, TaskGroup: tg,
Alloc: exist, Alloc: exist,
@ -105,7 +105,7 @@ func diffAllocs(job *structs.Job, taintedNodes map[string]bool,
} }
// Everything is up-to-date // Everything is up-to-date
result.ignore = append(result.ignore, &allocTuple{ result.ignore = append(result.ignore, allocTuple{
Name: name, Name: name,
TaskGroup: tg, TaskGroup: tg,
Alloc: exist, Alloc: exist,
@ -121,7 +121,7 @@ func diffAllocs(job *structs.Job, taintedNodes map[string]bool,
// is an existing allocation, we would have checked for a potential // is an existing allocation, we would have checked for a potential
// update or ignore above. // update or ignore above.
if !ok { if !ok {
result.place = append(result.place, &allocTuple{ result.place = append(result.place, allocTuple{
Name: name, Name: name,
TaskGroup: tg, TaskGroup: tg,
}) })
@ -156,7 +156,8 @@ func diffSystemAllocs(job *structs.Job, nodes []*structs.Node, taintedNodes map[
diff := diffAllocs(job, taintedNodes, required, allocs) diff := diffAllocs(job, taintedNodes, required, allocs)
// Mark the alloc as being for a specific node. // Mark the alloc as being for a specific node.
for _, alloc := range diff.place { for i := range diff.place {
alloc := &diff.place[i]
alloc.Alloc = &structs.Allocation{NodeID: nodeID} alloc.Alloc = &structs.Allocation{NodeID: nodeID}
} }
@ -311,7 +312,7 @@ func setStatus(logger *log.Logger, planner Planner, eval, nextEval *structs.Eval
// inplaceUpdate attempts to update allocations in-place where possible. // inplaceUpdate attempts to update allocations in-place where possible.
func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job, func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
stack Stack, updates []*allocTuple) []*allocTuple { stack Stack, updates []allocTuple) []allocTuple {
n := len(updates) n := len(updates)
inplace := 0 inplace := 0
@ -393,7 +394,7 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
// evictAndPlace is used to mark allocations for evicts and add them to the // evictAndPlace is used to mark allocations for evicts and add them to the
// placement queue. evictAndPlace modifies both the the diffResult and the // placement queue. evictAndPlace modifies both the the diffResult and the
// limit. It returns true if the limit has been reached. // limit. It returns true if the limit has been reached.
func evictAndPlace(ctx Context, diff *diffResult, allocs []*allocTuple, desc string, limit *int) bool { func evictAndPlace(ctx Context, diff *diffResult, allocs []allocTuple, desc string, limit *int) bool {
n := len(allocs) n := len(allocs)
for i := 0; i < n && i < *limit; i++ { for i := 0; i < n && i < *limit; i++ {
a := allocs[i] a := allocs[i]