jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1365522 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel: JsopDiff.java KernelNodeStore.java KernelNodeStoreBranch.java KernelRootStateBuilder.java
Date Wed, 25 Jul 2012 11:23:28 GMT
Author: jukka
Date: Wed Jul 25 11:23:27 2012
New Revision: 1365522

URL: http://svn.apache.org/viewvc?rev=1365522&view=rev
Log:
OAK-167: Caching NodeStore implementation

Move the diff to jsop conversiont to a separate class and prepare to use it from within KernelRootStateBuilder.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootStateBuilder.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java?rev=1365522&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
Wed Jul 25 11:23:27 2012
@@ -0,0 +1,140 @@
+/*
+ * 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.kernel;
+
+import static org.apache.jackrabbit.oak.kernel.CoreValueMapper.TYPE2HINT;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
+
+class JsopDiff implements NodeStateDiff {
+
+    private final JsopBuilder jsop;
+
+    private final String path;
+
+    public JsopDiff(JsopBuilder jsop, String path) {
+        this.jsop = jsop;
+        this.path = path;
+    }
+
+    public JsopDiff() {
+        this(new JsopBuilder(), "");
+    }
+
+    public static void diffToJsop(
+            NodeState before, NodeState after,
+            String path, JsopBuilder jsop) {
+        after.compareAgainstBaseState(before, new JsopDiff(jsop, path));
+    }
+
+    //-----------------------------------------------------< NodeStateDiff >--
+
+    @Override
+    public void propertyAdded(PropertyState after) {
+        jsop.tag('^').key(buildPath(after.getName()));
+        toJson(after, jsop);
+    }
+
+    @Override
+    public void propertyChanged(PropertyState before, PropertyState after) {
+        jsop.tag('^').key(buildPath(after.getName()));
+        toJson(after, jsop);
+    }
+
+    @Override
+    public void propertyDeleted(PropertyState before) {
+        jsop.tag('^').key(buildPath(before.getName())).value(null);
+    }
+
+    @Override
+    public void childNodeAdded(String name, NodeState after) {
+        jsop.tag('+').key(buildPath(name));
+        toJson(after, jsop);
+    }
+
+    @Override
+    public void childNodeDeleted(String name, NodeState before) {
+        jsop.tag('-').value(buildPath(name));
+    }
+
+    @Override
+    public void childNodeChanged(String name, NodeState before, NodeState after) {
+        after.compareAgainstBaseState(
+                before, new JsopDiff(jsop, PathUtils.concat(path, name)));
+    }
+
+    //------------------------------------------------------------< Object >--
+
+    public String toString() {
+        return jsop.toString();
+    }
+
+    //-----------------------------------------------------------< private >--
+
+    private String buildPath(String name) {
+        return PathUtils.concat(path, name);
+    }
+
+    private void toJson(NodeState nodeState, JsopBuilder jsop) {
+        jsop.object();
+        for (PropertyState property : nodeState.getProperties()) {
+            jsop.key(property.getName());
+            toJson(property, jsop);
+        }
+        for (ChildNodeEntry child : nodeState.getChildNodeEntries()) {
+            jsop.key(child.getName());
+            toJson(child.getNodeState(), jsop);
+        }
+        jsop.endObject();
+    }
+
+    private void toJson(PropertyState propertyState, JsopBuilder jsop) {
+        if (propertyState.isArray()) {
+            jsop.array();
+            for (CoreValue value : propertyState.getValues()) {
+                toJson(value, jsop);
+            }
+            jsop.endArray();
+        } else {
+            toJson(propertyState.getValue(), jsop);
+        }
+    }
+
+    private void toJson(CoreValue value, JsopBuilder jsop) {
+        int type = value.getType();
+        if (type == PropertyType.BOOLEAN) {
+            jsop.value(value.getBoolean());
+        } else if (type == PropertyType.LONG) {
+            jsop.value(value.getLong());
+        } else {
+            String string = value.getString();
+            if (type != PropertyType.STRING
+                    || CoreValueMapper.startsWithHint(string)) {
+                string = TYPE2HINT.get(type) + ':' + string;
+            }
+            jsop.value(string);
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1365522&r1=1365521&r2=1365522&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Wed Jul 25 11:23:27 2012
@@ -20,6 +20,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
 import org.apache.jackrabbit.oak.spi.commit.EmptyEditor;
 import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
@@ -102,7 +103,13 @@ public class KernelNodeStore implements 
 
     @Override
     public NodeStateBuilder getBuilder(NodeState base) {
-        return new KernelRootStateBuilder(base);
+        if (base instanceof KernelNodeState) {
+            KernelNodeState kbase = (KernelNodeState) base;
+            if ("/".equals(kbase.getPath())) {
+                return new KernelRootStateBuilder(kernel, kbase.getRevision());
+            }
+        }
+        return new MemoryNodeStateBuilder(base);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1365522&r1=1365521&r2=1365522&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Wed Jul 25 11:23:27 2012
@@ -16,25 +16,17 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
-import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-import static org.apache.jackrabbit.oak.kernel.CoreValueMapper.TYPE2HINT;
 
 /**
  * {@code NodeStoreBranch} based on {@link MicroKernel} branching and merging.
@@ -82,7 +74,9 @@ class KernelNodeStoreBranch implements N
     public void setRoot(NodeState newRoot) {
         if (!currentRoot.equals(newRoot)) {
             currentRoot = newRoot;
-            commit(buildJsop());
+            JsopDiff diff = new JsopDiff();
+            currentRoot.compareAgainstBaseState(committed, diff);
+            commit(diff.toString());
         }
     }
 
@@ -169,93 +163,4 @@ class KernelNodeStoreBranch implements N
         committed = currentRoot;
     }
 
-    private String buildJsop() {
-        JsopBuilder jsop = new JsopBuilder();
-        diffToJsop(committed, currentRoot, "", jsop);
-        return jsop.toString();
-    }
-
-    private static void diffToJsop(NodeState before, NodeState after, final String path,
-            final JsopBuilder jsop) {
-        after.compareAgainstBaseState(before, new NodeStateDiff() {
-            @Override
-            public void propertyAdded(PropertyState after) {
-                jsop.tag('^').key(buildPath(after.getName()));
-                toJson(after, jsop);
-            }
-
-            @Override
-            public void propertyChanged(PropertyState before, PropertyState after) {
-                jsop.tag('^').key(buildPath(after.getName()));
-                toJson(after, jsop);
-            }
-
-            @Override
-            public void propertyDeleted(PropertyState before) {
-                jsop.tag('^').key(buildPath(before.getName())).value(null);
-            }
-
-            @Override
-            public void childNodeAdded(String name, NodeState after) {
-                jsop.tag('+').key(buildPath(name));
-                toJson(after, jsop);
-            }
-
-            @Override
-            public void childNodeDeleted(String name, NodeState before) {
-                jsop.tag('-').value(buildPath(name));
-            }
-
-            @Override
-            public void childNodeChanged(String name, NodeState before, NodeState after)
{
-                diffToJsop(before, after, PathUtils.concat(path, name), jsop);
-            }
-
-            private String buildPath(String name) {
-                return PathUtils.concat(path, name);
-            }
-
-            private void toJson(NodeState nodeState, JsopBuilder jsop) {
-                jsop.object();
-                for (PropertyState property : nodeState.getProperties()) {
-                    jsop.key(property.getName());
-                    toJson(property, jsop);
-                }
-                for (ChildNodeEntry child : nodeState.getChildNodeEntries()) {
-                    jsop.key(child.getName());
-                    toJson(child.getNodeState(), jsop);
-                }
-                jsop.endObject();
-            }
-
-            private void toJson(PropertyState propertyState, JsopBuilder jsop) {
-                if (propertyState.isArray()) {
-                    jsop.array();
-                    for (CoreValue value : propertyState.getValues()) {
-                        toJson(value, jsop);
-                    }
-                    jsop.endArray();
-                } else {
-                    toJson(propertyState.getValue(), jsop);
-                }
-            }
-
-            private void toJson(CoreValue value, JsopBuilder jsop) {
-                int type = value.getType();
-                if (type == PropertyType.BOOLEAN) {
-                    jsop.value(value.getBoolean());
-                } else if (type == PropertyType.LONG) {
-                    jsop.value(value.getLong());
-                } else {
-                    String string = value.getString();
-                    if (type != PropertyType.STRING
-                            || CoreValueMapper.startsWithHint(string)) {
-                        string = TYPE2HINT.get(type) + ':' + string;
-                    }
-                    jsop.value(string);
-                }
-            }
-
-        });
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootStateBuilder.java?rev=1365522&r1=1365521&r2=1365522&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootStateBuilder.java
Wed Jul 25 11:23:27 2012
@@ -16,15 +16,31 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 class KernelRootStateBuilder extends MemoryNodeStateBuilder {
 
+    /**
+     * Number of content updates that need to happen before the updates
+     * are automatically committed to a branch in the MicroKernel.
+     */
+    private static final int UPDATE_LIMIT = 10000;
+
+    private final MicroKernel kernel;
+
+    private String baseRevision;
+
+    private String branchRevision;
+
     private int updates = 0;
 
-    public KernelRootStateBuilder(NodeState base) {
-        super(base);
+    public KernelRootStateBuilder(MicroKernel kernel, String revision) {
+        super(new KernelNodeState(kernel, "/", revision));
+        this.kernel = kernel;
+        this.baseRevision = revision;
+        this.branchRevision = null;
     }
 
     @Override
@@ -35,7 +51,13 @@ class KernelRootStateBuilder extends Mem
 
     @Override
     protected void updated() {
-        updates++;
+        if (updates++ > UPDATE_LIMIT) {
+            if (branchRevision == null) {
+                branchRevision = kernel.branch(baseRevision);
+            }
+
+            updates = 0;
+        }
     }
 
 }



Mime
View raw message