You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by William Song <sz...@163.com> on 2023/01/09 16:24:09 UTC

MatchIndex is not properly initialized

Hi dev,

I noticed that matchIndex in leaderStateImpl in initialized with value 0[1] and I think it is incorrect. 

As the Raft Paper[2] states, matchIndex is 'for each server, index of highest log entry known to be replicated on server’.

 0 is considered to be a valid Raft Log index in Ratis, and if we initialize matchIndex to 0, the very first log entry will become committed as soon as it is flushed into leader’s LogSegment, instead of after receiving majority ack responses.

Therefore, I think the correct initialization value for match index is -1. Existing CI passed with -1: 
https://github.com/apache/ratis/actions/runs/3875583646. What do you think?

Regards,
William Song


[1] https://github.com/apache/ratis/blob/d45dccc09c34d9dc51c52c6b14b468b2641692c2/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerInfoImpl.java#L40
[2] https://raft.github.io/raft.pdf 

Re: MatchIndex is not properly initialized

Posted by Tsz Wo Sze <sz...@gmail.com>.
Hi William,

I agree that it is better to initialize matchIndex to -1
(INVALID_LOG_INDEX).  Good catch!  Would you like to submit a pull request?

Tsz-Wo


On Tue, Jan 10, 2023 at 12:24 AM William Song <sz...@163.com> wrote:

> Hi dev,
>
> I noticed that matchIndex in leaderStateImpl in initialized with value
> 0[1] and I think it is incorrect.
>
> As the Raft Paper[2] states, matchIndex is 'for each server, index of
> highest log entry known to be replicated on server’.
>
>  0 is considered to be a valid Raft Log index in Ratis, and if we
> initialize matchIndex to 0, the very first log entry will become committed
> as soon as it is flushed into leader’s LogSegment, instead of after
> receiving majority ack responses.
>
> Therefore, I think the correct initialization value for match index is -1.
> Existing CI passed with -1:
> https://github.com/apache/ratis/actions/runs/3875583646. What do you
> think?
>
> Regards,
> William Song
>
>
> [1]
> https://github.com/apache/ratis/blob/d45dccc09c34d9dc51c52c6b14b468b2641692c2/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerInfoImpl.java#L40
> [2] https://raft.github.io/raft.pdf