You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "Tsz-wo Sze (Jira)" <ji...@apache.org> on 2020/11/19 06:21:00 UTC
[jira] [Assigned] (RATIS-1161) Updating commit index of follower
does not require term check.
[ https://issues.apache.org/jira/browse/RATIS-1161?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tsz-wo Sze reassigned RATIS-1161:
---------------------------------
Assignee: Tsz-wo Sze
[~glengeng], thanks a lot for filing this JIRA and the detailed description.
> 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
> Attachments: 截屏2020-11-17 下午8.31.38.png
>
>
> 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.3.4#803005)