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

发现个可能有问题的地方。 #21

Open
fspore opened this issue Nov 25, 2019 · 1 comment
Open

发现个可能有问题的地方。 #21

fspore opened this issue Nov 25, 2019 · 1 comment

Comments

@fspore
Copy link

fspore commented Nov 25, 2019

com.github.wenweihu86.raft.RaftNode#advanceCommitIndex
方法里的这行:
Arrays.sort(matchIndexes);

这里 sort 的时候, 升序应该不是正确的。要用降序。
考虑:
peerNum: 4
leader_last_log_idx: 3
follower match indexes:
peer1: 2
peer2: 1
peer3: 0

升序的话:
[0,1,2,3] 即可能的新 commitIdx = idxes[4/2] = 2
降序的话:
[3,2,1,0] 即可能的新 commitIdx = idxes[4/2] = 1
而 1 才是正确的。4 个 node 的话, 要 quorum >= 3

只是当 peerNum 为奇数时, 升降序的效果刚好一样罢了。

@wenweihu86
Copy link
Owner

peerNum要求是奇数。

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

2 participants