Removing the alloc runner from GC if it is destroyed by the server

This commit is contained in:
Diptanu Choudhury
2016-12-20 11:14:22 -08:00
parent 7ebe4a6972
commit 6f978dd051
2 changed files with 15 additions and 0 deletions

View File

@@ -1759,6 +1759,9 @@ func (c *Client) removeAlloc(alloc *structs.Allocation) error {
delete(c.allocs, alloc.ID)
c.allocLock.Unlock()
// Remove the allocrunner from garbage collector
c.garbageCollector.Remove(ar)
ar.Destroy()
return nil
}

View File

@@ -329,3 +329,15 @@ func (a *AllocGarbageCollector) MarkForCollection(ar *AllocRunner) error {
a.logger.Printf("[INFO] client: marking allocation %v for GC", ar.Alloc().ID)
return a.allocRunners.Push(ar)
}
// Remove removes an alloc runner without garbage collecting it
func (a *AllocGarbageCollector) Remove(ar *AllocRunner) {
if ar == nil || ar.Alloc() == nil {
return
}
alloc := ar.Alloc()
if _, err := a.allocRunners.Remove(alloc.ID); err == nil {
a.logger.Printf("[INFO] client: removed alloc runner %v from garbage collector", alloc.ID)
}
}