Skip to content

Commit

Permalink
nomad: wait for state store to sync in plan apply
Browse files Browse the repository at this point in the history
Wait for state store to catch up with raft when applying plans.
  • Loading branch information
schmichael committed Mar 12, 2019
1 parent 30cb5fd commit 0c45898
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nomad/plan_apply.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nomad

import (
"context"
"fmt"
"runtime"
"time"
Expand Down Expand Up @@ -99,7 +100,9 @@ func (p *planner) planApply() {
// Snapshot the state so that we have a consistent view of the world
// if no snapshot is available
if waitCh == nil || snap == nil {
snap, err = p.fsm.State().Snapshot()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
snap, err = p.fsm.State().SnapshotAfter(ctx, p.raft.LastIndex())
cancel()
if err != nil {
p.logger.Error("failed to snapshot state", "error", err)
pending.respond(nil, err)
Expand Down

0 comments on commit 0c45898

Please sign in to comment.