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 mr...@apache.org on 2019/01/30 07:41:01 UTC
svn commit: r1852491 - in /jackrabbit/oak/trunk/oak-store-document/src:
main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java
Author: mreutegg
Date: Wed Jan 30 07:41:01 2019
New Revision: 1852491
URL: http://svn.apache.org/viewvc?rev=1852491&view=rev
Log:
OAK-8008: Unmerged branch changes visible after restart
Revert changes from r1852460 and r1852461
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java
Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java?rev=1852491&r1=1852490&r2=1852491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java Wed Jan 30 07:41:01 2019
@@ -2063,25 +2063,20 @@ public final class NodeDocument extends
return false;
}
if (Utils.isCommitted(commitValue)) {
- Branch b = context.getBranches().getBranch(readRevision);
- if (b == null) {
- // readRevision is not from a branch commit, though it may
- // still be a branch revision when it references the base
- // of a new branch that has not yet been created. In that
- // case the branch revision is equivalent with the trunk
- // revision.
-
+ if (context.getBranches().getBranch(readRevision) == null
+ && !readRevision.isBranch()) {
// resolve commit revision
revision = resolveCommitRevision(revision, commitValue);
+ // readRevision is not from a branch
// compare resolved revision as is
return !readRevision.isRevisionNewer(revision);
} else {
- // read revision is on a branch and the change is committed
- // get the base revision of the branch and check
- // if change is visible from there
- RevisionVector baseRev = b.getBase(readRevision.getBranchRevision());
- revision = resolveCommitRevision(revision, commitValue);
- return !baseRev.isRevisionNewer(revision);
+ // on same merged branch?
+ Revision tr = readRevision.getBranchRevision().asTrunkRevision();
+ if (commitValue.equals(context.getCommitValue(tr, this))) {
+ // compare unresolved revision
+ return !readRevision.isRevisionNewer(revision);
+ }
}
} else {
// branch commit (not merged)
@@ -2092,23 +2087,9 @@ public final class NodeDocument extends
// this is an unmerged branch commit from another cluster node,
// hence never visible to us
return false;
- } else {
- // unmerged branch change with local clusterId
- Branch b = context.getBranches().getBranch(readRevision);
- if (b == null) {
- // reading on trunk never sees changes on an unmerged branch
- return false;
- } else if (b.containsCommit(revision)) {
- // read revision is on the same branch as the
- // unmerged branch changes -> compare revisions as is
- return !readRevision.isRevisionNewer(revision);
- } else {
- // read revision is on a different branch than the
- // unmerged branch changes -> never visible
- return false;
- }
}
}
+ return includeRevision(context, resolveCommitRevision(revision, commitValue), readRevision);
}
/**
@@ -2132,6 +2113,37 @@ public final class NodeDocument extends
return value;
}
+ private static boolean includeRevision(RevisionContext context,
+ Revision x,
+ RevisionVector readRevision) {
+ Branch b = null;
+ if (x.getClusterId() == context.getClusterId()) {
+ RevisionVector branchRev = new RevisionVector(x).asBranchRevision(context.getClusterId());
+ b = context.getBranches().getBranch(branchRev);
+ }
+ if (b != null) {
+ // only include if read revision is also a branch revision
+ // with a history including x
+ if (readRevision.isBranch()
+ && b.containsCommit(readRevision.getBranchRevision())) {
+ // in same branch, include if the same revision or
+ // readRevision is newer
+ return !readRevision.isRevisionNewer(x);
+ }
+ // not part of branch identified by requestedRevision
+ return false;
+ }
+ // assert: x is not a branch commit
+ b = context.getBranches().getBranch(readRevision);
+ if (b != null) {
+ // reset readRevision to branch base revision to make
+ // sure we don't include revisions committed after branch
+ // was created
+ readRevision = b.getBase(readRevision.getBranchRevision());
+ }
+ return !readRevision.isRevisionNewer(x);
+ }
+
/**
* Get the latest property value smaller or equal the readRevision revision.
*
Modified: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java?rev=1852491&r1=1852490&r2=1852491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranchTest.java Wed Jan 30 07:41:01 2019
@@ -16,27 +16,13 @@
*/
package org.apache.jackrabbit.oak.plugins.document;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
-import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
import org.junit.Rule;
import org.junit.Test;
-import static org.apache.jackrabbit.oak.plugins.document.TestUtils.asDocumentState;
import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge;
import static org.apache.jackrabbit.oak.plugins.document.TestUtils.persistToBranch;
-import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getRootDocument;
-import static org.hamcrest.Matchers.contains;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -117,55 +103,4 @@ public class DocumentNodeStoreBranchTest
// expected
}
}
-
- @Test
- public void orphanedBranchTest() {
- MemoryDocumentStore store = new MemoryDocumentStore();
- DocumentNodeStore ns = builderProvider.newBuilder()
- .setDocumentStore(store).build();
- NodeBuilder builder = ns.getRoot().builder();
- builder.setProperty("p", "v");
- persistToBranch(builder);
- ns.dispose();
-
- // start again
- ns = builderProvider.newBuilder()
- .setDocumentStore(store).build();
- assertFalse(ns.getRoot().hasProperty("p"));
- }
-
- @Test
- public void compareBranchStates() {
- DocumentNodeStore ns = builderProvider.newBuilder()
- .setAsyncDelay(0).build();
- ns.runBackgroundOperations();
- DocumentStore store = ns.getDocumentStore();
-
- NodeBuilder builder = ns.getRoot().builder();
- builder.setProperty("p", "a");
- persistToBranch(builder);
- NodeState s1 = builder.getNodeState();
- builder.setProperty("p", "b");
- persistToBranch(builder);
- NodeState s2 = builder.getNodeState();
-
- Set<String> changes = new HashSet<>();
- NodeStateDiff diff = new DefaultNodeStateDiff() {
- @Override
- public boolean propertyChanged(PropertyState before,
- PropertyState after) {
- changes.add(before.getName());
- return super.propertyChanged(before, after);
- }
- };
- s2.compareAgainstBaseState(s1, diff);
- assertThat(changes, contains("p"));
-
- NodeDocument root = getRootDocument(store);
- RevisionVector br = asDocumentState(s1).getRootRevision();
- assertTrue(br.isBranch());
- DocumentNodeState state = root.getNodeAtRevision(ns, br, null);
- assertNotNull(state);
- assertEquals("a", state.getString("p"));
- }
}