Author: mreutegg
Date: Wed Aug 14 12:03:56 2019
New Revision: 1865110

URL: http://svn.apache.org/viewvc?rev=1865110&view=rev
Log:
OAK-8538: Incomplete recovery on long running merge with branch commits

Detect branch commits on recovery and enable tests

Modified:
    
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
    
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AddNodesInBranchCommitWithRecoveryTest.java

Modified: 
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java?rev=1865110&r1=1865109&r2=1865110&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
 Wed Aug 14 12:03:56 2019
@@ -159,6 +159,15 @@ public class LastRevRecoveryAgent {
                     startTime = sweepRev.getTimestamp();
                     reason = "sweepRev: " + sweepRev.toString();
                 }
+                // are there branch commits that were merged right before the
+                // process crashed and the recovery needs to go further back?
+                // go through branch commits before startTime and check if 
their
+                // merge revision is newer than startTime
+                Revision bc = getEarliestBranchCommitMergedAround(root, 
startTime, clusterId);
+                if (bc != null) {
+                    startTime = bc.getTimestamp();
+                    reason = "branchRev: " + bc.toString();
+                }
 
                 return recoverCandidates(nodeInfo, startTime, waitUntil, 
reason);
             }
@@ -460,6 +469,38 @@ public class LastRevRecoveryAgent {
 
     //--------------------------< internal 
>------------------------------------
 
+    /**
+     * Get the earliest branch commit before {@code timeMillis} that has been
+     * merged after {@code timeMillis}. This method only considers branch
+     * commits performed by {@code clusterId}.
+     *
+     * @param doc the document to check for branch commits.
+     * @param timeMillis a time in milliseconds since start of the epoch.
+     * @param clusterId a clusterId.
+     * @return earliest branch commit or {@code null} if there is none matching
+     *          the criteria.
+     */
+    @Nullable
+    private Revision getEarliestBranchCommitMergedAround(@NotNull NodeDocument 
doc,
+                                                         long timeMillis,
+                                                         int clusterId) {
+        Revision earliest = null;
+        for (Revision bc : doc.getLocalBranchCommits()) {
+            if (bc.getClusterId() != clusterId) {
+                continue;
+            }
+            String cv = revisionContext.getCommitValue(bc, doc);
+            if (isCommitted(cv)) {
+                Revision mergeRevision = resolveCommitRevision(bc, cv);
+                if (mergeRevision.getTimestamp() > timeMillis
+                        && bc.getTimestamp() < timeMillis) {
+                    earliest = Utils.min(earliest, bc);
+                }
+            }
+        }
+        return earliest;
+    }
+
     @Nullable
     private NodeDocument findNearestAncestorOrSelf(@NotNull Path path,
                                                    @NotNull List<Path> 
missingDocuments) {

Modified: 
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AddNodesInBranchCommitWithRecoveryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AddNodesInBranchCommitWithRecoveryTest.java?rev=1865110&r1=1865109&r2=1865110&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AddNodesInBranchCommitWithRecoveryTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AddNodesInBranchCommitWithRecoveryTest.java
 Wed Aug 14 12:03:56 2019
@@ -25,7 +25,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.stats.Clock;
 import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -35,7 +34,6 @@ import static org.apache.jackrabbit.oak.
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-@Ignore
 public class AddNodesInBranchCommitWithRecoveryTest {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(AddNodesInBranchCommitWithRecoveryTest.class);


Reply via email to