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 07:50:22 UTC

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

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



##########
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:
       Can we add function name in the message?

##########
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:
       Can we add this fix in LogSegmentList#purge function? If the endIndex of last segment is same as purge index, we can remove it.




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