Disallow GC of parameterized jobs

This PR makes it so parameterized jobs do not get garbage collected and
adds a test.
This commit is contained in:
Alex Dadgar 2017-01-26 11:57:32 -08:00
parent 0933bcadf9
commit 7f9c6466d4
3 changed files with 65 additions and 2 deletions

View File

@ -192,6 +192,8 @@ func (c *CoreScheduler) evalGC(eval *structs.Evaluation) error {
// The Evaluation GC should not handle batch jobs since those need to be
// garbage collected in one shot
// XXX believe there is a bug that if a batch job gets stopped, there is no
// way for it to GC the eval/allocs
gc, allocs, err := c.gcEval(eval, oldThreshold, false)
if err != nil {
return err

View File

@ -965,6 +965,66 @@ func TestCoreScheduler_JobGC_Force(t *testing.T) {
}
}
// This test ensures parameterized and periodic jobs don't get GCd
func TestCoreScheduler_JobGC_NonGCable(t *testing.T) {
s1 := testServer(t, nil)
defer s1.Shutdown()
testutil.WaitForLeader(t, s1.RPC)
// COMPAT Remove in 0.6: Reset the FSM time table since we reconcile which sets index 0
s1.fsm.timetable.table = make([]TimeTableEntry, 1, 10)
// Insert a parameterized job.
state := s1.fsm.State()
job := mock.Job()
job.Type = structs.JobTypeBatch
job.Status = structs.JobStatusRunning
job.ParameterizedJob = &structs.ParameterizedJobConfig{
Payload: structs.DispatchPayloadRequired,
}
err := state.UpsertJob(1000, job)
if err != nil {
t.Fatalf("err: %v", err)
}
// Insert a periodic job.
job2 := mock.PeriodicJob()
if err := state.UpsertJob(1001, job2); err != nil {
t.Fatalf("err: %v", err)
}
// Create a core scheduler
snap, err := state.Snapshot()
if err != nil {
t.Fatalf("err: %v", err)
}
core := NewCoreScheduler(s1, snap)
// Attempt the GC
gc := s1.coreJobEval(structs.CoreJobForceGC, 1002)
err = core.Process(gc)
if err != nil {
t.Fatalf("err: %v", err)
}
// Should still exist
out, err := state.JobByID(job.ID)
if err != nil {
t.Fatalf("err: %v", err)
}
if out == nil {
t.Fatalf("bad: %v", out)
}
outE, err := state.JobByID(job2.ID)
if err != nil {
t.Fatalf("err: %v", err)
}
if outE == nil {
t.Fatalf("bad: %v", outE)
}
}
func TestCoreScheduler_PartitionReap(t *testing.T) {
s1 := testServer(t, nil)
defer s1.Shutdown()

View File

@ -149,9 +149,10 @@ func jobIsGCable(obj interface{}) (bool, error) {
return false, fmt.Errorf("Unexpected type: %v", obj)
}
// The job is GCable if it is batch and it is not periodic
// The job is GCable if it is batch, it is not periodic and is not a
// parameterized job.
periodic := j.Periodic != nil && j.Periodic.Enabled
gcable := j.Type == structs.JobTypeBatch && !periodic
gcable := j.Type == structs.JobTypeBatch && !periodic && !j.IsParameterized()
return gcable, nil
}