[ 
https://issues.apache.org/jira/browse/RATIS-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16640661#comment-16640661
 ] 

Tsz Wo Nicholas Sze commented on RATIS-341:
-------------------------------------------

>  ..., why do we need to change LeaderState?

In the Raft protocol, leader should send the leader commit index to followers 
so that we should not change LeaderState.  However, I agree that if a follower 
does not have the log flushed, the follower should not update the commit index. 
 Otherwise, it will violate the invariant
{code}
flushedIndex >= commitIndex
{code}
How about changing RaftLog as below?
{code}
@@ -94,8 +94,9 @@ public abstract class RaftLog implements Closeable {
         // paper for details.
         final TermIndex entry = getTermIndex(majorityIndex);
         if (entry != null && entry.getTerm() == currentTerm) {
-          LOG.debug("{}: Updating lastCommitted to {}", selfId, majorityIndex);
-          lastCommitted.set(majorityIndex);
+          final long commitIndex = Math.min(majorityIndex, 
getLatestFlushedIndex());
+          LOG.debug("{}: Updating lastCommitted to {}", selfId, commitIndex);
+          lastCommitted.set(commitIndex);
           return true;
         }
       }
{code}


> Raft log index on the follower should be applied to state machine only after 
> writing the log
> --------------------------------------------------------------------------------------------
>
>                 Key: RATIS-341
>                 URL: https://issues.apache.org/jira/browse/RATIS-341
>             Project: Ratis
>          Issue Type: Bug
>          Components: server
>    Affects Versions: 0.3.0
>            Reporter: Mukul Kumar Singh
>            Assignee: Mukul Kumar Singh
>            Priority: Major
>             Fix For: 0.3.0
>
>         Attachments: RATIS-341.002.patch
>
>
> In follower, RaftServerImpl#appendEntriesAsync, entries should only be 
> applied to state machine
> only after writing the log to the state machine.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to