[ https://issues.apache.org/jira/browse/RATIS-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16659089#comment-16659089 ]
Tsz Wo Nicholas Sze commented on RATIS-363: ------------------------------------------- Just found a bug -- stopIndex is better to use Long since raftLog.getLastCommittedIndex() may return -1. In such case, updater.join() may not return since the updater thread is stuck in wait(). Some tests may fail; e.g. https://builds.apache.org/job/PreCommit-RATIS-Build/434/testReport/org.apache.ratis/TestRaftServerLeaderElectionTimeout/testLeaderElectionDetection/ {code} +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java @@ -44,7 +44,7 @@ import java.util.concurrent.CompletableFuture; */ class StateMachineUpdater implements Runnable { static final Logger LOG = LoggerFactory.getLogger(StateMachineUpdater.class); - private volatile long stopIndex = -1; + private volatile Long stopIndex = null; enum State { RUNNING, STOP, RELOAD @@ -100,13 +100,13 @@ class StateMachineUpdater implements Runnable { * * @throws InterruptedException */ - public void stopAndJoin() - throws InterruptedException { - if (stopIndex == -1) { + void stopAndJoin() throws InterruptedException { + if (stopIndex == null) { synchronized (this) { this.stopIndex = raftLog.getLastCommittedIndex(); notifyUpdater(); } + LOG.info("{}: set stopIndex = {}", this, stopIndex); } updater.join(); } @@ -210,7 +210,7 @@ class StateMachineUpdater implements Runnable { } private boolean shouldStop() { - return stopIndex > -1 && getLastAppliedIndex() >= stopIndex; + return stopIndex != null && getLastAppliedIndex() >= stopIndex; } private boolean shouldTakeSnapshot() { {code} The patch in RATIS-352 will fix it. > StateMachineUpdater should wait for committed transactions to be applied > before shutdown. > ----------------------------------------------------------------------------------------- > > Key: RATIS-363 > URL: https://issues.apache.org/jira/browse/RATIS-363 > Project: Ratis > Issue Type: Improvement > Components: server > Reporter: Jitendra Nath Pandey > Assignee: Jitendra Nath Pandey > Priority: Blocker > Fix For: 0.3.0 > > Attachments: RATIS-363.5.patch > > > StateMachineUpdater should apply all the committed transactions before > shutdown, otherwise committed data can be lost. -- This message was sent by Atlassian JIRA (v7.6.3#76005)