Author: mreutegg
Date: Wed Sep 28 14:37:39 2016
New Revision: 1762673

URL: http://svn.apache.org/viewvc?rev=1762673&view=rev
Log:
OAK-4850: List checkpoints

Merged revision 1762453 from trunk

Modified:
    jackrabbit/oak/branches/1.4/   (props changed)
    
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
    
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
    
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ProxyNodeStore.java
    
jackrabbit/oak/branches/1.4/oak-it/src/test/java/org/apache/jackrabbit/oak/spi/state/NodeStoreTest.java
    
jackrabbit/oak/branches/1.4/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java

Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Sep 28 14:37:39 2016
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457,1750462
 
,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1759433,1760340,1760373,1760387,1760661-1760662,1761412,1761444,1761571,1761762,1761787,1761876,1762635
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457,1750462
 
,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1759433,1760340,1760373,1760387,1760661-1760662,1761412,1761444,1761571,1761762,1761787,1761876,1762453,1762635
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1762673&r1=1762672&r2=1762673&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 Wed Sep 28 14:37:39 2016
@@ -1619,6 +1619,24 @@ public final class DocumentNodeStore
         }
     }
 
+    @Nonnull
+    @Override
+    public Iterable<String> checkpoints() {
+        final long now = clock.getTime();
+        return 
Iterables.transform(Iterables.filter(checkpoints.getCheckpoints().entrySet(),
+                new Predicate<Map.Entry<Revision,Checkpoints.Info>>() {
+            @Override
+            public boolean apply(Map.Entry<Revision,Checkpoints.Info> cp) {
+                return cp.getValue().getExpiryTime() > now;
+            }
+        }), new Function<Map.Entry<Revision,Checkpoints.Info>, String>() {
+            @Override
+            public String apply(Map.Entry<Revision,Checkpoints.Info> cp) {
+                return cp.getKey().toString();
+            }
+        });
+    }
+
     @CheckForNull
     @Override
     public NodeState retrieve(@Nonnull String checkpoint) {

Modified: 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1762673&r1=1762672&r2=1762673&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
 Wed Sep 28 14:37:39 2016
@@ -36,7 +36,9 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import com.google.common.io.ByteStreams;
 
 import org.apache.jackrabbit.oak.api.Blob;
@@ -220,6 +222,12 @@ public class MemoryNodeStore implements
         }
     }
 
+    @Nonnull
+    @Override
+    public synchronized Iterable<String> checkpoints() {
+        return Lists.newArrayList(checkpoints.keySet());
+    }
+
     @Override @CheckForNull
     public synchronized NodeState retrieve(@Nonnull String checkpoint) {
         Checkpoint cp = checkpoints.get(checkNotNull(checkpoint));
@@ -237,8 +245,8 @@ public class MemoryNodeStore implements
     }
 
     /** test purpose only! */
-    public synchronized Set<String> listCheckpoints() {
-        return checkpoints.keySet();
+    public Set<String> listCheckpoints() {
+        return Sets.newHashSet(checkpoints());
     }
 
     //------------------------------------------------------------< private 
>---

Modified: 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java?rev=1762673&r1=1762672&r2=1762673&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
 Wed Sep 28 14:37:39 2016
@@ -158,6 +158,20 @@ public interface NodeStore {
     Map<String, String> checkpointInfo(@Nonnull String checkpoint);
 
     /**
+     * Returns all valid checkpoints. The returned {@code Iterable} provides a
+     * snapshot of valid checkpoints at the time this method is called. That
+     * is, the {@code Iterable} will not reflect checkpoints created after this
+     * method was called.
+     * <p>
+     * See {@link #checkpoint(long, Map)} for a definition of a valid
+     * checkpoint.
+     *
+     * @return valid checkpoints.
+     */
+    @Nonnull
+    Iterable<String> checkpoints();
+
+    /**
      * Retrieves the root node from a previously created repository checkpoint.
      *
      * @param checkpoint string reference of a checkpoint

Modified: 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ProxyNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ProxyNodeStore.java?rev=1762673&r1=1762672&r2=1762673&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ProxyNodeStore.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ProxyNodeStore.java
 Wed Sep 28 14:37:39 2016
@@ -80,6 +80,12 @@ public abstract class ProxyNodeStore imp
         return getNodeStore().checkpointInfo(checkpoint);
     }
 
+    @Nonnull
+    @Override
+    public Iterable<String> checkpoints() {
+        return getNodeStore().checkpoints();
+    }
+
     @Override
     public NodeState retrieve(String checkpoint) {
         return getNodeStore().retrieve(checkpoint);

Modified: 
jackrabbit/oak/branches/1.4/oak-it/src/test/java/org/apache/jackrabbit/oak/spi/state/NodeStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-it/src/test/java/org/apache/jackrabbit/oak/spi/state/NodeStoreTest.java?rev=1762673&r1=1762672&r2=1762673&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-it/src/test/java/org/apache/jackrabbit/oak/spi/state/NodeStoreTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-it/src/test/java/org/apache/jackrabbit/oak/spi/state/NodeStoreTest.java
 Wed Sep 28 14:37:39 2016
@@ -32,6 +32,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
@@ -39,6 +41,10 @@ import java.util.concurrent.atomic.Atomi
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
 import org.apache.jackrabbit.oak.NodeStoreFixtures;
 import org.apache.jackrabbit.oak.OakBaseTest;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -546,6 +552,32 @@ public class NodeStoreTest extends OakBa
         assertTrue(root.hasChildNode("bar"));
     }
 
+    @Test
+    public void checkpoints() throws Exception {
+        int numCps = 3;
+        Map<String, String> info = Maps.newHashMap();
+        Set<String> cps = Sets.newHashSet();
+        for (int i = 0; i < numCps; i++) {
+            info.put("key", "" + i);
+            cps.add(store.checkpoint(TimeUnit.HOURS.toMillis(1), info));
+        }
+        assertEquals(numCps, cps.size());
+        assertEquals(cps, Sets.newHashSet(store.checkpoints()));
+        Set<String> keys = Sets.newHashSet();
+        for (String cp : cps) {
+            info = store.checkpointInfo(cp);
+            assertTrue(info.containsKey("key"));
+            keys.add(info.get("key"));
+        }
+        assertEquals(Sets.newHashSet("0", "1", "2"), keys);
+        while (!cps.isEmpty()) {
+            String cp = cps.iterator().next();
+            cps.remove(cp);
+            store.release(cp);
+            assertEquals(cps.size(), Iterables.size(store.checkpoints()));
+        }
+    }
+
     private void compareAgainstBaseState(int childNodeCount) throws 
CommitFailedException {
         NodeState before = store.getRoot();
         NodeBuilder builder = before.builder();

Modified: 
jackrabbit/oak/branches/1.4/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1762673&r1=1762672&r2=1762673&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
 Wed Sep 28 14:37:39 2016
@@ -399,6 +399,12 @@ public class SegmentNodeStore implements
         return properties;
     }
 
+    @Nonnull
+    @Override
+    public Iterable<String> checkpoints() {
+        return getCheckpoints().getChildNodeNames();
+    }
+
     @Override @CheckForNull
     public NodeState retrieve(@Nonnull String checkpoint) {
         checkNotNull(checkpoint);


Reply via email to