Skip to content

Commit

Permalink
Fix regression by returning error on unknown alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Oct 30, 2017
1 parent 260caf2 commit 6c36f76
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,10 @@ func (c *Client) Stats() map[string]map[string]string {
return stats
}

// CollectAllocation garbage collects a single allocation
func (c *Client) CollectAllocation(allocID string) {
c.garbageCollector.Collect(allocID)
// CollectAllocation garbage collects a single allocation on a node. Returns
// true if alloc was found and garbage collected; otherwise false.
func (c *Client) CollectAllocation(allocID string) bool {
return c.garbageCollector.Collect(allocID)
}

// CollectAllAllocs garbage collects all allocations on a node in the terminal
Expand Down
8 changes: 5 additions & 3 deletions client/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,16 @@ func (a *AllocGarbageCollector) Stop() {
close(a.shutdownCh)
}

// Collect garbage collects a single allocation on a node
func (a *AllocGarbageCollector) Collect(allocID string) {
// Collect garbage collects a single allocation on a node. Returns true if
// alloc was found and garbage collected; otherwise false.
func (a *AllocGarbageCollector) Collect(allocID string) bool {
if gcAlloc := a.allocRunners.Remove(allocID); gcAlloc != nil {
a.destroyAllocRunner(gcAlloc.allocRunner, "forced collection")
return
return true
}

a.logger.Printf("[DEBUG] client.gc: alloc %s is invalid or was already garbage collected", allocID)
return false
}

// CollectAll garbage collects all termianated allocations on a node
Expand Down
5 changes: 4 additions & 1 deletion command/agent/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ func (s *HTTPServer) allocGC(allocID string, resp http.ResponseWriter, req *http
return nil, structs.ErrPermissionDenied
}

s.agent.Client().CollectAllocation(allocID)
if !s.agent.Client().CollectAllocation(allocID) {
// Could not find alloc
return nil, fmt.Errorf("unable to collect allocation: not present")
}
return nil, nil
}

Expand Down

0 comments on commit 6c36f76

Please sign in to comment.