jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1363984 - in /jackrabbit/oak/trunk: oak-core/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ oak-it/osgi/ ...
Date Fri, 20 Jul 2012 22:26:01 GMT
Author: jukka
Date: Fri Jul 20 22:26:01 2012
New Revision: 1363984

URL: http://svn.apache.org/viewvc?rev=1363984&view=rev
Log:
OAK-175: MemoryNodeStateBuilder inefficient for large child node lists

Reduce the amount of getNodeState() calls by making latest property information available
directly from NodeStateBuilder.
Use Guava instead of custom utility classes for generic iterables.

Modified:
    jackrabbit/oak/trunk/oak-core/pom.xml
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
    jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
    jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml

Modified: jackrabbit/oak/trunk/oak-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1363984&r1=1363983&r2=1363984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-core/pom.xml Fri Jul 20 22:26:01 2012
@@ -132,6 +132,11 @@
         <artifactId>commons-collections</artifactId>
         <version>3.2.1</version>
     </dependency>
+    <dependency>
+        <groupId>com.google.guava</groupId>
+        <artifactId>guava</artifactId>
+        <version>12.0.1</version>
+    </dependency>
 
     <!-- Optional dependencies for different persistence backends -->
     <dependency>

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1363984&r1=1363983&r2=1363984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Fri Jul 20 22:26:01 2012
@@ -114,7 +114,7 @@ public class TreeImpl implements Tree, P
 
     @Override
     public PropertyState getProperty(String name) {
-        return getNodeState().getProperty(name);
+        return getNodeStateBuilder().getProperty(name);
     }
 
     @Override
@@ -162,17 +162,17 @@ public class TreeImpl implements Tree, P
 
     @Override
     public boolean hasProperty(String name) {
-        return getNodeState().getProperty(name) != null;
+        return getProperty(name) != null;
     }
 
     @Override
     public long getPropertyCount() {
-        return getNodeState().getPropertyCount();
+        return getNodeStateBuilder().getPropertyCount();
     }
 
     @Override
     public Iterable<? extends PropertyState> getProperties() {
-        return getNodeState().getProperties();
+        return getNodeStateBuilder().getProperties();
     }
 
     @Override
@@ -437,10 +437,6 @@ public class TreeImpl implements Tree, P
             }
         }
 
-        public void clear() {
-            children.clear();
-        }
-
         @Override
         public Iterator<TreeImpl> iterator() {
             return children.values().iterator();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java?rev=1363984&r1=1363983&r2=1363984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
Fri Jul 20 22:26:01 2012
@@ -21,10 +21,17 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
 
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Basic in-memory node state builder.
@@ -121,6 +128,47 @@ public class MemoryNodeStateBuilder impl
     }
 
     @Override
+    public long getPropertyCount() {
+        long count = base.getPropertyCount();
+        for (Map.Entry<String, PropertyState> entry : properties.entrySet()) {
+            PropertyState before = base.getProperty(entry.getKey());
+            PropertyState after = entry.getValue();
+            if (before == null && after != null) {
+                count++;
+            } else if (before != null && after == null) {
+                count--;
+            }
+        }
+        return count;
+    }
+
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        frozen = true;
+        final Set<String> names = properties.keySet();
+        Predicate<PropertyState> predicate = new Predicate<PropertyState>() {
+            @Override
+            public boolean apply(PropertyState input) {
+                return !names.contains(input.getName());
+            }
+        };
+        return Iterables.concat(
+                Iterables.filter(properties.values(), Predicates.notNull()),
+                Iterables.filter(base.getProperties(), predicate));
+    }
+
+
+    @Override
+    public PropertyState getProperty(String name) {
+        PropertyState property = properties.get(name);
+        if (property != null || properties.containsKey(name)) {
+            return property;
+        } else {
+            return base.getProperty(name);
+        }
+    }
+
+    @Override
     public void setProperty(String name, CoreValue value) {
         unfreeze();
         properties.put(name, new SinglePropertyState(name, value));

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java?rev=1363984&r1=1363983&r2=1363984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
Fri Jul 20 22:26:01 2012
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
 
 /**
  * Builder interface for constructing new {@link NodeState node states}.
@@ -51,6 +52,29 @@ public interface NodeStateBuilder {
     void removeNode(String name);
 
     /**
+     * Returns the current number of properties.
+     *
+     * @return number of properties
+     */
+    long getPropertyCount();
+
+    /**
+     * Returns the current properties.
+     *
+     * @return current properties
+     */
+    Iterable<? extends PropertyState> getProperties();
+
+    /**
+     * Returns the current state of the named property, or {@code null}
+     * if the property is not set.
+     *
+     * @param name property name
+     * @return property state
+     */
+    PropertyState getProperty(String name);
+
+    /**
      * Set a property.
      *
      * @param name property name

Modified: jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java?rev=1363984&r1=1363983&r2=1363984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
Fri Jul 20 22:26:01 2012
@@ -50,6 +50,7 @@ public class OSGiIT {
                 bundle(new File(base, "jcr.jar").toURI().toURL().toString()),
                 bundle(new File(base, "commons-io.jar").toURI().toURL().toString()),
                 bundle(new File(base, "commons-collections.jar").toURI().toURL().toString()),
+                bundle(new File(base, "guava.jar").toURI().toURL().toString()),
                 bundle(new File(base, "jackrabbit-api.jar").toURI().toURL().toString()),
                 bundle(new File(base, "jackrabbit-jcr-commons.jar").toURI().toURL().toString()),
                 bundle(new File(base, "oak-commons.jar").toURI().toURL().toString()),

Modified: jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml?rev=1363984&r1=1363983&r2=1363984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml (original)
+++ jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml Fri Jul 20 22:26:01 2012
@@ -31,6 +31,7 @@
         <include>javax.jcr:jcr</include>
         <include>commons-io:commons-io</include>
         <include>commons-collections:commons-collections</include>
+        <include>com.google.guava:guava</include>
         <include>org.apache.jackrabbit:jackrabbit-api</include>
         <include>org.apache.jackrabbit:jackrabbit-jcr-commons</include>
         <include>org.apache.jackrabbit:oak-commons</include>



Mime
View raw message