-
Notifications
You must be signed in to change notification settings - Fork 315
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
Prefered leader #18
Prefered leader #18
Conversation
if (!memberState.isLeader()) { | ||
return; | ||
} | ||
String pid = dLedgerConfig.getPreferredLeaderId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to change pid to peerId
@@ -226,6 +231,10 @@ public void changeRoleToFollower(long term, String leaderId) { | |||
return CompletableFuture.completedFuture(new VoteResponse(request).term(memberState.getLedgerEndTerm()).voteResult(VoteResponse.RESULT.REJECT_TERM_SMALL_THAN_LEDGER)); | |||
} | |||
|
|||
if (!self && isTakingLeadership() && request.getLedgerEndIndex() == memberState.getLedgerEndIndex()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of insurance, compare LedgerEndTerm first.
return; | ||
} | ||
} else { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Role may be follower when term < memberState.getTermToTakeLeadership() , it should not return directly, setting TAKE_LEADERSHIP_FAILED is more appropriate. For example, the node receive heartbeat before term increase as a candidate, it will be follower and term will not increase.
@Jason918 I will merge this PR to branch prefered_leader at first, then make it easier to be polished. |
Preferred Leader implementation.
Also add the leadership transfer command in BossCommand. Using the following command, we can transfer leadership from n0 to n1 on term 1.
java -jar target/DLedger.jar leadershipTransfer -p "n0-localhost:20911;n1-localhost:20912;n2-localhost:20913" -l n0 -t n1 --term 1