Author: mreutegg
Date: Tue Mar 12 11:46:24 2019
New Revision: 1855312

URL: http://svn.apache.org/viewvc?rev=1855312&view=rev
Log:
OAK-8108: Branch reset does not remove all branch commit entries

Merged revisions 1854848 and 1854859 from trunk

Modified:
    jackrabbit/oak/branches/1.10/   (props changed)
    
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ResetDiff.java
    
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKResetTest.java

Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 12 11:46:24 2019
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854701,1855221
+/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854701,1854848,1854859,1855221
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1855312&r1=1855311&r2=1855312&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 (original)
+++ 
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 Tue Mar 12 11:46:24 2019
@@ -1661,6 +1661,7 @@ public final class DocumentNodeStore
         for (Revision r : reverse(revs)) {
             NodeDocument.removeCollision(rootOp, r.asTrunkRevision());
             NodeDocument.removeRevision(rootOp, r.asTrunkRevision());
+            NodeDocument.removeBranchCommit(rootOp, r.asTrunkRevision());
             operations.clear();
             BranchCommit bc = b.getCommit(r);
             if (bc.isRebase()) {

Modified: 
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ResetDiff.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ResetDiff.java?rev=1855312&r1=1855311&r2=1855312&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ResetDiff.java
 (original)
+++ 
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ResetDiff.java
 Tue Mar 12 11:46:24 2019
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
@@ -35,6 +36,7 @@ import static org.apache.jackrabbit.oak.
  */
 class ResetDiff implements NodeStateDiff {
 
+    private final ResetDiff parent;
     private final Revision revision;
     private final String path;
     private final Map<String, UpdateOp> operations;
@@ -42,12 +44,14 @@ class ResetDiff implements NodeStateDiff
 
     ResetDiff(@NotNull Revision revision,
               @NotNull Map<String, UpdateOp> operations) {
-        this(revision, "/", operations);
+        this(null, revision, "/", operations);
     }
 
-    private ResetDiff(@NotNull Revision revision,
+    private ResetDiff(@Nullable ResetDiff parent,
+                      @NotNull Revision revision,
                       @NotNull String path,
                       @NotNull Map<String, UpdateOp> operations) {
+        this.parent = parent;
         this.revision = checkNotNull(revision);
         this.path = checkNotNull(path);
         this.operations = checkNotNull(operations);
@@ -75,9 +79,14 @@ class ResetDiff implements NodeStateDiff
     public boolean childNodeAdded(String name, NodeState after) {
         NodeDocument.removeCommitRoot(getUpdateOp(), revision);
         String p = PathUtils.concat(path, name);
-        ResetDiff diff = new ResetDiff(revision, p, operations);
+        ResetDiff diff = new ResetDiff(this, revision, p, operations);
         UpdateOp op = diff.getUpdateOp();
         NodeDocument.removeDeleted(op, revision);
+        NodeDocument.setDeletedOnce(op);
+        if (parent != null) {
+            // make sure branch related entries are removed also on the parent
+            parent.getUpdateOp();
+        }
         return after.compareAgainstBaseState(EMPTY_NODE, diff);
     }
 
@@ -87,13 +96,13 @@ class ResetDiff implements NodeStateDiff
                                     NodeState after) {
         String p = PathUtils.concat(path, name);
         return after.compareAgainstBaseState(before,
-                new ResetDiff(revision, p, operations));
+                new ResetDiff(this, revision, p, operations));
     }
 
     @Override
     public boolean childNodeDeleted(String name, NodeState before) {
         String p = PathUtils.concat(path, name);
-        ResetDiff diff = new ResetDiff(revision, p, operations);
+        ResetDiff diff = new ResetDiff(this, revision, p, operations);
         NodeDocument.removeDeleted(diff.getUpdateOp(), revision);
         return MISSING_NODE.compareAgainstBaseState(before, diff);
     }
@@ -112,6 +121,7 @@ class ResetDiff implements NodeStateDiff
             }
             NodeDocument.removeRevision(update, revision);
             NodeDocument.removeCommitRoot(update, revision);
+            NodeDocument.removeBranchCommit(update, revision);
         }
         return update;
     }

Modified: 
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKResetTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKResetTest.java?rev=1855312&r1=1855311&r2=1855312&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKResetTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKResetTest.java
 Tue Mar 12 11:46:24 2019
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.Map;
 
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.junit.Test;
 
 import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
@@ -165,6 +166,30 @@ public class DocumentMKResetTest extends
     }
 
     @Test
+    public void resetRemovesBranchCommitEntries() {
+        DocumentStore store = mk.getDocumentStore();
+
+        addNodes(null, "/foo");
+        String b0 = mk.branch(null);
+        String b1 = addNodes(b0, "/foo/bar");
+
+        NodeDocument foo = store.find(NODES, getIdFromPath("/foo"));
+        assertNotNull(foo);
+        assertTrue(foo.getLocalCommitRoot().containsKey(
+                Revision.fromString(b1).asTrunkRevision()));
+
+        addNodes(null, "/foo/bar");
+
+        mk.reset(b1, b0);
+
+        // reset must also remove _bc entry on parent document
+        Revision r = Revision.fromString(b1).asTrunkRevision();
+        for (NodeDocument doc : Utils.getAllDocuments(store)) {
+            assertFalse(doc.getId(), doc.getLocalBranchCommits().contains(r));
+        }
+    }
+
+    @Test
     public void resetMultipleCommits() {
         DocumentStore store = mk.getDocumentStore();
 


Reply via email to