[ 
https://issues.apache.org/jira/browse/RATIS-1161?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Attila Doroszlai updated RATIS-1161:
------------------------------------
    Fix Version/s: 2.0.0
                       (was: 1.1.0)

> Updating commit index of follower does not require term check.
> --------------------------------------------------------------
>
>                 Key: RATIS-1161
>                 URL: https://issues.apache.org/jira/browse/RATIS-1161
>             Project: Ratis
>          Issue Type: Improvement
>          Components: server
>    Affects Versions: 1.1.0
>            Reporter: Glen Geng
>            Assignee: Tsz-wo Sze
>            Priority: Minor
>             Fix For: 2.0.0
>
>         Attachments: 截屏2020-11-17 下午8.31.38.png
>
>          Time Spent: 5h 40m
>  Remaining Estimate: 0h
>
> This is a followup of Jira https://issues.apache.org/jira/browse/RATIS-748
>  
> According to the basic raft algorithm, the logic of advancing commit index 
> for follower and leader is different.
> *For follower:*
> When receiving an AppendEntries Request, the logic is 
> {code:java}
> If leaderCommit > commitIndex: set commitIndex = min(leaderCommit, index of 
> last new entry)
> {code}
>  
> *For leader:*
> The majority commit should only be used on the log entry that created by 
> current leader, thus need a term check.
> {code:java}
> If there exists an N such that N > commitIndex, a majority of matchIndex[i] ≥ 
> N, and log[N].term == currentTerm: set commitIndex = N{code}
>  
> *For current ratis:*
> We apply the advancing commit index logic of leader to follower, which will 
> make follower's commit index to lag behind for situations like:
> 1, when failover happened
> 2, it is an empty follower that join the raft group by membership change.
> {code:java}
>   /**
>    * Update the last committed index.
>    * @param majorityIndex the index that has achieved majority.
>    * @param currentTerm the current term.
>    * @return true if update is applied; otherwise, return false, i.e. no 
> update required.
>    */
>   public boolean updateLastCommitted(long majorityIndex, long currentTerm) {
>     try(AutoCloseableLock writeLock = writeLock()) {
>       final long oldCommittedIndex = getLastCommittedIndex();
>       final long newCommitIndex = Math.min(majorityIndex, getFlushIndex());
>       if (oldCommittedIndex < newCommitIndex) {
>         // Only update last committed index for current term. See §5.4.2 in
>         // paper for details.
>         final TermIndex entry = getTermIndex(newCommitIndex);
>         if (entry != null && entry.getTerm() == currentTerm) {
>           commitIndex.updateIncreasingly(newCommitIndex, traceIndexChange);
>           return true;
>         }
>       }
>     }
>     return false;
>   }
> {code}
>  
> *Intention of this Jira*
> We want to prove the we can safely change the advancing commit index logic of 
> follower for current ratis.
>  
>   



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to