Skip to content

Commit

Permalink
Ensure comparison of creation to modification index and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stswidwinski committed Nov 1, 2022
1 parent c725c1b commit 721bb72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions nomad/core_sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64,
// If the batch job doesn't exist we can GC it regardless of allowBatch
if !collect {
// Find allocs associated with older (based on createindex) and GC them if terminal
oldAllocs := olderVersionTerminalAllocs(allocs, job)
oldAllocs := olderVersionTerminalAllocs(allocs)
return false, oldAllocs, nil
}
}
Expand All @@ -346,10 +346,10 @@ func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64,

// olderVersionTerminalAllocs returns terminal allocations whose job create index
// is older than the job's create index
func olderVersionTerminalAllocs(allocs []*structs.Allocation, job *structs.Job) []string {
func olderVersionTerminalAllocs(allocs []*structs.Allocation) []string {
var ret []string
for _, alloc := range allocs {
if alloc.Job != nil && alloc.Job.CreateIndex < job.CreateIndex && alloc.TerminalStatus() {
if alloc.Job != nil && alloc.CreateIndex < alloc.Job.ModifyIndex && alloc.TerminalStatus() {
ret = append(ret, alloc.ID)
}
}
Expand Down
15 changes: 9 additions & 6 deletions nomad/core_sched_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,21 @@ func TestCoreScheduler_EvalGC_Batch_OldVersion(t *testing.T) {
alloc2.DesiredStatus = structs.AllocDesiredStatusRun
alloc2.ClientStatus = structs.AllocClientStatusLost

// Insert alloc with older job modifyindex
err = store.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2})
if err != nil {
t.Fatalf("err: %v", err)
}

// Insert alloc with indexes older job modifyindex
alloc3 := mock.Alloc()
job2 := job.Copy()

alloc3.Job = job2
alloc3.JobID = job2.ID
alloc3.Job = job
alloc3.JobID = job.ID
alloc3.EvalID = eval.ID
job2.CreateIndex = 500
alloc3.DesiredStatus = structs.AllocDesiredStatusRun
alloc3.ClientStatus = structs.AllocClientStatusLost

err = store.UpsertAllocs(structs.MsgTypeTestSetup, 1002, []*structs.Allocation{alloc, alloc2, alloc3})
err = store.UpsertAllocs(structs.MsgTypeTestSetup, job.ModifyIndex - 1, []*structs.Allocation{alloc3})
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down

0 comments on commit 721bb72

Please sign in to comment.