Skip to content

Commit

Permalink
scheduler: stopped-yet-running allocs are still running
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Apr 25, 2021
1 parent accf39a commit c79161e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nomad/structs/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi
// For each alloc, add the resources
for _, alloc := range allocs {
// Do not consider the resource impact of terminal allocations
if alloc.TerminalStatus() {
if alloc.ClientTerminalStatus() {
continue
}

Expand Down
2 changes: 2 additions & 0 deletions nomad/structs/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func TestAllocsFit_TerminalAlloc_Old(t *testing.T) {
// Should fit second allocation since it is terminal
a2 := a1.Copy()
a2.DesiredStatus = AllocDesiredStatusStop
a2.ClientStatus = AllocClientStatusComplete
fit, _, used, err = AllocsFit(n, []*Allocation{a1, a2}, nil, false)
require.NoError(err)
require.True(fit)
Expand Down Expand Up @@ -479,6 +480,7 @@ func TestAllocsFit_TerminalAlloc(t *testing.T) {
// Should fit second allocation since it is terminal
a2 := a1.Copy()
a2.DesiredStatus = AllocDesiredStatusStop
a2.ClientStatus = AllocClientStatusComplete
fit, dim, used, err := AllocsFit(n, []*Allocation{a1, a2}, nil, false)
require.NoError(err)
require.True(fit, dim)
Expand Down
2 changes: 1 addition & 1 deletion nomad/structs/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (idx *NetworkIndex) SetNode(node *Node) (collide bool) {
func (idx *NetworkIndex) AddAllocs(allocs []*Allocation) (collide bool) {
for _, alloc := range allocs {
// Do not consider the resource impact of terminal allocations
if alloc.TerminalStatus() {
if alloc.ClientTerminalStatus() {
continue
}

Expand Down
6 changes: 5 additions & 1 deletion scheduler/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (e *EvalContext) Reset() {
func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, error) {
// Get the existing allocations that are non-terminal
ws := memdb.NewWatchSet()
proposed, err := e.state.AllocsByNodeTerminal(ws, nodeID, false)
proposed, err := e.state.AllocsByNode(ws, nodeID)
if err != nil {
return nil, err
}
Expand All @@ -141,6 +141,10 @@ func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, erro
// update occurs, we do not double count and we override the old allocation.
proposedIDs := make(map[string]*structs.Allocation, len(proposed))
for _, alloc := range proposed {
if alloc.ClientTerminalStatus() {
continue
}

proposedIDs[alloc.ID] = alloc
}
for _, alloc := range e.plan.NodeAllocation[nodeID] {
Expand Down

0 comments on commit c79161e

Please sign in to comment.