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

Prefered leader #18

Merged
merged 10 commits into from
May 24, 2019
Merged

Conversation

Jason918
Copy link
Member

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

if (!memberState.isLeader()) {
return;
}
String pid = dLedgerConfig.getPreferredLeaderId();
Copy link
Contributor

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()) {
Copy link
Contributor

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;
Copy link
Contributor

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.

@dongeforever dongeforever changed the base branch from master to prefered_leader May 24, 2019 10:03
@dongeforever
Copy link
Member

@Jason918 I will merge this PR to branch prefered_leader at first, then make it easier to be polished.

@dongeforever dongeforever merged commit 425a232 into openmessaging:prefered_leader May 24, 2019
@RongtongJin RongtongJin added this to the 0.2.0 milestone Jul 18, 2020
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

Successfully merging this pull request may close these issues.

3 participants