From 2e6b1cdf957714aabc08f17a1c1f8d09ffa9cee3 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sat, 15 Aug 2015 17:42:51 -0700 Subject: [PATCH] nomad: Integrate Eval GC with FSM time table --- nomad/core_sched.go | 11 ++++++++--- nomad/core_sched_test.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nomad/core_sched.go b/nomad/core_sched.go index edd62212c..0162ffccf 100644 --- a/nomad/core_sched.go +++ b/nomad/core_sched.go @@ -2,6 +2,7 @@ package nomad import ( "fmt" + "time" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" @@ -43,10 +44,14 @@ func (c *CoreScheduler) evalGC(eval *structs.Evaluation) error { return err } - // TODO: compute the old threshold limit for GC. - // This is a rough mapping of a time duration to the + // Compute the old threshold limit for GC using the FSM + // time table. This is a rough mapping of a time to the // Raft index it belongs to. - var oldThreshold uint64 = eval.ModifyIndex + tt := c.srv.fsm.TimeTable() + cutoff := time.Now().UTC().Add(-1 * c.srv.config.EvalGCThreshold) + oldThreshold := tt.NearestIndex(cutoff) + c.srv.logger.Printf("[DEBUG] sched.core: eval GC: scanning before index %d (%v)", + oldThreshold, c.srv.config.EvalGCThreshold) // Collect the allocations and evaluations to GC var gcAlloc, gcEval []string diff --git a/nomad/core_sched_test.go b/nomad/core_sched_test.go index 823c507f4..416f12def 100644 --- a/nomad/core_sched_test.go +++ b/nomad/core_sched_test.go @@ -2,6 +2,7 @@ package nomad import ( "testing" + "time" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -31,6 +32,10 @@ func TestCoreScheduler_EvalGC(t *testing.T) { t.Fatalf("err: %v", err) } + // Update the time tables to make this work + tt := s1.fsm.TimeTable() + tt.Witness(2000, time.Now().UTC().Add(-1*s1.config.EvalGCThreshold)) + // Create a core scheduler snap, err := state.Snapshot() if err != nil {