You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2022/07/21 17:44:53 UTC

[GitHub] [ratis] szetszwo commented on a diff in pull request #688: RATIS-1626. Preserve recent logs when purge logs

szetszwo commented on code in PR #688:
URL: https://github.com/apache/ratis/pull/688#discussion_r926948970


##########
ratis-server-api/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java:
##########
@@ -285,6 +285,15 @@ static void setPurgeUptoSnapshotIndex(RaftProperties properties, boolean shouldP
       setBoolean(properties::setBoolean, PURGE_UPTO_SNAPSHOT_INDEX_KEY, shouldPurgeUptoSnapshotIndex);
     }
 
+    String PURGE_PRESERVE_LOG_NUM_KEY = PREFIX + "purge.preserve.log.num";

Review Comment:
   "preserve" is a good word choice.  Let's call it ".purge. preservation" so that it is similar to ".purge.gap".
   
   BTW, it needs a "." in the beginning.  



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java:
##########
@@ -297,7 +299,8 @@ private void takeSnapshot() {
             CommitInfoProto::getCommitIndex);
         purgeIndex = LongStream.concat(LongStream.of(i), commitIndexStream).min().orElse(i);
       }
-      raftLog.purge(purgeIndex);
+      final long purgeIndexWithPreserve = Math.max(0L, purgeIndex - purgePreserveLogNum);
+      raftLog.purge(purgeIndexWithPreserve);

Review Comment:
   Let's change it in RaftLogBase.purge(..) so that the new code will be next to the purgeGap code.  We may add a `purgePreservation` field and use it as below
   ```
   +++ b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLogBase.java
   @@ -301,6 +301,10 @@ public abstract class RaftLogBase implements RaftLog {
    
      @Override
      public final CompletableFuture<Long> purge(long suggestedIndex) {
   +    if (purgePreservation > 0) {
   +      final long currentIndex = getNextIndex() - 1;
   +      suggestedIndex = Math.min(suggestedIndex, currentIndex - purgePreservation);
   +    }
        final long lastPurge = purgeIndex.get();
        if (suggestedIndex - lastPurge < purgeGap) {
          return CompletableFuture.completedFuture(lastPurge);
   ```



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

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

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