raft/raft.go
func (r *raft) maybeCommit() bool {
	// Preserving matchBuf across calls is an optimization
	// used to avoid allocating a new slice on each call.
	if cap(r.matchBuf) < len(r.prs) {
		r.matchBuf = make(uint64Slice, len(r.prs))
	}
	r.matchBuf = r.matchBuf[:len(r.prs)]
	idx := 0
	for _, p := range r.prs {
		r.matchBuf[idx] = p.Match
		idx++
	}
	sort.Sort(&r.matchBuf)
	mci := r.matchBuf[len(r.matchBuf)-r.quorum()]
	return r.raftLog.maybeCommit(mci, r.Term)
}
func (r *raft) maybeCommit() bool {
	// Preserving matchBuf across calls is an optimization
	// used to avoid allocating a new slice on each call.
	if cap(r.matchBuf) < len(r.prs) {
		r.matchBuf = make(uint64Slice, len(r.prs))
	}
	r.matchBuf = r.matchBuf[:len(r.prs)]
	idx := 0
	for _, p := range r.prs {
		r.matchBuf[idx] = p.Match
		idx++
	}
	sort.Sort(&r.matchBuf)
	mci := r.matchBuf[len(r.matchBuf)-r.quorum()]
	return r.raftLog.maybeCommit(mci, r.Term)
}
// maybeCommit attempts to advance the commit index. Returns true if
// the commit index changed (in which case the caller should call
// r.bcastAppend).