mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: move good case of truncateAndAppend to the first place
This commit is contained in:
parent
411063e14f
commit
b7ca56e3c8
@ -105,16 +105,16 @@ func (u *unstable) restore(s pb.Snapshot) {
|
|||||||
|
|
||||||
func (u *unstable) truncateAndAppend(after uint64, ents []pb.Entry) {
|
func (u *unstable) truncateAndAppend(after uint64, ents []pb.Entry) {
|
||||||
switch {
|
switch {
|
||||||
|
case after == u.offset+uint64(len(u.entries))-1:
|
||||||
|
// after is the last index in the u.entries
|
||||||
|
// directly append
|
||||||
|
u.entries = append(u.entries, ents...)
|
||||||
case after < u.offset:
|
case after < u.offset:
|
||||||
log.Printf("raftlog: replace the unstable entries from index %d", after+1)
|
log.Printf("raftlog: replace the unstable entries from index %d", after+1)
|
||||||
// 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 + 1
|
||||||
u.entries = ents
|
u.entries = ents
|
||||||
case after == u.offset+uint64(len(u.entries))-1:
|
|
||||||
// after is the last index in the u.entries
|
|
||||||
// directly append
|
|
||||||
u.entries = append(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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user