mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1897 from xiang90/raft
raft: get rid of the using of defer in critical path
This commit is contained in:
commit
89cba625d6
@ -272,11 +272,16 @@ func (l *raftLog) slice(lo uint64, hi uint64) []pb.Entry {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
panic(err) // TODO(bdarnell)
|
panic(err) // TODO(bdarnell)
|
||||||
}
|
}
|
||||||
ents = append(ents, storedEnts...)
|
ents = storedEnts
|
||||||
}
|
}
|
||||||
if hi > l.unstable.offset {
|
if hi > l.unstable.offset {
|
||||||
unstable := l.unstable.slice(max(lo, l.unstable.offset), hi)
|
unstable := l.unstable.slice(max(lo, l.unstable.offset), hi)
|
||||||
ents = append(ents, unstable...)
|
if len(ents) > 0 {
|
||||||
|
ents = append([]pb.Entry{}, ents...)
|
||||||
|
ents = append(ents, unstable...)
|
||||||
|
} else {
|
||||||
|
ents = unstable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ents
|
return ents
|
||||||
}
|
}
|
||||||
|
@ -410,12 +410,10 @@ func (r *raft) poll(id uint64, v bool) (granted int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *raft) Step(m pb.Message) error {
|
func (r *raft) Step(m pb.Message) error {
|
||||||
// TODO(bmizerany): this likely allocs - prevent that.
|
|
||||||
defer func() { r.Commit = r.raftLog.committed }()
|
|
||||||
|
|
||||||
if m.Type == pb.MsgHup {
|
if m.Type == pb.MsgHup {
|
||||||
log.Printf("raft: %x is starting a new election at term %d", r.id, r.Term)
|
log.Printf("raft: %x is starting a new election at term %d", r.id, r.Term)
|
||||||
r.campaign()
|
r.campaign()
|
||||||
|
r.Commit = r.raftLog.committed
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,6 +435,7 @@ func (r *raft) Step(m pb.Message) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
r.step(r, m)
|
r.step(r, m)
|
||||||
|
r.Commit = r.raftLog.committed
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user