From 69ba495f0ca37171f30a339ce48f83b89fe9f711 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 26 Jun 2019 08:49:24 -0700 Subject: [PATCH] nomad: expand comments on subtle plan apply behaviors --- nomad/plan_apply.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nomad/plan_apply.go b/nomad/plan_apply.go index 4d9fccc08..27368f447 100644 --- a/nomad/plan_apply.go +++ b/nomad/plan_apply.go @@ -104,7 +104,8 @@ func (p *planner) planApply() { select { case idx := <-planIndexCh: // Previous plan committed. Discard snapshot and ensure - // future snapshots include this plan. + // future snapshots include this plan. idx may be 0 if + // plan failed to apply, so use max(prev, idx) prevPlanResultIndex = max(prevPlanResultIndex, idx) planIndexCh = nil snap = nil @@ -112,7 +113,9 @@ func (p *planner) planApply() { } if snap != nil { - // If snapshot isn't new enough, discard it + // If snapshot doesn't contain the previous plan + // result's index and the current plan's snapshot it, + // discard it and get a new one below. minIndex := max(prevPlanResultIndex, pending.plan.SnapshotIndex) if idx, err := snap.LatestIndex(); err != nil || idx < minIndex { snap = nil @@ -120,7 +123,10 @@ func (p *planner) planApply() { } // Snapshot the state so that we have a consistent view of the world - // if no snapshot is available + // if no snapshot is available. + // - planIndexCh will be nil if the previous plan result applied + // during Dequeue + // - snap will be nil if its index < max(prevIndex, curIndex) if planIndexCh == nil || snap == nil { snap, err = p.snapshotMinIndex(prevPlanResultIndex, pending.plan.SnapshotIndex) if err != nil {