Skip to content

Commit

Permalink
Abort any soon-to-be obsoleted commits during a user restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
slackpad committed Oct 14, 2016
1 parent 7c09f49 commit a65e906
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a65e906

Please sign in to comment.