Commit 61c52a4a authored by Michael Schurter's avatar Michael Schurter
Browse files

wip alloc copy fixes

parent 71cafc5d
Showing with 44 additions and 18 deletions
+44 -18
......@@ -193,6 +193,7 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi
}
// Check if the network is overcommitted
//XXX Remove
if netIdx.Overcommitted() {
return false, "bandwidth exceeded", used, nil
}
......
......@@ -216,6 +216,7 @@ func (idx *NetworkIndex) AddReserved(n *NetworkResource) (collide bool) {
for _, port := range ports {
// Guard against invalid port
if port.Value < 0 || port.Value >= MaxValidPort {
//XXX Is it safe to return early here? or should we continue so used is properly updated
return true
}
if used.Check(uint(port.Value)) {
......
......@@ -2529,6 +2529,12 @@ func (p AllocatedPorts) Get(label string) (AllocatedPortMapping, bool) {
return AllocatedPortMapping{}, false
}
func (p AllocatedPorts) Copy() AllocatedPorts {
n := make(AllocatedPorts, len(p))
copy(n, p)
return n
}
type Port struct {
// Label is the key for HCL port stanzas: port "foo" {}
Label string
......@@ -3690,7 +3696,7 @@ func (a AllocatedSharedResources) Copy() AllocatedSharedResources {
return AllocatedSharedResources{
Networks: a.Networks.Copy(),
DiskMB: a.DiskMB,
Ports: a.Ports,
Ports: a.Ports.Copy(),
}
}
......@@ -9121,6 +9127,21 @@ type DesiredTransition struct {
ForceReschedule *bool
}
// Copy returns a copy of the DesiredTransition
func (d DesiredTransition) Copy() DesiredTransition {
cpy := DesiredTransition{}
if d.Migrate != nil {
cpy.Migrate = helper.BoolToPtr(*d.Migrate)
}
if d.Reschedule != nil {
cpy.Reschedule = helper.BoolToPtr(*d.Reschedule)
}
if d.ForceReschedule != nil {
cpy.ForceReschedule = helper.BoolToPtr(*d.ForceReschedule)
}
return cpy
}
// Merge merges the two desired transitions, preferring the values from the
// passed in object.
func (d *DesiredTransition) Merge(o *DesiredTransition) {
......@@ -9373,9 +9394,9 @@ func (a *Allocation) copyImpl(job bool) *Allocation {
na.Job = na.Job.Copy()
}
na.AllocatedResources = na.AllocatedResources.Copy()
na.Resources = na.Resources.Copy()
na.SharedResources = na.SharedResources.Copy()
na.AllocatedResources = a.AllocatedResources.Copy()
na.Resources = a.Resources.Copy()
na.SharedResources = a.SharedResources.Copy()
if a.TaskResources != nil {
tr := make(map[string]*Resources, len(na.TaskResources))
......@@ -9385,18 +9406,25 @@ func (a *Allocation) copyImpl(job bool) *Allocation {
na.TaskResources = tr
}
na.Metrics = na.Metrics.Copy()
na.DeploymentStatus = na.DeploymentStatus.Copy()
na.Metrics = a.Metrics.Copy()
na.DesiredTransition = a.DesiredTransition.Copy()
if a.TaskStates != nil {
ts := make(map[string]*TaskState, len(na.TaskStates))
for task, state := range na.TaskStates {
ts[task] = state.Copy()
na.TaskStates = make(map[string]*TaskState, len(a.TaskStates))
for task, state := range a.TaskStates {
na.TaskStates[task] = state.Copy()
}
}
if a.AllocStates != nil {
na.AllocStates = make([]*AllocState, len(a.AllocStates))
for i, s := range a.AllocStates {
na.AllocStates[i] = s
}
na.TaskStates = ts
}
na.DeploymentStatus = a.DeploymentStatus.Copy()
na.RescheduleTracker = a.RescheduleTracker.Copy()
na.NetworkStatus = a.NetworkStatus.Copy()
na.PreemptedAllocations = helper.CopySliceString(a.PreemptedAllocations)
return na
}
......
......@@ -378,6 +378,7 @@ OUTER:
}
// Reserve this to prevent another task from colliding
//XXX Check return value?!
netIdx.AddReserved(offer)
// Update the network ask to the offer
......
......@@ -799,9 +799,8 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
resources.Devices = devices
}
// Create a shallow copy
newAlloc := new(structs.Allocation)
*newAlloc = *update.Alloc
// Create a copy
newAlloc := update.Alloc.Copy()
// Update the allocation
newAlloc.EvalID = eval.ID
......@@ -810,11 +809,7 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job,
newAlloc.AllocatedResources = &structs.AllocatedResources{
Tasks: option.TaskResources,
TaskLifecycles: option.TaskLifecycles,
Shared: structs.AllocatedSharedResources{
DiskMB: int64(update.TaskGroup.EphemeralDisk.SizeMB),
Ports: update.Alloc.AllocatedResources.Shared.Ports,
Networks: update.Alloc.AllocatedResources.Shared.Networks.Copy(),
},
Shared: update.Alloc.AllocatedResources.Shared.Copy(),
}
newAlloc.Metrics = ctx.Metrics()
ctx.Plan().AppendAlloc(newAlloc, nil)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment