Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensuring allocs are not added multiple times to blocking queue #2040

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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