You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/05/07 11:03:52 UTC

[GitHub] [incubator-ratis] lokeshj1703 commented on a change in pull request #89: RATIS-874. Fix AppendEntry validity checks to take the SnapshotIndex into account

lokeshj1703 commented on a change in pull request #89:
URL: https://github.com/apache/incubator-ratis/pull/89#discussion_r421414338



##########
File path: ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java
##########
@@ -342,10 +342,10 @@ int getMaxCachedSegments() {
   }
 
   void loadSegment(LogPathAndIndex pi, boolean keepEntryInCache,
-      Consumer<LogEntryProto> logConsumer) throws IOException {
+      Consumer<LogEntryProto> logConsumer, long lastIndexInSnapshot) throws IOException {
     LogSegment logSegment = LogSegment.loadSegment(storage, pi.getPath().toFile(),

Review comment:
       We should not load logSegment if endIndex < lastIndexInSnapshot. We will also need to cover the case where endIndex is INVALID_LOG_INDEX.

##########
File path: ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java
##########
@@ -313,11 +338,15 @@ protected void validateLogEntry(LogEntryProto entry) {
     }
     TermIndex lastTermIndex = getLastEntryTermIndex();
     if (lastTermIndex != null) {
+      long latestSnapshotIndex = getSnapshotIndex();
+      long lastIndex = lastTermIndex.getIndex() > latestSnapshotIndex ?
+          lastTermIndex.getIndex() : latestSnapshotIndex;

Review comment:
       Due to some race condition is it possible that snapshotIndex is higher and follower is appending a log entry with a lower index?

##########
File path: ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java
##########
@@ -342,10 +342,10 @@ int getMaxCachedSegments() {
   }
 
   void loadSegment(LogPathAndIndex pi, boolean keepEntryInCache,
-      Consumer<LogEntryProto> logConsumer) throws IOException {
+      Consumer<LogEntryProto> logConsumer, long lastIndexInSnapshot) throws IOException {
     LogSegment logSegment = LogSegment.loadSegment(storage, pi.getPath().toFile(),

Review comment:
       We should not load logSegment if endIndex < lastIndexInSnapshot. We will also need to cover the case where endIndex is INVALID_LOG_INDEX.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org