jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1564235 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/ test/java/org/apache/jackrabbit/oak/plugins/document/
Date Tue, 04 Feb 2014 09:28:08 GMT
Author: mreutegg
Date: Tue Feb  4 09:28:07 2014
New Revision: 1564235

URL: http://svn.apache.org/r1564235
Log:
OAK-1322: Reduce calls to MongoDB

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1564235&r1=1564234&r2=1564235&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
Tue Feb  4 09:28:07 2014
@@ -352,6 +352,7 @@ final class DocumentNodeState extends Ab
         private String previousName;
         private Iterator<ChildNodeEntry> current;
         private int fetchSize = INITIAL_FETCH_SIZE;
+        private int currentRemaining = fetchSize;
 
         ChildNodeEntryIterator() {
             fetchMore();
@@ -364,6 +365,9 @@ final class DocumentNodeState extends Ab
                     return false;
                 } else if (current.hasNext()) {
                     return true;
+                } else if (currentRemaining > 0) {
+                    // current returned less than fetchSize
+                    return false;
                 }
                 fetchMore();
             }
@@ -376,6 +380,7 @@ final class DocumentNodeState extends Ab
             }
             ChildNodeEntry entry = current.next();
             previousName = entry.getName();
+            currentRemaining--;
             return entry;
         }
 
@@ -387,6 +392,7 @@ final class DocumentNodeState extends Ab
         private void fetchMore() {
             Iterator<ChildNodeEntry> entries = getChildNodeEntries(
                     previousName, fetchSize).iterator();
+            currentRemaining = fetchSize;
             fetchSize = Math.min(fetchSize * 2, MAX_FETCH_SIZE);
             if (entries.hasNext()) {
                 current = entries;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java?rev=1564235&r1=1564234&r2=1564235&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
Tue Feb  4 09:28:07 2014
@@ -770,6 +770,9 @@ public class NodeDocument extends Docume
      */
     Iterable<NodeDocument> getPreviousDocs(@Nonnull final String property,
                                            @Nullable final Revision revision) {
+        if (getPreviousRanges().isEmpty()) {
+            return Collections.emptyList();
+        }
         return new PropertyHistory(store, this, property, revision);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1564235&r1=1564234&r2=1564235&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Tue Feb  4 09:28:07 2014
@@ -17,14 +17,19 @@
 package org.apache.jackrabbit.oak.plugins.document;
 
 import java.util.ArrayList;
+import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.kernel.KernelNodeState;
 import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.util.TimingDocumentStoreWrapper;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.Test;
@@ -93,6 +98,9 @@ public class DocumentNodeStoreTest {
         root = store1.getRoot();
         // now node2 is visible
         assertTrue(root.hasChildNode("node2"));
+
+        store1.dispose();
+        store2.dispose();
     }
 
     @Test
@@ -114,5 +122,44 @@ public class DocumentNodeStoreTest {
         store.merge(builder, EmptyHook.INSTANCE, null);
         int numEntries = Iterables.size(store.getRoot().getChildNodeEntries());
         assertEquals(max - 1, numEntries);
+        store.dispose();
+    }
+
+    @Test
+    public void childNodeEntries() throws Exception {
+        final AtomicInteger counter = new AtomicInteger();
+        DocumentStore docStore = new MemoryDocumentStore() {
+            @Nonnull
+            @Override
+            public <T extends Document> List<T> query(Collection<T> collection,
+                                                      String fromKey,
+                                                      String toKey,
+                                                      int limit) {
+                counter.incrementAndGet();
+                return super.query(collection, fromKey, toKey, limit);
+            }
+        };
+        DocumentNodeStore store = new DocumentMK.Builder()
+                .setDocumentStore(docStore).getNodeStore();
+        NodeBuilder root = store.getRoot().builder();
+        for (int i = 0; i < 10; i++) {
+            root.child("node-" + i);
+        }
+        store.merge(root, EmptyHook.INSTANCE, null);
+        counter.set(0);
+        // the following should just make one call to DocumentStore.query()
+        for (ChildNodeEntry e : store.getRoot().getChildNodeEntries()) {
+            e.getNodeState();
+        }
+        assertEquals(1, counter.get());
+
+        counter.set(0);
+        // now the child node entries are cached and no call should happen
+        for (ChildNodeEntry e : store.getRoot().getChildNodeEntries()) {
+            e.getNodeState();
+        }
+        assertEquals(0, counter.get());
+
+        store.dispose();
     }
 }



Mime
View raw message