Repository: incubator-ratis Updated Branches: refs/heads/master 288ea4f42 -> 9494b75c1
RATIS-209. StateMachine updater may miss writeLog Request after a new Leader is chosen. Contributed by Mukul Kumar Singh Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/9494b75c Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/9494b75c Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/9494b75c Branch: refs/heads/master Commit: 9494b75c1ef285fb8a292118de97ccc37cc5b89c Parents: 288ea4f Author: Tsz-Wo Nicholas Sze <[email protected]> Authored: Tue Mar 27 15:36:16 2018 +0800 Committer: Tsz-Wo Nicholas Sze <[email protected]> Committed: Tue Mar 27 15:36:16 2018 +0800 ---------------------------------------------------------------------- .../apache/ratis/server/storage/SegmentedRaftLog.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/9494b75c/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java b/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java index 036f3e0..3f14571 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java @@ -272,8 +272,17 @@ public class SegmentedRaftLog extends RaftLog { checkAndEvictCache(); } + // If the entry has state machine data, then the entry should be inserted + // to statemachine first and then to the cache. Not following the order + // will leave a spurious entry in the cache. + CompletableFuture<Long> writeFuture = + fileLogWorker.writeLogEntry(entry).getFuture(); cache.appendEntry(entry); - return fileLogWorker.writeLogEntry(entry).getFuture(); + return writeFuture; + } catch (Throwable throwable) { + LOG.error(getSelfId() + "exception while appending entry with index:" + + entry.getIndex(), throwable); + throw throwable; } }
