mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1820 from xiang90/fix_storage
raft: fix memory storage
This commit is contained in:
commit
cb74b6812b
@ -179,13 +179,27 @@ func (ms *MemoryStorage) Append(entries []pb.Entry) {
|
|||||||
if len(entries) == 0 {
|
if len(entries) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
offset := entries[0].Index - ms.snapshot.Metadata.Index
|
first := ms.snapshot.Metadata.Index + 1
|
||||||
// do not append out of date entries
|
last := entries[0].Index + uint64(len(entries)) - 1
|
||||||
if offset < 0 {
|
|
||||||
|
// shortcut if there is no new entry.
|
||||||
|
if last < first {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if uint64(len(ms.ents)) > offset {
|
// truncate old entries
|
||||||
ms.ents = append([]pb.Entry{}, ms.ents[:offset]...)
|
if first > entries[0].Index {
|
||||||
|
entries = entries[first-entries[0].Index:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset := entries[0].Index - ms.snapshot.Metadata.Index
|
||||||
|
switch {
|
||||||
|
case uint64(len(ms.ents)) > offset:
|
||||||
|
ms.ents = append([]pb.Entry{}, ms.ents[:offset]...)
|
||||||
ms.ents = append(ms.ents, entries...)
|
ms.ents = append(ms.ents, entries...)
|
||||||
|
case uint64(len(ms.ents)) == offset:
|
||||||
|
ms.ents = append(ms.ents, entries...)
|
||||||
|
default:
|
||||||
|
log.Panicf("missing log entry [last: %d, append at: %d]",
|
||||||
|
ms.snapshot.Metadata.Index+uint64(len(ms.ents)), entries[0].Index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user