Author: chetanm
Date: Fri Nov  4 14:36:33 2016
New Revision: 1768045

URL: http://svn.apache.org/viewvc?rev=1768045&view=rev
Log:
OAK-5067 - Node bundling does not work with SecondaryNodeStore feature

Ensure that required meta properties get copied to the cloned NodeState. Other 
meta properties like for child  ':doc-self' etc are not required to be copied 
as they are only needed by DocumentNodeState for reading bundled nodes. In case 
of DelegatingDocumentNodeState the child nodes would not be bundled

So only important property is :doc-pattern as that determines if the node is 
bundled or not

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1768045&r1=1768044&r2=1768045&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 Fri Nov  4 14:36:33 2016
@@ -72,6 +72,7 @@ import com.google.common.base.Predicate;
 import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import com.google.common.cache.Cache;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -86,6 +87,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob;
 import org.apache.jackrabbit.oak.plugins.document.Branch.BranchCommit;
 import 
org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler;
+import org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor;
 import 
org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache;
 import 
org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.DynamicBroadcastConfig;
 import 
org.apache.jackrabbit.oak.plugins.document.util.ReadOnlyDocumentStoreWrapperFactory;
@@ -138,6 +140,15 @@ public final class DocumentNodeStore
     static final int NUM_CHILDREN_CACHE_LIMIT = 
Integer.getInteger("oak.documentMK.childrenCacheLimit", 16 * 1024);
 
     /**
+     * List of meta properties which are created by DocumentNodeStore and 
which needs to be
+     * retained in any cloned copy of DocumentNodeState. This does not include 
other properties defined
+     * in DocumentBundlor as those are only required by DocumentNodeState
+     */
+    public static final List<String> META_PROP_NAMES = ImmutableList.of(
+            DocumentBundlor.META_PROP_PATTERN
+    );
+
+    /**
      * Feature flag to enable concurrent add/remove operations of hidden empty
      * nodes. See OAK-2673.
      */

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=1768045&r1=1768044&r2=1768045&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 14:36:33 2016
@@ -19,6 +19,8 @@
 
 package org.apache.jackrabbit.oak.plugins.document.secondary;
 
+import java.util.List;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState;
 import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
@@ -41,8 +43,8 @@ class PathFilteringDiff extends ApplyDif
     private final DiffContext ctx;
     private final AbstractDocumentNodeState parent;
 
-    public PathFilteringDiff(NodeBuilder builder, PathFilter pathFilter, 
AbstractDocumentNodeState parent) {
-        this(builder, new DiffContext(pathFilter), parent);
+    public PathFilteringDiff(NodeBuilder builder, PathFilter pathFilter, 
List<String> metaPropNames, AbstractDocumentNodeState parent) {
+        this(builder, new DiffContext(pathFilter, metaPropNames), parent);
     }
 
     private PathFilteringDiff(NodeBuilder builder, DiffContext ctx, 
AbstractDocumentNodeState parent) {
@@ -65,7 +67,7 @@ class PathFilteringDiff extends ApplyDif
         //super.childNodeAdded(name, after);
 
         NodeBuilder childBuilder = builder.child(name);
-        copyMetaProperties(afterDoc, childBuilder);
+        copyMetaProperties(afterDoc, childBuilder, ctx.metaPropNames);
         return after.compareAgainstBaseState(EMPTY_NODE,
                 new PathFilteringDiff(childBuilder, ctx, afterDoc));
     }
@@ -77,7 +79,7 @@ class PathFilteringDiff extends ApplyDif
         if (ctx.pathFilter.filter(nextPath) != PathFilter.Result.EXCLUDE) {
             ctx.traversingNode(nextPath);
             NodeBuilder childBuilder = builder.getChildNode(name);
-            copyMetaProperties(afterDoc, childBuilder);
+            copyMetaProperties(afterDoc, childBuilder, ctx.metaPropNames);
             return after.compareAgainstBaseState(
                     before, new PathFilteringDiff(builder.getChildNode(name), 
ctx, afterDoc));
         }
@@ -100,10 +102,17 @@ class PathFilteringDiff extends ApplyDif
         return (AbstractDocumentNodeState) state;
     }
 
-    static void copyMetaProperties(AbstractDocumentNodeState state, 
NodeBuilder builder) {
+    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);
+            if (ps != null){
+                builder.setProperty(ps);
+            }
+        }
     }
 
     private static PropertyState asPropertyState(String name, RevisionVector 
revision) {
@@ -113,9 +122,11 @@ class PathFilteringDiff extends ApplyDif
     private static class DiffContext {
         private long count;
         final PathFilter pathFilter;
+        final List<String> metaPropNames;
 
-        public DiffContext(PathFilter filter) {
+        public DiffContext(PathFilter filter, List<String> metaPropNames) {
             this.pathFilter = filter;
+            this.metaPropNames = metaPropNames;
         }
 
         public void traversingNode(String path){

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java?rev=1768045&r1=1768044&r2=1768045&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
 Fri Nov  4 14:36:33 2016
@@ -20,7 +20,9 @@
 package org.apache.jackrabbit.oak.plugins.document.secondary;
 
 import java.util.Collections;
+import java.util.List;
 
+import com.google.common.collect.ImmutableList;
 import org.apache.jackrabbit.oak.plugins.document.NodeStateDiffer;
 import org.apache.jackrabbit.oak.plugins.index.PathFilter;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -33,6 +35,7 @@ public class SecondaryStoreBuilder {
     private PathFilter pathFilter = new PathFilter(singletonList("/"), 
Collections.<String>emptyList());
     private NodeStateDiffer differ = NodeStateDiffer.DEFAULT_DIFFER;
     private StatisticsProvider statsProvider = StatisticsProvider.NOOP;
+    private List<String> metaPropNames = Collections.emptyList();
 
     public SecondaryStoreBuilder(NodeStore nodeStore) {
         this.store = nodeStore;
@@ -53,6 +56,11 @@ public class SecondaryStoreBuilder {
         return this;
     }
 
+    public SecondaryStoreBuilder metaPropNames(List<String> metaPropNames) {
+        this.metaPropNames = ImmutableList.copyOf(metaPropNames);
+        return this;
+    }
+
     public SecondaryStoreCache buildCache() {
         return new SecondaryStoreCache(store, differ, pathFilter, 
statsProvider);
     }
@@ -62,6 +70,6 @@ public class SecondaryStoreBuilder {
     }
 
     public SecondaryStoreObserver buildObserver(SecondaryStoreRootObserver 
secondaryStoreRootObserver) {
-        return new SecondaryStoreObserver(store, differ, pathFilter, 
statsProvider, secondaryStoreRootObserver);
+        return new SecondaryStoreObserver(store, metaPropNames, differ, 
pathFilter, statsProvider, secondaryStoreRootObserver);
     }
 }

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java?rev=1768045&r1=1768044&r2=1768045&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
 Fri Nov  4 14:36:33 2016
@@ -30,7 +30,6 @@ import javax.annotation.Nonnull;
 import com.google.common.collect.Lists;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyUnbounded;
@@ -142,6 +141,7 @@ public class SecondaryStoreCacheService
 
         SecondaryStoreBuilder builder = new 
SecondaryStoreBuilder(secondaryStoreProvider.getNodeStore())
                 .differ(differ)
+                .metaPropNames(DocumentNodeStore.META_PROP_NAMES)
                 .statisticsProvider(statisticsProvider)
                 .pathFilter(pathFilter);
         SecondaryStoreCache cache = builder.buildCache();

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java?rev=1768045&r1=1768044&r2=1768045&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
 Fri Nov  4 14:36:33 2016
@@ -19,6 +19,7 @@
 
 package org.apache.jackrabbit.oak.plugins.document.secondary;
 
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import javax.annotation.Nonnull;
@@ -46,6 +47,7 @@ class SecondaryStoreObserver implements
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final NodeStore nodeStore;
     private final PathFilter pathFilter;
+    private final List<String> metaPropNames;
     private final SecondaryStoreRootObserver secondaryObserver;
     private final NodeStateDiffer differ;
     private final TimerStats local;
@@ -53,6 +55,7 @@ class SecondaryStoreObserver implements
     private boolean firstEventProcessed;
 
     public SecondaryStoreObserver(NodeStore nodeStore,
+                                  List<String> metaPropNames,
                                   NodeStateDiffer differ,
                                   PathFilter pathFilter,
                                   StatisticsProvider statisticsProvider,
@@ -61,6 +64,7 @@ class SecondaryStoreObserver implements
         this.pathFilter = pathFilter;
         this.secondaryObserver = secondaryObserver;
         this.differ = differ;
+        this.metaPropNames = metaPropNames;
         this.local = statisticsProvider.getTimer("DOCUMENT_CACHE_SEC_LOCAL", 
StatsOptions.DEFAULT);
         this.external = 
statisticsProvider.getTimer("DOCUMENT_CACHE_SEC_EXTERNAL", 
StatsOptions.DEFAULT);
     }
@@ -78,10 +82,10 @@ class SecondaryStoreObserver implements
         NodeState secondaryRoot = nodeStore.getRoot();
         NodeState base = 
DelegatingDocumentNodeState.wrapIfPossible(secondaryRoot, differ);
         NodeBuilder builder = secondaryRoot.builder();
-        ApplyDiff diff = new PathFilteringDiff(builder, pathFilter, target);
+        ApplyDiff diff = new PathFilteringDiff(builder, pathFilter, 
metaPropNames, target);
 
         //Copy the root node meta properties
-        PathFilteringDiff.copyMetaProperties(target, builder);
+        PathFilteringDiff.copyMetaProperties(target, builder, metaPropNames);
 
         //Apply the rest of properties
         target.compareAgainstBaseState(base, diff);

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java?rev=1768045&r1=1768044&r2=1768045&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
 Fri Nov  4 14:36:33 2016
@@ -218,7 +218,6 @@ public class SecondaryStoreCacheTest {
         assertFalse(cache.isCached("/x"));
     }
 
-    @Ignore("OAK-5067")
     @Test
     public void bundledNodes() throws Exception{
         SecondaryStoreCache cache = createCache(new PathFilter(of("/"), 
empty));
@@ -251,6 +250,7 @@ public class SecondaryStoreCacheTest {
 
     private SecondaryStoreCache createCache(PathFilter pathFilter){
         SecondaryStoreBuilder builder = createBuilder(pathFilter);
+        builder.metaPropNames(DocumentNodeStore.META_PROP_NAMES);
         SecondaryStoreCache cache = builder.buildCache();
         SecondaryStoreObserver observer = builder.buildObserver(cache);
         primary.addObserver(observer);


Reply via email to