Skip to content

Commit

Permalink
Merge pull request #14720 from nvanbenschoten/nvanbenschoten/clarifyU…
Browse files Browse the repository at this point in the history
…nstableStableTo
  • Loading branch information
tbg authored Nov 11, 2022
2 parents da619c3 + c18d79d commit 910b81b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions raft/log_unstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@ func (u *unstable) maybeTerm(i uint64) (uint64, bool) {
func (u *unstable) stableTo(i, t uint64) {
gt, ok := u.maybeTerm(i)
if !ok {
// Unstable entry missing. Ignore.
return
}
// if i < offset, term is matched with the snapshot
// only update the unstable entries if term is matched with
// an unstable entry.
if gt == t && i >= u.offset {
u.entries = u.entries[i+1-u.offset:]
u.offset = i + 1
u.shrinkEntriesArray()
if i < u.offset {
// Index matched unstable snapshot, not unstable entry. Ignore.
return
}
if gt != t {
// Term mismatch between unstable entry and specified entry. Ignore.
return
}
u.entries = u.entries[i+1-u.offset:]
u.offset = i + 1
u.shrinkEntriesArray()
}

// shrinkEntriesArray discards the underlying array used by the entries slice
Expand Down

0 comments on commit 910b81b

Please sign in to comment.