Merge pull request #1908 from bdarnell/error-fixes

raft: remove panic when we see a proposal with no leader.
This commit is contained in:
Xiang Li 2014-12-11 13:58:51 -08:00
commit 2c2e032155
2 changed files with 8 additions and 5 deletions

View File

@ -482,7 +482,8 @@ func stepLeader(r *raft, m pb.Message) {
func stepCandidate(r *raft, m pb.Message) {
switch m.Type {
case pb.MsgProp:
panic("no leader")
log.Printf("raft: %x no leader at term %d; dropping proposal", r.id, r.Term)
return
case pb.MsgApp:
r.becomeFollower(r.Term, m.From)
r.handleAppendEntries(m)
@ -513,7 +514,8 @@ func stepFollower(r *raft, m pb.Message) {
switch m.Type {
case pb.MsgProp:
if r.lead == None {
panic("no leader")
log.Printf("raft: %x no leader at term %d; dropping proposal", r.id, r.Term)
return
}
m.To = r.lead
r.send(m)

View File

@ -180,18 +180,18 @@ func (ms *MemoryStorage) Compact(i uint64, cs *pb.ConfState, data []byte) error
}
// Append the new entries to storage.
func (ms *MemoryStorage) Append(entries []pb.Entry) {
func (ms *MemoryStorage) Append(entries []pb.Entry) error {
ms.Lock()
defer ms.Unlock()
if len(entries) == 0 {
return
return nil
}
first := ms.snapshot.Metadata.Index + 1
last := entries[0].Index + uint64(len(entries)) - 1
// shortcut if there is no new entry.
if last < first {
return
return nil
}
// truncate old entries
if first > entries[0].Index {
@ -209,4 +209,5 @@ func (ms *MemoryStorage) Append(entries []pb.Entry) {
log.Panicf("missing log entry [last: %d, append at: %d]",
ms.snapshot.Metadata.Index+uint64(len(ms.ents)), entries[0].Index)
}
return nil
}