From 7d67b33219fe428816aa928427009b525df6112f Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Fri, 26 Apr 2019 15:03:32 -0400 Subject: [PATCH] Vendor in-progress etcd/raft optimizations https://github.com/etcd-io/etcd/pull/10679 https://github.com/etcd-io/etcd/pull/10680 https://github.com/etcd-io/etcd/pull/10684 --- vendor/go.etcd.io/etcd/raft/log.go | 6 ++++-- vendor/go.etcd.io/etcd/raft/raft.go | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/vendor/go.etcd.io/etcd/raft/log.go b/vendor/go.etcd.io/etcd/raft/log.go index 03f83e6..77eedfc 100644 --- a/vendor/go.etcd.io/etcd/raft/log.go +++ b/vendor/go.etcd.io/etcd/raft/log.go @@ -332,8 +332,10 @@ func (l *raftLog) slice(lo, hi, maxSize uint64) ([]pb.Entry, error) { if hi > l.unstable.offset { unstable := l.unstable.slice(max(lo, l.unstable.offset), hi) if len(ents) > 0 { - ents = append([]pb.Entry{}, ents...) - ents = append(ents, unstable...) + combined := make([]pb.Entry, len(ents)+len(unstable)) + n := copy(combined, ents) + copy(combined[n:], unstable) + ents = combined } else { ents = unstable } diff --git a/vendor/go.etcd.io/etcd/raft/raft.go b/vendor/go.etcd.io/etcd/raft/raft.go index 61ad12c..71c3749 100644 --- a/vendor/go.etcd.io/etcd/raft/raft.go +++ b/vendor/go.etcd.io/etcd/raft/raft.go @@ -607,14 +607,14 @@ func (r *raft) maybeCommit() bool { if cap(r.matchBuf) < len(r.prs) { r.matchBuf = make(uint64Slice, len(r.prs)) } - mis := r.matchBuf[:len(r.prs)] + r.matchBuf = r.matchBuf[:len(r.prs)] idx := 0 for _, p := range r.prs { - mis[idx] = p.Match + r.matchBuf[idx] = p.Match idx++ } - sort.Sort(mis) - mci := mis[len(mis)-r.quorum()] + sort.Sort(&r.matchBuf) + mci := r.matchBuf[len(r.matchBuf)-r.quorum()] return r.raftLog.maybeCommit(mci, r.Term) } @@ -1005,11 +1005,12 @@ func stepLeader(r *raft, m pb.Message) error { return ErrProposalDropped } - for i, e := range m.Entries { + for i := range m.Entries { + e := &m.Entries[i] if e.Type == pb.EntryConfChange { if r.pendingConfIndex > r.raftLog.applied { r.logger.Infof("propose conf %s ignored since pending unapplied configuration [index %d, applied %d]", - e.String(), r.pendingConfIndex, r.raftLog.applied) + e, r.pendingConfIndex, r.raftLog.applied) m.Entries[i] = pb.Entry{Type: pb.EntryNormal} } else { r.pendingConfIndex = r.raftLog.lastIndex() + uint64(i) + 1