Author: mreutegg
Date: Tue Jun  9 11:11:42 2015
New Revision: 1684379

URL: http://svn.apache.org/r1684379
Log:
OAK-1970: Optimize the diff logic for large number of children case

Merged revision 1684186 from trunk

Modified:
    jackrabbit/oak/branches/1.2/   (props changed)
    
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun  9 11:11:42 2015
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1679958,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683278,1683323,1683687,1684174-1684175
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1679958,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683278,1683323,1683687,1684174-1684175,1684186
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1684379&r1=1684378&r2=1684379&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
 Tue Jun  9 11:11:42 2015
@@ -24,6 +24,7 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS_RESOLUTION;
 import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.NUM_REVS_THRESHOLD;
 import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.PREV_SPLIT_FACTOR;
+import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.getModifiedInSecs;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -1749,6 +1750,71 @@ public class DocumentNodeStoreTest {
 
     }
 
+    // OAK-1970
+    @Test
+    public void diffMany() throws Exception {
+        Clock clock = new Clock.Virtual();
+        clock.waitUntil(System.currentTimeMillis());
+        Revision.setClock(clock);
+        final List<Long> startValues = Lists.newArrayList();
+        MemoryDocumentStore ds = new MemoryDocumentStore() {
+            @Nonnull
+            @Override
+            public <T extends Document> List<T> query(Collection<T> collection,
+                                                      String fromKey,
+                                                      String toKey,
+                                                      String indexedProperty,
+                                                      long startValue,
+                                                      int limit) {
+                if (indexedProperty != null) {
+                    startValues.add(startValue);
+                }
+                return super.query(collection, fromKey, toKey, 
indexedProperty, startValue, limit);
+            }
+        };
+        DocumentNodeStore ns = new DocumentMK.Builder().clock(clock)
+                .setDocumentStore(ds).setAsyncDelay(0).getNodeStore();
+
+        NodeBuilder builder = ns.getRoot().builder();
+        NodeBuilder test = builder.child("test");
+        for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
+            test.child("node-" + i);
+        }
+        merge(ns, builder);
+
+        // 'wait one hour'
+        clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
+
+        // perform a change and use the resulting root as before state
+        builder = ns.getRoot().builder();
+        builder.child("foo");
+        DocumentNodeState before = asDocumentNodeState(merge(ns, builder));
+        NodeState beforeTest = before.getChildNode("test");
+
+        // perform another change to span the diff across multiple revisions
+        // this will prevent diff calls served from the local cache
+        builder = ns.getRoot().builder();
+        builder.child("bar");
+        merge(ns, builder);
+
+        // add a child node
+        builder = ns.getRoot().builder();
+        builder.child("test").child("bar");
+        NodeState after = merge(ns, builder);
+        NodeState afterTest = after.getChildNode("test");
+
+        startValues.clear();
+        afterTest.compareAgainstBaseState(beforeTest, new 
DefaultNodeStateDiff());
+
+        assertEquals(1, startValues.size());
+        long beforeModified = 
getModifiedInSecs(before.getRevision().getTimestamp());
+        // startValue must be based on the revision of the before state
+        // and not when '/test' was last modified
+        assertEquals(beforeModified, (long) startValues.get(0));
+
+        ns.dispose();
+    }
+
     private static DocumentNodeState asDocumentNodeState(NodeState state) {
         if (!(state instanceof DocumentNodeState)) {
             throw new IllegalArgumentException("Not a DocumentNodeState");
@@ -1778,9 +1844,9 @@ public class DocumentNodeStoreTest {
         }
     }
 
-    private static void merge(NodeStore store, NodeBuilder root)
+    private static NodeState merge(NodeStore store, NodeBuilder root)
             throws CommitFailedException {
-        store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+        return store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
     }
 
     private static class TestHook extends EditorHook {


Reply via email to