GlenGeng commented on a change in pull request #383:
URL: https://github.com/apache/incubator-ratis/pull/383#discussion_r552334420



##########
File path: 
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -104,6 +104,20 @@ public RaftPeerRole getCurrentRole() {
       return getRole().getCurrentRole();
     }
 
+    @Override
+    public boolean isLeader() {

Review comment:
       @runzhiwang  Thanks for the tag. I have following suggestions:
   
   1. I agree that leader should sort the `sendTsWithAck` increasingly, and 
iterate from large to small to pick the `sendTsWithAck` that majority of the 
followers(including himself) has replied the leader as the `startOfLease` .
   2. We can use `LeaderStateImpl#checkLeadership` to calculate and maintain 
the lease, and step down when lease is expired. `isLeader()` might be called 
hundreds or thousands times per second, which would be a potential waste to 
resource. `LeaderStateImpl#checkLeadership` can make leader step down if lease 
is expired, which is more suitable for the semantics of lease.
   3. We may not need the `LEADER_LEASE_TIMEOUT_RATIO_KEY ` at the very 
beginning. What we worry about is the lease is too short to make leader 
unstable, and we can revisit the `clock drift bound` feature later.
   4. To maintain the lease, the follower should withhold its vote if its has 
replied the AppendEntriesRequest, even it meets a RequestVoteRequest with 
higher term and newer raft log. Seems the RequestVote logic is not touched in 
this PR ?
   5. I suggest that leader should step down when the maintained lease is 
expired. From the view of App layer, `isLeaderReady()` means raft server has 
become leader, yet the `appliedLogIndex` of StateMachine has not reach the 
`lastLogIndex`, As soon as `isLeaderReady()` return true, the App layer would 
expect leader not return false during the whole term.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to