You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2016/06/21 06:19:02 UTC

svn commit: r1749430 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary: PathFilteringDiff.java SecondaryStoreObserver.java

Author: chetanm
Date: Tue Jun 21 06:19:02 2016
New Revision: 1749430

URL: http://svn.apache.org/viewvc?rev=1749430&view=rev
Log:
OAK-4180 - Use another NodeStore as a local cache for a remote Document store

At time ClassCastException is being seen. Improve the exception message to provide more details around that

Modified:
    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/SecondaryStoreObserver.java

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=1749430&r1=1749429&r2=1749430&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 Tue Jun 21 06:19:02 2016
@@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.slf4j.Logger;
 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;
@@ -38,19 +39,21 @@ import static org.apache.jackrabbit.oak.
 class PathFilteringDiff extends ApplyDiff {
     private static final Logger logger = LoggerFactory.getLogger(PathFilteringDiff.class);
     private final DiffContext ctx;
+    private final AbstractDocumentNodeState parent;
 
-    public PathFilteringDiff(NodeBuilder builder, PathFilter pathFilter) {
-        this(builder, new DiffContext(pathFilter));
+    public PathFilteringDiff(NodeBuilder builder, PathFilter pathFilter, AbstractDocumentNodeState parent) {
+        this(builder, new DiffContext(pathFilter), parent);
     }
 
-    private PathFilteringDiff(NodeBuilder builder, DiffContext ctx) {
+    private PathFilteringDiff(NodeBuilder builder, DiffContext ctx, AbstractDocumentNodeState parent) {
         super(builder);
         this.ctx = ctx;
+        this.parent = parent;
     }
 
     @Override
     public boolean childNodeAdded(String name, NodeState after) {
-        AbstractDocumentNodeState afterDoc = asDocumentState(after);
+        AbstractDocumentNodeState afterDoc = asDocumentState(after, name);
         String nextPath = afterDoc.getPath();
         PathFilter.Result result = ctx.pathFilter.filter(nextPath);
         if (result == PathFilter.Result.EXCLUDE){
@@ -64,32 +67,39 @@ class PathFilteringDiff extends ApplyDif
         NodeBuilder childBuilder = builder.child(name);
         copyMetaProperties(afterDoc, childBuilder);
         return after.compareAgainstBaseState(EMPTY_NODE,
-                new PathFilteringDiff(childBuilder, ctx));
+                new PathFilteringDiff(childBuilder, ctx, afterDoc));
     }
 
     @Override
     public boolean childNodeChanged(String name, NodeState before, NodeState after) {
-        AbstractDocumentNodeState afterDoc = asDocumentState(after);
+        AbstractDocumentNodeState afterDoc = asDocumentState(after, name);
         String nextPath = afterDoc.getPath();
         if (ctx.pathFilter.filter(nextPath) != PathFilter.Result.EXCLUDE) {
             ctx.traversingNode(nextPath);
             NodeBuilder childBuilder = builder.getChildNode(name);
             copyMetaProperties(afterDoc, childBuilder);
             return after.compareAgainstBaseState(
-                    before, new PathFilteringDiff(builder.getChildNode(name), ctx));
+                    before, new PathFilteringDiff(builder.getChildNode(name), ctx, afterDoc));
         }
         return true;
     }
 
     @Override
     public boolean childNodeDeleted(String name, NodeState before) {
-        String path = asDocumentState(before).getPath();
+        String path = asDocumentState(before, name).getPath();
         if (ctx.pathFilter.filter(path) != PathFilter.Result.EXCLUDE) {
             return super.childNodeDeleted(name, before);
         }
         return true;
     }
 
+    private AbstractDocumentNodeState asDocumentState(NodeState state, String name){
+        checkArgument(state instanceof AbstractDocumentNodeState, "Node %s (%s) at [%s/%s] is not" +
+                " of expected type i.e. AbstractDocumentNodeState. Parent %s (%s)",
+                state, state.getClass(), parent.getPath(), name, parent, parent.getClass());
+        return (AbstractDocumentNodeState) state;
+    }
+
     static void copyMetaProperties(AbstractDocumentNodeState state, NodeBuilder builder) {
         builder.setProperty(asPropertyState(PROP_REVISION, state.getRevision()));
         builder.setProperty(asPropertyState(PROP_LAST_REV, state.getLastRevision()));
@@ -100,10 +110,6 @@ class PathFilteringDiff extends ApplyDif
         return createProperty(name, revision.asString());
     }
 
-    private static AbstractDocumentNodeState asDocumentState(NodeState state){
-        return (AbstractDocumentNodeState) state;
-    }
-
     private static class DiffContext {
         private long count;
         final PathFilter pathFilter;

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=1749430&r1=1749429&r2=1749430&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 Tue Jun 21 06:19:02 2016
@@ -76,14 +76,14 @@ class SecondaryStoreObserver implements
         }
 
         Stopwatch w = Stopwatch.createStarted();
-        NodeState target = root;
+        AbstractDocumentNodeState target = (AbstractDocumentNodeState) root;
         NodeState secondaryRoot = nodeStore.getRoot();
         NodeState base = DelegatingDocumentNodeState.wrapIfPossible(secondaryRoot, differ);
         NodeBuilder builder = secondaryRoot.builder();
-        ApplyDiff diff = new PathFilteringDiff(builder, pathFilter);
+        ApplyDiff diff = new PathFilteringDiff(builder, pathFilter, target);
 
         //Copy the root node meta properties
-        PathFilteringDiff.copyMetaProperties((AbstractDocumentNodeState) target, builder);
+        PathFilteringDiff.copyMetaProperties(target, builder);
 
         //Apply the rest of properties
         target.compareAgainstBaseState(base, diff);