Merge pull request #14720 from nvanbenschoten/nvanbenschoten/clarifyUnstableStableTo

This commit is contained in:
Tobias Grieger 2022-11-11 16:25:37 +01:00 committed by GitHub
commit 910b81b153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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