jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1583584 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecovery.java
Date Tue, 01 Apr 2014 09:47:46 GMT
Author: chetanm
Date: Tue Apr  1 09:47:46 2014
New Revision: 1583584

URL: http://svn.apache.org/r1583584
Log:
OAK-1295 - Recovery for missing _lastRev updates (WIP)

Avoid unnecessary updates of lastRev on parent where the lastRev is consistent and only lastRev
for child needs to be fixed

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecovery.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecovery.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecovery.java?rev=1583584&r1=1583583&r2=1583584&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecovery.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecovery.java
Tue Apr  1 09:47:46 2014
@@ -20,11 +20,13 @@
 package org.apache.jackrabbit.oak.plugins.document;
 
 import java.util.Iterator;
+import java.util.Map;
 import java.util.concurrent.locks.ReentrantLock;
 
 import javax.annotation.CheckForNull;
 
 import com.google.common.base.Predicate;
+import com.google.common.collect.Maps;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,11 +46,18 @@ public class LastRevRecovery {
 
     public int recover(Iterator<NodeDocument> suspects, int clusterId) {
         UnsavedModifications unsaved = new UnsavedModifications();
+        UnsavedModifications unsavedParents = new UnsavedModifications();
+
+        //Map of known last rev of checked paths
+        Map<String, Revision> knownLastRevs = Maps.newHashMap();
 
         while (suspects.hasNext()) {
             NodeDocument doc = suspects.next();
 
             Revision currentLastRev = doc.getLastRev().get(clusterId);
+            if (currentLastRev != null) {
+                knownLastRevs.put(doc.getPath(), currentLastRev);
+            }
             Revision lostLastRev = determineMissedLastRev(doc, clusterId);
 
             //1. Update lastRev for this doc
@@ -73,11 +82,24 @@ public class LastRevRecovery {
                         break;
                     }
                     path = PathUtils.getParentPath(path);
-                    unsaved.put(path, lastRevForParents);
+                    unsavedParents.put(path, lastRevForParents);
                 }
             }
         }
 
+        for(String parentPath : unsavedParents.getPaths()){
+            Revision calcLastRev = unsavedParents.get(parentPath);
+            Revision knownLastRev = knownLastRevs.get(parentPath);
+
+            //Copy the calcLastRev of parent only if they have changed
+            //In many case it might happen that parent have consistent lastRev
+            //This check ensures that unnecessary updates are not made
+            if(knownLastRev == null
+                    || calcLastRev.compareRevisionTime(knownLastRev) > 0){
+                unsaved.put(parentPath, calcLastRev);
+            }
+        }
+
         //Note the size before persist as persist operation
         //would empty the internal state
         int size = unsaved.getPaths().size();



Mime
View raw message