Skip to content

Commit

Permalink
Merge pull request #2097 from hashicorp/b-wait-remote-alloc
Browse files Browse the repository at this point in the history
cancelling waiting for remote allocation
  • Loading branch information
diptanu committed Dec 13, 2016
2 parents 1f0184e + 76794f0 commit 9c31a41
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,10 +1447,11 @@ func (c *Client) blockForRemoteAlloc(alloc *structs.Allocation) {
}

// Wait for the remote previous alloc to be terminal if the alloc is sticky
if tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky {
if tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky && tg.EphemeralDisk.Migrate {
c.logger.Printf("[DEBUG] client: blocking alloc %q for previous allocation %q", alloc.ID, alloc.PreviousAllocation)
// Block until the previous allocation migrates to terminal state
prevAlloc, err := c.waitForAllocTerminal(alloc.PreviousAllocation)
stopCh := c.migratingAllocs[alloc.ID]
prevAlloc, err := c.waitForAllocTerminal(alloc.PreviousAllocation, stopCh)
if err != nil {
c.logger.Printf("[ERR] client: error waiting for allocation %q: %v",
alloc.PreviousAllocation, err)
Expand All @@ -1473,7 +1474,7 @@ ADDALLOC:

// waitForAllocTerminal waits for an allocation with the given alloc id to
// transition to terminal state and blocks the caller until then.
func (c *Client) waitForAllocTerminal(allocID string) (*structs.Allocation, error) {
func (c *Client) waitForAllocTerminal(allocID string, stopCh chan struct{}) (*structs.Allocation, error) {
req := structs.AllocSpecificRequest{
AllocID: allocID,
QueryOptions: structs.QueryOptions{
Expand All @@ -1491,6 +1492,8 @@ func (c *Client) waitForAllocTerminal(allocID string) (*structs.Allocation, erro
select {
case <-time.After(retry):
continue
case <-stopCh:
return nil, fmt.Errorf("giving up waiting on alloc %v since migration is not needed", allocID)
case <-c.shutdownCh:
return nil, fmt.Errorf("aborting because client is shutting down")
}
Expand Down

0 comments on commit 9c31a41

Please sign in to comment.