Skip to content

Commit

Permalink
Ensuring allocs are not added multiple times to blocking queue
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Nov 29, 2016
1 parent f74472a commit 9100497
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,22 +1370,32 @@ func (c *Client) runAllocs(update *allocUpdates) {
for _, add := range diff.added {
// If the allocation is chained and the previous allocation hasn't
// terminated yet, then add the alloc to the blocked queue.
c.blockedAllocsLock.Lock()
ar, ok := c.getAllocRunners()[add.PreviousAllocation]
if ok && !ar.Alloc().Terminated() {
c.logger.Printf("[DEBUG] client: added alloc %q to blocked queue", add.ID)
c.blockedAllocsLock.Lock()
c.blockedAllocations[add.PreviousAllocation] = add
// Check if the alloc is already present in the blocked allocations
// map
if _, ok := c.blockedAllocations[add.PreviousAllocation]; !ok {
c.logger.Printf("[DEBUG] client: added alloc %q to blocked queue for previous allocation %q", add.ID,
add.PreviousAllocation)
c.blockedAllocations[add.PreviousAllocation] = add
}
c.blockedAllocsLock.Unlock()
continue
}
c.blockedAllocsLock.Unlock()

// This means the allocation has a previous allocation on another node
// so we will block for the previous allocation to complete
if add.PreviousAllocation != "" && !ok {
// Ensure that we are not blocking for the remote allocation if we
// have already blocked
c.migratingAllocsLock.Lock()
c.migratingAllocs[add.ID] = make(chan struct{})
if _, ok := c.migratingAllocs[add.ID]; !ok {
c.migratingAllocs[add.ID] = make(chan struct{})
go c.blockForRemoteAlloc(add)
}
c.migratingAllocsLock.Unlock()
go c.blockForRemoteAlloc(add)
continue
}

Expand Down

0 comments on commit 9100497

Please sign in to comment.