jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1490258 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Date Thu, 06 Jun 2013 12:41:29 GMT
Author: jukka
Date: Thu Jun  6 12:41:28 2013
New Revision: 1490258

URL: http://svn.apache.org/r1490258
Log:
OAK-781: Clarify / fix effects of MISSING_NODE as base state of NodeBuilder

Fix the performance issue of a ConnectedHead never actually updating
the head state after a rebase. It would just repeatedly create new
UnconnectedHead instances without ever setting the head field. This
commit makes updating the head field the responsibility of the head()
method, which by centralizing the state transition should help avoid
potential other similar issues.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1490258&r1=1490257&r2=1490258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Thu Jun  6 12:41:28 2013
@@ -142,7 +142,11 @@ public class MemoryNodeBuilder implement
      * @return  head of this builder
      */
     private Head head() {
-        return head.update();
+        Head newHead = head.update();
+        if (newHead != head) {
+            head = newHead;
+        }
+        return newHead;
     }
 
     /**
@@ -381,9 +385,13 @@ public class MemoryNodeBuilder implement
     private abstract static class Head {
 
         /**
-         * Update the {@link MemoryNodeBuilder#head} of this builder by apply any pending
-         * state transition.
-         * @return  the new head of the associated builder.
+         * Returns the up-to-date head of the associated builder. In most
+         * cases the returned value will be the current head instance, but
+         * a different head can be returned if a state transition is needed.
+         * The returned value is then used as the new current head of the
+         * builder.
+         *
+         * @return up-to-date head of the associated builder
          */
         public abstract Head update();
 
@@ -428,16 +436,19 @@ public class MemoryNodeBuilder implement
 
         @Override
         public Head update() {
-            if (revision != rootHead().revision) {
+            long rootRevision = rootHead().revision;
+            if (revision != rootRevision) {
                 // root revision changed: recursively re-get state from parent
                 NodeState parentState = parent.head().getCurrentNodeState();
                 NodeState newState = parentState.getChildNode(name);
                 if (newState instanceof MutableNodeState) {
-                    return head = new ConnectedHead((MutableNodeState) newState);
+                    // transition state to ConnectedHead
+                    return new ConnectedHead((MutableNodeState) newState);
                 } else {
+                    // update to match the latest revision
                     state = newState;
+                    revision = rootRevision;
                 }
-                revision = rootHead().revision;
             }
             return this;
         }
@@ -451,8 +462,9 @@ public class MemoryNodeBuilder implement
         public MutableNodeState getMutableNodeState() {
             // switch to connected state recursively up to the parent
             MutableNodeState parentState = parent.head().getMutableNodeState();
-            head = new ConnectedHead(parentState.getMutableChildNode(name));
-            return head.getMutableNodeState();
+            MutableNodeState state = parentState.getMutableChildNode(name);
+            // triggers a head state transition at next access
+            return new ConnectedHead(state).getMutableNodeState();
         }
 
         @Override
@@ -486,8 +498,9 @@ public class MemoryNodeBuilder implement
                 // the root builder's base state has been reset: transition back
                 // to unconnected and connect again if necessary.
                 return new UnconnectedHead().update();
+            } else {
+                return this;
             }
-            return this;
         }
 
         @Override



Mime
View raw message