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/10/14 21:00:07 UTC

[GitHub] [incubator-ratis] avijayanhwx commented on a change in pull request #217: RATIS-1088. SegmentedRaftLogWorker#closeLogSegment should also roll the open segment maintained in the cache.

avijayanhwx commented on a change in pull request #217:
URL: https://github.com/apache/incubator-ratis/pull/217#discussion_r504968883



##########
File path: ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java
##########
@@ -493,10 +493,21 @@ public void syncWithSnapshot(long lastSnapshotIndex) {
 
     // Close open log segment if entries are already included in snapshot
     LogSegment openSegment = cache.getOpenSegment();
-    if (openSegment != null && openSegment.getEndIndex() <= lastSnapshotIndex) {
-      fileLogWorker.closeLogSegment(openSegment);
+    long purgeIndex = lastSnapshotIndex;
+    if (openSegment != null && openSegment.hasEntries()) {
+      LOG.debug("Found open segment {}, with end index {}, snapshotIndex {}",

Review comment:
       Done

##########
File path: ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java
##########
@@ -493,10 +493,21 @@ public void syncWithSnapshot(long lastSnapshotIndex) {
 
     // Close open log segment if entries are already included in snapshot
     LogSegment openSegment = cache.getOpenSegment();
-    if (openSegment != null && openSegment.getEndIndex() <= lastSnapshotIndex) {
-      fileLogWorker.closeLogSegment(openSegment);
+    long purgeIndex = lastSnapshotIndex;
+    if (openSegment != null && openSegment.hasEntries()) {
+      LOG.debug("Found open segment {}, with end index {}, snapshotIndex {}",
+          openSegment, openSegment.getEndIndex(), lastSnapshotIndex);
+      if (openSegment.getEndIndex() <= lastSnapshotIndex) {
+        fileLogWorker.closeLogSegment(openSegment);
+        cache.rollOpenSegment(true);
+        if (openSegment.getEndIndex() == lastSnapshotIndex) {
+          // Since purgeImpl does not delete any segment which has overlap,
+          // passing in snapshotIndex + 1.
+          purgeIndex = lastSnapshotIndex + 1;
+        }

Review comment:
       Done. 




----------------------------------------------------------------
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