You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2019/11/19 15:40:32 UTC

[incubator-ratis] branch master updated: ATIS-748. Follower might not update its commit index. Contributed by Lokesh Jain

This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 2168065  ATIS-748. Follower might not update its commit index.  Contributed by Lokesh Jain
2168065 is described below

commit 216806550f761b639abbb7f5ebe1988ce804a0f6
Author: Tsz Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Tue Nov 19 07:39:56 2019 -0800

    ATIS-748. Follower might not update its commit index.  Contributed by Lokesh Jain
---
 .../src/main/java/org/apache/ratis/server/raftlog/RaftLog.java | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java
index 3bf5f84..a9adb96 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java
@@ -115,15 +115,13 @@ public abstract class RaftLog implements RaftLogSequentialOps, Closeable {
   public boolean updateLastCommitted(long majorityIndex, long currentTerm) {
     try(AutoCloseableLock writeLock = writeLock()) {
       final long oldCommittedIndex = getLastCommittedIndex();
-      if (oldCommittedIndex < majorityIndex) {
+      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(majorityIndex);
+        final TermIndex entry = getTermIndex(newCommitIndex);
         if (entry != null && entry.getTerm() == currentTerm) {
-          final long newCommitIndex = Math.min(majorityIndex, getFlushIndex());
-          if (newCommitIndex > oldCommittedIndex) {
-            commitIndex.updateIncreasingly(newCommitIndex, traceIndexChange);
-          }
+          commitIndex.updateIncreasingly(newCommitIndex, traceIndexChange);
           return true;
         }
       }