jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1513799 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ManyChildrenIT.java
Date Wed, 14 Aug 2013 10:33:40 GMT
Author: thomasm
Date: Wed Aug 14 10:33:40 2013
New Revision: 1513799

URL: http://svn.apache.org/r1513799
Log:
OAK-858 NodeBuilder.getChildNodeCount performance and scalability

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ManyChildrenIT.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1513799&r1=1513798&r2=1513799&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Wed Aug 14 10:33:40 2013
@@ -277,7 +277,7 @@ public final class KernelNodeState exten
                 return childNodeCountMin;
             }
             // count the entries
-            Iterator<?> iterator = getChildNodeEntries().iterator();
+            Iterator<? extends ChildNodeEntry> iterator = getChildNodeEntries().iterator();
             long n = 0;
             while (n <= max) {
                 if (!iterator.hasNext()) {
@@ -303,7 +303,7 @@ public final class KernelNodeState exten
         checkNotNull(name);
         init();
         return childNames.contains(name)
-                || (childNodeCount > MAX_CHILD_NODE_NAMES
+                || (getChildNodeCount(MAX_CHILD_NODE_NAMES) > MAX_CHILD_NODE_NAMES
                         && getChildNode(name).exists());
     }
 
@@ -315,16 +315,12 @@ public final class KernelNodeState exten
         if (childNames.contains(name)) {
             childPath = getChildPath(name);
         }
-        if (childPath == null && childNodeCount > MAX_CHILD_NODE_NAMES) {
+        if (childPath == null && getChildNodeCount(MAX_CHILD_NODE_NAMES) > MAX_CHILD_NODE_NAMES)
{
             String path = getChildPath(name);
             // OAK-506: Avoid the nodeExists() call when already cached
             NodeState state = cache.getIfPresent(revision + path);
             if (state != null) {
-                if (state != NULL) {
-                    return state;
-                } else {
-                    return MISSING_NODE;
-                }
+                return state == NULL ? MISSING_NODE : state;                
             }
             // not able to tell from cache if node exists
             // need to ask MicroKernel
@@ -347,7 +343,7 @@ public final class KernelNodeState exten
     @Override
     public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
         init();
-        if (childNodeCount <= childNames.size()) {
+        if (childNodeCount <= MAX_CHILD_NODE_NAMES && childNodeCount <= childNames.size())
{
             return iterable(childNames);
         }
         List<Iterable<ChildNodeEntry>> iterables = Lists.newArrayList();
@@ -476,7 +472,7 @@ public final class KernelNodeState exten
                     } else if (id != null && id.equals(kbase.id)) {
                         return true; // no differences
                     } else if (path.equals(kbase.path)
-                            && childNodeCount > LOCAL_DIFF_THRESHOLD) {
+                            && getChildNodeCount(LOCAL_DIFF_THRESHOLD) > LOCAL_DIFF_THRESHOLD)
{
                         // use MK.diff() when there are 'many' child nodes
                         String jsonDiff = kernel.diff(kbase.getRevision(), revision, path,
0);
                         return processJsonDiff(jsonDiff, kbase, diff);

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ManyChildrenIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ManyChildrenIT.java?rev=1513799&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ManyChildrenIT.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ManyChildrenIT.java
Wed Aug 14 10:33:40 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr;
+
+import static junit.framework.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+
+import org.junit.Test;
+
+/**
+ * Test nodes with many child nodes.
+ */
+public class ManyChildrenIT extends AbstractRepositoryTest {
+
+    public ManyChildrenIT(NodeStoreFixture fixture) {
+        super(fixture);
+    }
+
+    @Test
+    public void sizeTest() throws Exception {
+        Session session = getAdminSession();
+        int count = 5000;
+        String nodeType = "nt:folder";
+        Node many = session.getRootNode().addNode("many", nodeType);
+        for (int i = 0; i < count; i++) {
+            many.addNode("test" + i, nodeType);
+        }
+        session.save();
+        Session session2 = getAdminSession();
+        many = session2.getRootNode().getNode("many");
+        NodeIterator it = many.getNodes();
+        long size = it.getSize();
+        assertTrue("size: " + size, size == -1 || size == count);
+        for (int i = 0; i < count; i++) {
+            assertTrue(it.hasNext());
+            it.next();
+        }
+        assertFalse(it.hasNext());
+        session2.logout();
+    }
+
+}



Mime
View raw message