From bc9423e61b5ab2cdcae560084e654a3060fc5fc4 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sat, 20 Feb 2016 11:29:15 -0800 Subject: [PATCH] scheduler: Use AllocsByNodeTerminal to avoid filtering --- scheduler/context.go | 7 ++----- scheduler/scheduler.go | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scheduler/context.go b/scheduler/context.go index 0a765944f..01f61eed9 100644 --- a/scheduler/context.go +++ b/scheduler/context.go @@ -107,15 +107,12 @@ func (e *EvalContext) Reset() { } func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, error) { - // Get the existing allocations - existingAlloc, err := e.state.AllocsByNode(nodeID) + // Get the existing allocations that are non-terminal + existingAlloc, err := e.state.AllocsByNodeTerminal(nodeID, false) if err != nil { return nil, err } - // Filter on alloc state - existingAlloc = structs.FilterTerminalAllocs(existingAlloc) - // Determine the proposed allocation by first removing allocations // that are planned evictions and adding the new allocations. proposed := existingAlloc diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index baed71e73..518280d07 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -63,6 +63,9 @@ type State interface { // AllocsByNode returns all the allocations by node AllocsByNode(node string) ([]*structs.Allocation, error) + // AllocsByNodeTerminal returns all the allocations by node filtering by terminal status + AllocsByNodeTerminal(node string, terminal bool) ([]*structs.Allocation, error) + // GetNodeByID is used to lookup a node by ID NodeByID(nodeID string) (*structs.Node, error)