Skip to content

Commit

Permalink
Not moving alloc data when sticky is turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Nov 24, 2016
1 parent 3e63908 commit 8a45ae8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,17 +1069,23 @@ func (c *Client) updateNodeStatus() error {

// updateAllocStatus is used to update the status of an allocation
func (c *Client) updateAllocStatus(alloc *structs.Allocation) {
// Only send the fields that are updatable by the client.
select {
case c.allocUpdates <- alloc:
case <-c.shutdownCh:
}
}

// stripAllocation strips the allocation of fields which can be re-assembled in
// the server.
func (c *Client) stripAllocation(alloc *structs.Allocation) *structs.Allocation {
stripped := new(structs.Allocation)
stripped.ID = alloc.ID
stripped.NodeID = c.Node().ID
stripped.TaskStates = alloc.TaskStates
stripped.ClientStatus = alloc.ClientStatus
stripped.ClientDescription = alloc.ClientDescription
select {
case c.allocUpdates <- stripped:
case <-c.shutdownCh:
}

return stripped
}

// allocSync is a long lived function that batches allocation updates to the
Expand All @@ -1103,7 +1109,10 @@ func (c *Client) allocSync() {
if blockedAlloc, ok := c.blockedAllocations[alloc.ID]; ok && alloc.Terminated() {
var prevAllocDir *allocdir.AllocDir
if ar, ok := c.getAllocRunners()[alloc.ID]; ok {
prevAllocDir = ar.GetAllocDir()
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg != nil && tg.EphemeralDisk.Sticky {
prevAllocDir = ar.GetAllocDir()
}
}
if err := c.addAlloc(blockedAlloc, prevAllocDir); err != nil {
c.logger.Printf("[ERR] client: failed to add alloc which was previously blocked %q: %v",
Expand All @@ -1120,7 +1129,9 @@ func (c *Client) allocSync() {

sync := make([]*structs.Allocation, 0, len(updates))
for _, alloc := range updates {
sync = append(sync, alloc)
// Only send the fields that are updatable by the client.
stripped := c.stripAllocation(alloc)
sync = append(sync, stripped)
}

// Send to server.
Expand Down Expand Up @@ -1393,7 +1404,7 @@ func (c *Client) runAllocs(update *allocUpdates) {
// previous allocation
var prevAllocDir *allocdir.AllocDir
tg := add.Job.LookupTaskGroup(add.TaskGroup)
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky == true && ar != nil {
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky && ar != nil {
prevAllocDir = ar.GetAllocDir()
}

Expand Down

0 comments on commit 8a45ae8

Please sign in to comment.