diff --git a/nomad/leader.go b/nomad/leader.go index d69478a80..b3964cf8f 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -254,17 +254,9 @@ func (s *Server) schedulePeriodic(stopCh chan struct{}) { // getLatest grabs the latest index from the state store. It returns true if // the index was retrieved successfully. getLatest := func() (uint64, bool) { - // Snapshot the current state - snap, err := s.fsm.State().Snapshot() + snapshotIndex, err := s.fsm.State().LatestIndex() if err != nil { - s.logger.Printf("[ERR] nomad: failed to snapshot state for periodic GC: %v", err) - return 0, false - } - - // Store the snapshot's index - snapshotIndex, err := snap.LatestIndex() - if err != nil { - s.logger.Printf("[ERR] nomad: failed to determine snapshot's index for periodic GC: %v", err) + s.logger.Printf("[ERR] nomad: failed to determine state store's index: %v", err) return 0, false } diff --git a/nomad/system_endpoint.go b/nomad/system_endpoint.go index 46ca15053..3c3e4529d 100644 --- a/nomad/system_endpoint.go +++ b/nomad/system_endpoint.go @@ -18,16 +18,10 @@ func (s *System) GarbageCollect(args *structs.GenericRequest, reply *structs.Gen return err } - // Snapshot the current state - snap, err := s.srv.fsm.State().Snapshot() + // Get the states current index + snapshotIndex, err := s.srv.fsm.State().LatestIndex() if err != nil { - return fmt.Errorf("failed to snapshot state: %v", err) - } - - // Store the snapshot's index - snapshotIndex, err := snap.LatestIndex() - if err != nil { - return fmt.Errorf("failed to determine snapshot's index: %v", err) + return fmt.Errorf("failed to determine state store's index: %v", err) } s.srv.evalBroker.Enqueue(s.srv.coreJobEval(structs.CoreJobForceGC, snapshotIndex)) diff --git a/nomad/worker.go b/nomad/worker.go index 7717600ec..0c414fc90 100644 --- a/nomad/worker.go +++ b/nomad/worker.go @@ -212,19 +212,17 @@ func (w *Worker) sendAck(evalID, token string, ack bool) { // state (attempt to allocate to a failed/dead node), we may need // to sync our state again and do the planning with more recent data. func (w *Worker) waitForIndex(index uint64, timeout time.Duration) error { + // XXX: Potential optimization is to set up a watch on the state stores + // index table and only unblock via a trigger rather than timing out and + // checking. + start := time.Now() defer metrics.MeasureSince([]string{"nomad", "worker", "wait_for_index"}, start) CHECK: - // Snapshot the current state - snap, err := w.srv.fsm.State().Snapshot() + // Get the states current index + snapshotIndex, err := w.srv.fsm.State().LatestIndex() if err != nil { - return fmt.Errorf("failed to snapshot state: %v", err) - } - - // Store the snapshot's index - snapshotIndex, err := snap.LatestIndex() - if err != nil { - return fmt.Errorf("failed to determine snapshot's index: %v", err) + return fmt.Errorf("failed to determine state store's index: %v", err) } // We only need the FSM state to be as recent as the given index