GC-ing before we start a new allocation

This commit is contained in:
Diptanu Choudhury 2016-12-11 22:40:11 -08:00
parent afdaa979f7
commit 0ffd92668d
2 changed files with 14 additions and 9 deletions

View file

@ -1792,6 +1792,11 @@ func (c *Client) addAlloc(alloc *structs.Allocation, prevAllocDir *allocdir.Allo
return nil
}
// Make room for the allocation
if err := c.garbageCollector.MakeRoomFor([]*structs.Allocation{alloc}); err != nil {
c.logger.Printf("[ERR] client: error making room for allocation: %v", err)
}
c.configLock.RLock()
ar := NewAllocRunner(c.logger, c.configCopy, c.updateAllocStatus, alloc, c.vaultClient)
ar.SetPreviousAllocDir(prevAllocDir)

View file

@ -11,9 +11,9 @@ import (
)
type GCAlloc struct {
timeStamp time.Time
alloc *AllocRunner
index int
timeStamp time.Time
allocRunner *AllocRunner
index int
}
type GCAllocPQImpl []*GCAlloc
@ -68,8 +68,8 @@ func (i *IndexedGCAllocPQ) Push(ar *AllocRunner) error {
return fmt.Errorf("alloc %v already being tracked for GC", alloc.ID)
}
gcAlloc := &GCAlloc{
timeStamp: time.Now(),
alloc: ar,
timeStamp: time.Now(),
allocRunner: ar,
}
i.index[alloc.ID] = gcAlloc
heap.Push(&i.heap, gcAlloc)
@ -82,7 +82,7 @@ func (i *IndexedGCAllocPQ) Pop() *GCAlloc {
}
gcAlloc := heap.Pop(&i.heap).(*GCAlloc)
delete(i.index, gcAlloc.alloc.Alloc().ID)
delete(i.index, gcAlloc.allocRunner.Alloc().ID)
return gcAlloc
}
@ -123,7 +123,7 @@ func (a *AllocGarbageCollector) Collect(allocID string) error {
return fmt.Errorf("unable to collect allocation %q: %v", allocID, err)
}
ar := gcAlloc.alloc
ar := gcAlloc.allocRunner
a.logger.Printf("[INFO] client: garbage collecting allocation %q", ar.Alloc().ID)
ar.Destroy()
@ -137,7 +137,7 @@ func (a *AllocGarbageCollector) CollectAll() error {
if gcAlloc == nil {
break
}
ar := gcAlloc.alloc
ar := gcAlloc.allocRunner
a.logger.Printf("[INFO] client: garbage collecting alloc runner for alloc %q", ar.Alloc().ID)
ar.Destroy()
}
@ -161,7 +161,7 @@ func (a *AllocGarbageCollector) MakeRoomFor(allocations []*structs.Allocation) e
break
}
ar := gcAlloc.alloc
ar := gcAlloc.allocRunner
alloc := ar.Alloc()
ar.Destroy()
diskCleared += alloc.Resources.DiskMB