Merge pull request #2040 from hashicorp/b-block-allocs
Ensuring allocs are not added multiple times to blocking queue
This commit is contained in:
commit
eaed59c028
|
@ -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()
|
||||
// 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()
|
||||
if _, ok := c.migratingAllocs[add.ID]; !ok {
|
||||
c.migratingAllocs[add.ID] = make(chan struct{})
|
||||
c.migratingAllocsLock.Unlock()
|
||||
go c.blockForRemoteAlloc(add)
|
||||
}
|
||||
c.migratingAllocsLock.Unlock()
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue