mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: get rid of allocation
This commit is contained in:
parent
e4c0f5c1a8
commit
96de9776b7
@ -272,11 +272,16 @@ func (l *raftLog) slice(lo uint64, hi uint64) []pb.Entry {
|
||||
} else if err != nil {
|
||||
panic(err) // TODO(bdarnell)
|
||||
}
|
||||
ents = append(ents, storedEnts...)
|
||||
ents = storedEnts
|
||||
}
|
||||
if hi > l.unstable.offset {
|
||||
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
|
||||
}
|
||||
|
@ -407,12 +407,10 @@ func (r *raft) poll(id uint64, v bool) (granted int) {
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Printf("raft: %x is starting a new election at term %d", r.id, r.Term)
|
||||
r.campaign()
|
||||
r.Commit = r.raftLog.committed
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -434,6 +432,7 @@ func (r *raft) Step(m pb.Message) error {
|
||||
return nil
|
||||
}
|
||||
r.step(r, m)
|
||||
r.Commit = r.raftLog.committed
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user