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 mr...@apache.org on 2016/05/31 20:59:10 UTC

svn commit: r1746342 - /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java

Author: mreutegg
Date: Tue May 31 20:59:10 2016
New Revision: 1746342

URL: http://svn.apache.org/viewvc?rev=1746342&view=rev
Log:
OAK-4358: Stale cluster ids can potentially lead to lots of previous docs traversal in NodeDocument.getNewestRevision

Add test - currently ignored.

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java?rev=1746342&r1=1746341&r2=1746342&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java Tue May 31 20:59:10 2016
@@ -37,6 +37,7 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static com.google.common.collect.Sets.newHashSet;
@@ -553,6 +554,77 @@ public class NodeDocumentTest {
         ns.dispose();
     }
 
+    // OAK-4358
+    @Ignore
+    @Test
+    public void tooManyReadsOnGetNewestRevision() throws Exception {
+        final Set<String> prevDocCalls = newHashSet();
+        MemoryDocumentStore store = new MemoryDocumentStore() {
+            @Override
+            public <T extends Document> T find(Collection<T> collection,
+                                               String key) {
+                if (Utils.getPathFromId(key).startsWith("p")) {
+                    prevDocCalls.add(key);
+                }
+                return super.find(collection, key);
+            }
+        };
+        DocumentNodeStore ns1 = createTestStore(store, 1, 0);
+        DocumentNodeStore ns2 = createTestStore(store, 2, 0);
+
+        // create a test node on ns1
+        NodeBuilder b1 = ns1.getRoot().builder();
+        b1.child("test");
+        merge(ns1, b1);
+        ns1.runBackgroundOperations();
+        ns2.runBackgroundOperations();
+
+        // modify node on ns2 a couple of time and
+        // split off some changes
+        for (int i = 0; i < 3; i++) {
+            NodeBuilder b2 = ns2.getRoot().builder();
+            b2.child("test").setProperty("ns2", i);
+            merge(ns2, b2);
+        }
+        String testId = Utils.getIdFromPath("/test");
+        NodeDocument test = ns2.getDocumentStore().find(NODES, testId);
+        assertNotNull(test);
+        List<UpdateOp> ops = SplitOperations.forDocument(test, ns2,
+                ns2.getHeadRevision(), Predicates.<String>alwaysFalse(), 2);
+        assertEquals(2, ops.size());
+        for (UpdateOp op : ops) {
+            ns2.getDocumentStore().createOrUpdate(NODES, op);
+        }
+        ns2.runBackgroundOperations();
+        ns1.runBackgroundOperations();
+
+        List<RevisionVector> headRevs = Lists.newArrayList();
+        // perform many changes on ns1 and split
+        for (int i = 0; i < 20; i++) {
+            b1 = ns1.getRoot().builder();
+            b1.child("test").setProperty("ns1", i);
+            merge(ns1, b1);
+            test = ns1.getDocumentStore().find(NODES, testId);
+            for (UpdateOp op : SplitOperations.forDocument(test, ns1,
+                    ns1.getHeadRevision(), Predicates.<String>alwaysFalse(), 3)) {
+                ns1.getDocumentStore().createOrUpdate(NODES, op);
+            }
+            headRevs.add(ns1.getHeadRevision());
+        }
+
+        int numPrevDocs = Iterators.size(test.getPreviousDocLeaves());
+        assertEquals(10, numPrevDocs);
+
+        // getNewestRevision must not read all previous documents
+        prevDocCalls.clear();
+        // simulate a call done by a commit with a
+        // base revision somewhat in the past
+        test.getNewestRevision(ns1, headRevs.get(16), ns1.newRevision(),
+                null, new HashSet<Revision>());
+        // must only read one previous document for ns1 changes
+        assertEquals(1, prevDocCalls.size());
+    }
+
     private DocumentNodeStore createTestStore(int numChanges) throws Exception {
         return createTestStore(new MemoryDocumentStore(), 0, numChanges);
     }