Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization:add preTermLastlog index to accelerate the find hintIndex #180

Open
1797818494 opened this issue Mar 8, 2024 · 0 comments

Comments

@1797818494
Copy link

1797818494 commented Mar 8, 2024

Now etcd raft find hintindex slowly

func (l *raftLog) findConflictByTerm(index uint64, term uint64) (uint64, uint64) {
	for ; index > 0; index-- {
		// If there is an error (likely ErrCompacted or ErrUnavailable), we don't
		// know whether it's a match or not, so assume a possible match and return
		// the index, with 0 term indicating an unknown term.
		if ourTerm, err := l.term(index); err != nil {
			return index, 0
		} else if ourTerm <= term {
			return index, ourTerm
		}
	}
	return 0, 0
}

But when PreVote and checkQuorum is enable, one electionTimeout's log may be the stale log When partition happened.This is common.And When network recover, the follower will search many logs. And When PreVote and CheckQuorum is enable, there is only one term logs will be stale in the most cases. So I think there is a need to add preTermLastLog to accelerate this.For example:

func (l *raftLog) findConflictByTerm(index uint64, term uint64) (uint64, uint64) {
	if l.preTermLastIndex > 0 {
		return l.preTermLastIndex, l.preTerm 
	}
	for ; index > 0; index-- {
		// If there is an error (likely ErrCompacted or ErrUnavailable), we don't
		// know whether it's a match or not, so assume a possible match and return
		// the index, with 0 term indicating an unknown term.
		if ourTerm, err := l.term(index); err != nil {
			return index, 0
		} else if ourTerm <= term {
			return index, ourTerm
		}
	}
	return 0, 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant