Author: chetanm
Date: Tue Jun 21 06:18:20 2016
New Revision: 1749427

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

Add logging for the case when a large diff is being applied for e.g. in intial 
store creation

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/PathFilteringDiff.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=1749427&r1=1749426&r2=1749427&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:18:20 2016
@@ -26,6 +26,8 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.state.ApplyDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 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;
@@ -34,40 +36,47 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
 
 class PathFilteringDiff extends ApplyDiff {
-    private final PathFilter pathFilter;
+    private static final Logger logger = 
LoggerFactory.getLogger(PathFilteringDiff.class);
+    private final DiffContext ctx;
 
     public PathFilteringDiff(NodeBuilder builder, PathFilter pathFilter) {
+        this(builder, new DiffContext(pathFilter));
+    }
+
+    private PathFilteringDiff(NodeBuilder builder, DiffContext ctx) {
         super(builder);
-        this.pathFilter = pathFilter;
+        this.ctx = ctx;
     }
 
     @Override
     public boolean childNodeAdded(String name, NodeState after) {
         AbstractDocumentNodeState afterDoc = asDocumentState(after);
         String nextPath = afterDoc.getPath();
-        PathFilter.Result result = pathFilter.filter(nextPath);
+        PathFilter.Result result = ctx.pathFilter.filter(nextPath);
         if (result == PathFilter.Result.EXCLUDE){
             return true;
         }
 
+        ctx.traversingNode(nextPath);
         //We avoid this as we need to copy meta properties
         //super.childNodeAdded(name, after);
 
         NodeBuilder childBuilder = builder.child(name);
         copyMetaProperties(afterDoc, childBuilder);
         return after.compareAgainstBaseState(EMPTY_NODE,
-                new PathFilteringDiff(childBuilder, pathFilter));
+                new PathFilteringDiff(childBuilder, ctx));
     }
 
     @Override
     public boolean childNodeChanged(String name, NodeState before, NodeState 
after) {
         AbstractDocumentNodeState afterDoc = asDocumentState(after);
         String nextPath = afterDoc.getPath();
-        if (pathFilter.filter(nextPath) != PathFilter.Result.EXCLUDE) {
+        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), 
pathFilter));
+                    before, new PathFilteringDiff(builder.getChildNode(name), 
ctx));
         }
         return true;
     }
@@ -75,7 +84,7 @@ class PathFilteringDiff extends ApplyDif
     @Override
     public boolean childNodeDeleted(String name, NodeState before) {
         String path = asDocumentState(before).getPath();
-        if (pathFilter.filter(path) != PathFilter.Result.EXCLUDE) {
+        if (ctx.pathFilter.filter(path) != PathFilter.Result.EXCLUDE) {
             return super.childNodeDeleted(name, before);
         }
         return true;
@@ -94,4 +103,19 @@ class PathFilteringDiff extends ApplyDif
     private static AbstractDocumentNodeState asDocumentState(NodeState state){
         return (AbstractDocumentNodeState) state;
     }
+
+    private static class DiffContext {
+        private long count;
+        final PathFilter pathFilter;
+
+        public DiffContext(PathFilter filter) {
+            this.pathFilter = filter;
+        }
+
+        public void traversingNode(String path){
+            if (++count % 10000 == 0) {
+                logger.info("Updating Secondary Store. Traversed #{} - {}", 
count, path);
+            }
+        }
+    }
 }


Reply via email to