Author: chetanm
Date: Fri Nov  4 19:38:49 2016
New Revision: 1768082

URL: http://svn.apache.org/viewvc?rev=1768082&view=rev
Log:
OAK-4606 - Avoid persisting rootRevision in PathFilteringDiff

First step - Avoid storing path as it can be computed at runtime

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeStateTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java?rev=1768082&r1=1768081&r2=1768082&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
 Fri Nov  4 19:38:49 2016
@@ -37,6 +37,8 @@ import org.apache.jackrabbit.oak.spi.sta
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
+import static org.apache.jackrabbit.oak.commons.PathUtils.ROOT_PATH;
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
 
 /**
@@ -46,10 +48,8 @@ import static org.apache.jackrabbit.oak.
  */
 class DelegatingDocumentNodeState extends AbstractDocumentNodeState {
     //Hidden props holding DocumentNodeState meta properties
-    static final String PROP_PATH = ":doc-path";
     static final String PROP_REVISION = ":doc-rev";
     static final String PROP_LAST_REV = ":doc-lastRev";
-    private static final int META_PROP_COUNT = 3; //Count of above meta props
 
     private static final Predicate<PropertyState> NOT_META_PROPS = new 
Predicate<PropertyState>() {
         @Override
@@ -62,8 +62,9 @@ class DelegatingDocumentNodeState extend
     private final NodeState delegate;
     private final RevisionVector rootRevision;
     private final boolean fromExternalChange;
+    private final String path;
     private RevisionVector lastRevision;
-    private String path;
+
 
     /**
      * Wraps a given NodeState as a {@link DelegatingDocumentNodeState} if
@@ -75,7 +76,7 @@ class DelegatingDocumentNodeState extend
     public static NodeState wrapIfPossible(NodeState delegate, NodeStateDiffer 
differ) {
         if (hasMetaProps(delegate)) {
             String revVector = getRequiredProp(delegate, PROP_REVISION);
-            return new DelegatingDocumentNodeState(delegate, 
RevisionVector.fromString(revVector), false, differ);
+            return new DelegatingDocumentNodeState(delegate, ROOT_PATH, 
RevisionVector.fromString(revVector), false, differ);
         }
         return delegate;
     }
@@ -86,15 +87,16 @@ class DelegatingDocumentNodeState extend
 
     public static AbstractDocumentNodeState wrap(NodeState delegate, 
NodeStateDiffer differ) {
         String revVector = getRequiredProp(delegate, PROP_REVISION);
-        return new DelegatingDocumentNodeState(delegate, 
RevisionVector.fromString(revVector), false, differ);
+        return new DelegatingDocumentNodeState(delegate, ROOT_PATH, 
RevisionVector.fromString(revVector), false, differ);
     }
 
-    private DelegatingDocumentNodeState(NodeState delegate, RevisionVector 
rootRevision,
+    private DelegatingDocumentNodeState(NodeState delegate, String path, 
RevisionVector rootRevision,
                                        boolean fromExternalChange, 
NodeStateDiffer differ) {
         this.differ = differ;
         this.delegate = delegate;
         this.rootRevision = rootRevision;
         this.fromExternalChange = fromExternalChange;
+        this.path = path;
     }
 
     private DelegatingDocumentNodeState(DelegatingDocumentNodeState original,
@@ -111,9 +113,6 @@ class DelegatingDocumentNodeState extend
 
     @Override
     public String getPath() {
-        if (path == null){
-            this.path = getRequiredProp(PROP_PATH);
-        }
         return path;
     }
 
@@ -176,7 +175,7 @@ class DelegatingDocumentNodeState extend
     @Nonnull
     @Override
     public NodeState getChildNode(@Nonnull String name) throws 
IllegalArgumentException {
-        return decorate(delegate.getChildNode(name));
+        return decorate(name, delegate.getChildNode(name));
     }
 
     @Nonnull
@@ -186,7 +185,7 @@ class DelegatingDocumentNodeState extend
             @Nullable
             @Override
             public ChildNodeEntry apply(ChildNodeEntry input) {
-                return new MemoryChildNodeEntry(input.getName(), 
decorate(input.getNodeState()));
+                return new MemoryChildNodeEntry(input.getName(), 
decorate(input.getName(), input.getNodeState()));
             }
         });
     }
@@ -209,7 +208,7 @@ class DelegatingDocumentNodeState extend
 
     @Override
     public long getPropertyCount() {
-        return delegate.getPropertyCount() - META_PROP_COUNT;
+        return Iterables.size(getProperties());
     }
 
     @Override
@@ -261,9 +260,10 @@ class DelegatingDocumentNodeState extend
 
     //~--------------------------------------------< internal >
 
-    private NodeState decorate(NodeState childNode) {
+    private NodeState decorate(String nodeName, NodeState childNode) {
         if (childNode.exists()) {
-            return new DelegatingDocumentNodeState(childNode, rootRevision, 
fromExternalChange, differ);
+            return new DelegatingDocumentNodeState(childNode, concat(path, 
nodeName), rootRevision,
+                    fromExternalChange, differ);
         }
         return childNode;
     }

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.java?rev=1768082&r1=1768081&r2=1768082&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.java
 Fri Nov  4 19:38:49 2016
@@ -33,7 +33,6 @@ import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState.PROP_LAST_REV;
-import static 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState.PROP_PATH;
 import static 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState.PROP_REVISION;
 import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static 
org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
@@ -105,7 +104,6 @@ class PathFilteringDiff extends ApplyDif
     static void copyMetaProperties(AbstractDocumentNodeState state, 
NodeBuilder builder, List<String> metaPropNames) {
         builder.setProperty(asPropertyState(PROP_REVISION, 
state.getRootRevision()));
         builder.setProperty(asPropertyState(PROP_LAST_REV, 
state.getLastRevision()));
-        builder.setProperty(createProperty(PROP_PATH, state.getPath()));
 
         for (String metaProp : metaPropNames){
             PropertyState ps = state.getProperty(metaProp);

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeStateTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeStateTest.java?rev=1768082&r1=1768081&r2=1768082&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeStateTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeStateTest.java
 Fri Nov  4 19:38:49 2016
@@ -31,7 +31,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.junit.Test;
 
 import static 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState.PROP_LAST_REV;
-import static 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState.PROP_PATH;
 import static 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState.PROP_REVISION;
 import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static 
org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
@@ -49,12 +48,10 @@ public class DelegatingDocumentNodeState
         RevisionVector rv2 = new RevisionVector(new Revision(1,0,3));
         builder.setProperty(asPropertyState(PROP_REVISION, rv1));
         builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
-        builder.setProperty(createProperty(PROP_PATH, "foo"));
         AbstractDocumentNodeState state = 
DelegatingDocumentNodeState.wrap(builder.getNodeState(), 
NodeStateDiffer.DEFAULT_DIFFER);
 
         assertEquals(rv1, state.getRootRevision());
         assertEquals(rv2, state.getLastRevision());
-        assertEquals("foo", state.getPath());
         assertTrue(state.hasNoChildren());
         assertTrue(state.exists());
         assertFalse(state.isFromExternalChange());
@@ -97,7 +94,6 @@ public class DelegatingDocumentNodeState
         RevisionVector rv2 = new RevisionVector(new Revision(1,0,3));
         builder.setProperty(asPropertyState(PROP_REVISION, rv1));
         builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
-        builder.setProperty(createProperty(PROP_PATH, "foo"));
         AbstractDocumentNodeState state = 
DelegatingDocumentNodeState.wrap(builder.getNodeState(), 
NodeStateDiffer.DEFAULT_DIFFER);
 
         AbstractDocumentNodeState state2 = state.withRootRevision(rv1, false);
@@ -136,7 +132,6 @@ public class DelegatingDocumentNodeState
     private static void setMetaProps(NodeBuilder nb){
         nb.setProperty(asPropertyState(PROP_REVISION, new RevisionVector(new 
Revision(1,0,1))));
         nb.setProperty(asPropertyState(PROP_LAST_REV, new RevisionVector(new 
Revision(1,0,1))));
-        nb.setProperty(createProperty(PROP_PATH, "foo"));
     }
 
     private static PropertyState asPropertyState(String name, RevisionVector 
revision) {


Reply via email to