You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by jo...@apache.org on 2024/06/24 15:07:08 UTC

(jackrabbit-oak) branch OAK-10915 created (now 1d700cfb1c)

This is an automated email from the ASF dual-hosted git repository.

joscorbe pushed a change to branch OAK-10915
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


      at 1d700cfb1c OAK-10915: Avoid deleting expired checkpoints when running FullGC on a read-only NodeStore

This branch includes the following new commits:

     new 1d700cfb1c OAK-10915: Avoid deleting expired checkpoints when running FullGC on a read-only NodeStore

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(jackrabbit-oak) 01/01: OAK-10915: Avoid deleting expired checkpoints when running FullGC on a read-only NodeStore

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joscorbe pushed a commit to branch OAK-10915
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 1d700cfb1c6673593c2ec8be5f84d7d6e6236f25
Author: Jose Cordero <co...@adobe.com>
AuthorDate: Mon Jun 24 17:06:47 2024 +0200

    OAK-10915: Avoid deleting expired checkpoints when running FullGC on a read-only NodeStore
---
 .../oak/plugins/document/Checkpoints.java          |  4 +++
 .../plugins/document/VersionGCRecommendations.java | 36 +++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
index e57a75258d..eab4de94a9 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
@@ -204,6 +204,10 @@ class Checkpoints {
         return rv;
     }
 
+    DocumentNodeStore getNodeStore() {
+        return nodeStore;
+    }
+
     void setInfoProperty(@NotNull String checkpoint, @NotNull String key, @Nullable String value) {
         Revision r = Revision.fromString(checkNotNull(checkpoint));
         Info info = getCheckpoints().get(r);
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCRecommendations.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCRecommendations.java
index 6ee38b4925..b66f3fb420 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCRecommendations.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCRecommendations.java
@@ -20,15 +20,18 @@ package org.apache.jackrabbit.oak.plugins.document;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.SortedMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.util.TimeInterval;
 import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.apache.jackrabbit.oak.spi.gc.GCMonitor;
 import org.apache.jackrabbit.oak.stats.Clock;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -223,7 +226,12 @@ public class VersionGCRecommendations {
         }
 
         //Check for any registered checkpoint which prevent the GC from running
-        Revision checkpoint = checkpoints.getOldestRevisionToKeep();
+        Revision checkpoint;
+        if (checkpoints.getNodeStore().isReadOnlyMode()) {
+            checkpoint = getLastAliveRevision(clock, checkpoints);
+        } else {
+            checkpoint = checkpoints.getOldestRevisionToKeep();
+        }
 
         final GCResult gcResult = getResult(options, checkpoint, clock, RGC, scope);
         scope = gcResult.gcScope;
@@ -321,6 +329,32 @@ public class VersionGCRecommendations {
         }
     }
 
+    @Nullable
+    private Revision getLastAliveRevision(Clock clock, Checkpoints checkpoints) {
+        //Get uncached doc
+        SortedMap<Revision, Checkpoints.Info> checkpointsInfoMap = checkpoints.getCheckpoints();
+        if(checkpointsInfoMap.isEmpty()){
+            return null;
+        }
+
+        final long currentTime = clock.getTime();
+        Revision lastAliveRevision = null;
+
+        for (Map.Entry<Revision, Checkpoints.Info> e : checkpointsInfoMap.entrySet()) {
+            long expiryTime = e.getValue().getExpiryTime();
+            if (currentTime < expiryTime) {
+                Revision cpRev = e.getKey();
+                RevisionVector rv = e.getValue().getCheckpoint();
+                if (rv != null) {
+                    cpRev = rv.getRevision(cpRev.getClusterId());
+                }
+                lastAliveRevision = Utils.min(lastAliveRevision, cpRev);
+            }
+        }
+
+        return lastAliveRevision;
+    }
+
     private Map<String, Object> getVGCSettings() {
         Document versionGCDoc = vgc.getDocumentStore().find(Collection.SETTINGS, SETTINGS_COLLECTION_ID, 0);
         Map<String, Object> settings = new HashMap<>();