From a65e9064b388168af39ac9da8c0c6503a282b48b Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 13 Oct 2016 23:22:02 -0700 Subject: [PATCH] Abort any soon-to-be obsoleted commits during a user restore. --- api.go | 4 ++++ raft.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/api.go b/api.go index 26fb77d2cdc5..5b4a050266a4 100644 --- a/api.go +++ b/api.go @@ -26,6 +26,10 @@ var ( // because it's been deposed in the process. ErrLeadershipLost = errors.New("leadership lost while committing log") + // ErrAbortedByRestore is returned when a leader fails to commit a log + // entry because it's been superseded by a user snapshot restore. + ErrAbortedByRestore = errors.New("snapshot restored while committing log") + // ErrRaftShutdown is returned when operations are requested against an // inactive Raft. ErrRaftShutdown = errors.New("raft is already shutdown") diff --git a/raft.go b/raft.go index fbb0772d202f..98b2ae49c63b 100644 --- a/raft.go +++ b/raft.go @@ -719,6 +719,16 @@ func (r *Raft) restoreUserSnapshot(meta *SnapshotMeta, reader io.ReadCloser) err latestIndex, committedIndex) } + // Cancel any inflight requests. + for { + e := r.leaderState.inflight.Front() + if e == nil { + break + } + e.Value.(*logFuture).respond(ErrAbortedByRestore) + r.leaderState.inflight.Remove(e) + } + // We will overwrite the snapshot metadata with the current term, // an index that's greater than the current index, or the last // index in the snapshot. It's important that we leave a hole in