szetszwo commented on code in PR #811:
URL: https://github.com/apache/ratis/pull/811#discussion_r1080871181
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java:
##########
@@ -1024,49 +1057,15 @@ private long[] getSorted(List<FollowerInfo>
followerInfos, boolean includeSelf,
return indices;
}
- private void yieldLeaderToHigherPriorityPeer() {
- if (!server.getInfo().isLeader()) {
- return;
- }
-
+ private void checkPeersForYieldingLeader() {
final RaftConfigurationImpl conf = server.getRaftConf();
final RaftPeer leader = conf.getPeer(server.getId());
if (leader == null) {
LOG.error("{} the leader {} is not in the conf {}", this,
server.getId(), conf);
return;
}
- int leaderPriority = leader.getPriority();
-
for (LogAppender logAppender : senders.getSenders()) {
- final FollowerInfo followerInfo = logAppender.getFollower();
- final RaftPeerId followerID = followerInfo.getPeer().getId();
- final RaftPeer follower = conf.getPeer(followerID);
- if (follower == null) {
- if (conf.getPeer(followerID, RaftPeerRole.LISTENER) == null) {
- LOG.error("{} the follower {} is not in the conf {}", this,
followerID, conf);
- }
- continue;
- }
- final int followerPriority = follower.getPriority();
- if (followerPriority <= leaderPriority) {
- continue;
- }
- final TermIndex leaderLastEntry = server.getState().getLastEntry();
- if (leaderLastEntry == null) {
- LOG.info("{} send StartLeaderElectionRequest to follower:{} on term:{}
because follower's priority:{} " +
- "is higher than leader's:{} and leader's lastEntry is null",
- this, followerID, currentTerm, followerPriority, leaderPriority);
-
- sendStartLeaderElectionToHigherPriorityPeer(followerID, null);
- return;
- }
-
- if (followerInfo.getMatchIndex() >= leaderLastEntry.getIndex()) {
- LOG.info("{} send StartLeaderElectionRequest to follower:{} on term:{}
because follower's priority:{} " +
- "is higher than leader's:{} and follower's lastEntry index:{}
catch up with leader's:{}",
- this, followerID, currentTerm, followerPriority, leaderPriority,
followerInfo.getMatchIndex(),
- leaderLastEntry.getIndex());
- sendStartLeaderElectionToHigherPriorityPeer(followerID,
leaderLastEntry);
+ if (sendStartLeaderElection(logAppender.getFollower(),
leader.getPriority())) {
Review Comment:
Sure, this is a good idea!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]