GC-ing before we start a new allocation
This commit is contained in:
parent
afdaa979f7
commit
0ffd92668d
|
@ -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)
|
||||
|
|
12
client/gc.go
12
client/gc.go
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
type GCAlloc struct {
|
||||
timeStamp time.Time
|
||||
alloc *AllocRunner
|
||||
allocRunner *AllocRunner
|
||||
index int
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func (i *IndexedGCAllocPQ) Push(ar *AllocRunner) error {
|
|||
}
|
||||
gcAlloc := &GCAlloc{
|
||||
timeStamp: time.Now(),
|
||||
alloc: ar,
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue