|
@@ -101,23 +101,23 @@ func (u *unstable) restore(s pb.Snapshot) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (u *unstable) truncateAndAppend(ents []pb.Entry) {
|
|
func (u *unstable) truncateAndAppend(ents []pb.Entry) {
|
|
|
- after := ents[0].Index - 1
|
|
|
|
|
|
|
+ after := ents[0].Index
|
|
|
switch {
|
|
switch {
|
|
|
- case after == u.offset+uint64(len(u.entries))-1:
|
|
|
|
|
- // after is the last index in the u.entries
|
|
|
|
|
|
|
+ case after == u.offset+uint64(len(u.entries)):
|
|
|
|
|
+ // after is the next index in the u.entries
|
|
|
// directly append
|
|
// directly append
|
|
|
u.entries = append(u.entries, ents...)
|
|
u.entries = append(u.entries, ents...)
|
|
|
- case after < u.offset:
|
|
|
|
|
- u.logger.Infof("replace the unstable entries from index %d", after+1)
|
|
|
|
|
|
|
+ case after <= u.offset:
|
|
|
|
|
+ u.logger.Infof("replace the unstable entries from index %d", after)
|
|
|
// The log is being truncated to before our current offset
|
|
// The log is being truncated to before our current offset
|
|
|
// portion, so set the offset and replace the entries
|
|
// portion, so set the offset and replace the entries
|
|
|
- u.offset = after + 1
|
|
|
|
|
|
|
+ u.offset = after
|
|
|
u.entries = ents
|
|
u.entries = ents
|
|
|
default:
|
|
default:
|
|
|
// truncate to after and copy to u.entries
|
|
// truncate to after and copy to u.entries
|
|
|
// then append
|
|
// then append
|
|
|
- u.logger.Infof("truncate the unstable entries to index %d", after)
|
|
|
|
|
- u.entries = append([]pb.Entry{}, u.slice(u.offset, after+1)...)
|
|
|
|
|
|
|
+ u.logger.Infof("truncate the unstable entries before index %d", after)
|
|
|
|
|
+ u.entries = append([]pb.Entry{}, u.slice(u.offset, after)...)
|
|
|
u.entries = append(u.entries, ents...)
|
|
u.entries = append(u.entries, ents...)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|