Author: alexparvulescu
Date: Mon Sep 19 09:49:59 2016
New Revision: 1761412

URL: http://svn.apache.org/viewvc?rev=1761412&view=rev
Log:
OAK-4043 Oak run checkpoints needs to account for multiple index lanes


Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/Checkpoints.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/DocumentCheckpoints.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentCheckpoints.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentTarCheckpoints.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsHelper.java

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/Checkpoints.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/Checkpoints.java?rev=1761412&r1=1761411&r2=1761412&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/Checkpoints.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/Checkpoints.java
 Mon Sep 19 09:49:59 2016
@@ -18,9 +18,11 @@ package org.apache.jackrabbit.oak.checkp
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
-import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 
 import com.google.common.io.Closer;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -77,18 +79,19 @@ public abstract class Checkpoints {
      */
     public abstract int remove(String cp);
 
-    @CheckForNull
-    static String getReferenceCheckpoint(NodeState root) {
-        String ref = null;
-        PropertyState refPS = root.getChildNode(":async").getProperty("async");
-        if (refPS != null) {
-            ref = refPS.getValue(Type.STRING);
+    @Nonnull
+    static Set<String> getReferencedCheckpoints(NodeState root) {
+        Set<String> cps = new HashSet<String>();
+        for (PropertyState ps : root.getChildNode(":async").getProperties()) {
+            String name = ps.getName();
+            if (name.endsWith("async") && ps.getType().equals(Type.STRING)) {
+                String ref = ps.getValue(Type.STRING);
+                System.out.println("Referenced checkpoint from /:async@" + name
+                        + " is " + ref);
+                cps.add(ref);
+            }
         }
-        if (ref != null) {
-            System.out.println(
-                    "Referenced checkpoint from /:async@async is " + ref);
-        }
-        return ref;
+        return cps;
     }
 
     public static final class CP {

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/DocumentCheckpoints.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/DocumentCheckpoints.java?rev=1761412&r1=1761411&r2=1761412&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/DocumentCheckpoints.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/DocumentCheckpoints.java
 Mon Sep 19 09:49:59 2016
@@ -18,6 +18,7 @@
 package org.apache.jackrabbit.oak.checkpoint;
 
 import static 
org.apache.jackrabbit.oak.plugins.document.CheckpointsHelper.getCheckpoints;
+import static org.apache.jackrabbit.oak.plugins.document.CheckpointsHelper.min;
 import static 
org.apache.jackrabbit.oak.plugins.document.CheckpointsHelper.removeOlderThan;
 
 import java.util.List;
@@ -54,11 +55,11 @@ class DocumentCheckpoints extends Checkp
 
     @Override
     public long removeUnreferenced() {
-        String ref = getReferenceCheckpoint(store.getRoot());
+        Revision ref = min(getReferencedCheckpoints(store.getRoot()));
         if (ref == null) {
             return -1;
         }
-        return removeOlderThan(store, Revision.fromString(ref));
+        return removeOlderThan(store, ref);
     }
 
     @Override

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentCheckpoints.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentCheckpoints.java?rev=1761412&r1=1761411&r2=1761412&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentCheckpoints.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentCheckpoints.java
 Mon Sep 19 09:49:59 2016
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.checkp
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
+import java.util.Set;
 
 import com.google.common.collect.Lists;
 import com.google.common.io.Closer;
@@ -73,13 +74,13 @@ final class SegmentCheckpoints extends C
     public long removeUnreferenced() {
         SegmentNodeState head = store.getHead();
 
-        String ref = getReferenceCheckpoint(head.getChildNode("root"));
+        Set<String> refs = getReferencedCheckpoints(head.getChildNode("root"));
 
         NodeBuilder builder = head.builder();
         NodeBuilder cps = builder.getChildNode("checkpoints");
         long cnt = 0;
         for (String c : cps.getChildNodeNames()) {
-            if (c.equals(ref)) {
+            if (refs.contains(c)) {
                 continue;
             }
             cps.getChildNode(c).remove();

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentTarCheckpoints.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentTarCheckpoints.java?rev=1761412&r1=1761411&r2=1761412&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentTarCheckpoints.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/checkpoint/SegmentTarCheckpoints.java
 Mon Sep 19 09:49:59 2016
@@ -22,6 +22,7 @@ import static org.apache.jackrabbit.oak.
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
+import java.util.Set;
 
 import com.google.common.collect.Lists;
 import com.google.common.io.Closer;
@@ -79,13 +80,13 @@ class SegmentTarCheckpoints extends Chec
     public long removeUnreferenced() {
         SegmentNodeState head = store.getHead();
 
-        String ref = getReferenceCheckpoint(head.getChildNode("root"));
+        Set<String> refs = getReferencedCheckpoints(head.getChildNode("root"));
 
         NodeBuilder builder = head.builder();
         NodeBuilder cps = builder.getChildNode("checkpoints");
         long cnt = 0;
         for (String c : cps.getChildNodeNames()) {
-            if (c.equals(ref)) {
+            if (refs.contains(c)) {
                 continue;
             }
             cps.getChildNode(c).remove();

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsHelper.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsHelper.java?rev=1761412&r1=1761411&r2=1761412&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsHelper.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsHelper.java
 Mon Sep 19 09:49:59 2016
@@ -19,11 +19,13 @@
 package org.apache.jackrabbit.oak.plugins.document;
 
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedMap;
 
 import com.google.common.collect.Maps;
 
 import static org.apache.jackrabbit.oak.plugins.document.Checkpoints.Info;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 
 /**
  * Helper class to access package private functionality.
@@ -69,4 +71,15 @@ public abstract class CheckpointsHelper
         }
     }
 
+    public static Revision min(Set<String> revs) {
+        if (revs == null || revs.isEmpty()) {
+            return null;
+        }
+        Revision r = null;
+        for (String cp : revs) {
+            r = Utils.min(r, Revision.fromString(cp));
+        }
+        return r;
+    }
+
 }


Reply via email to