Author: mreutegg
Date: Tue Sep 10 13:01:02 2019
New Revision: 1866750
URL: http://svn.apache.org/viewvc?rev=1866750&view=rev
Log:
OAK-8591: Conflict exception on commit
Merge revisions 1866382,1866697,1866730 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/NodeDocument.java
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Sep 10 13:01:02 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,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853083,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854579-1854580,1854596,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855522,1855776,1855905,1855993,1856049,1856056,1856538,1856545,1857000,1857010,1857104,1857159,1857212,1857221,1857238,1857242,1857247,1857253,1857294,1857314,1857332,1857463,1857480,1857577,1857589,1857592,1857627,1857634-1857635,1857638,1857640,1857687,1857936,1858032,1858053,1858123,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1858931,1859020,1859231,1859292,1859294,1859350-1859351,1859359,1859365,1859533,1859609
,1859612,1859619,1859711,1859716,1859772,1859776,1859780,1859843,1859854,1859881,1860120,1860131,1860137,1860202,1860278,1860328,1860330,1860355,1860393,1860442,1860548,1860564-1860565,1860931,1861114,1861270,1861626,1861743,1861757,1861763,1861770,1861776,1861780,1862044,1862093,1862266,1862370,1862422,1862447-1862448,1862465,1862499,1862531,1862536-1862537,1862728,1862746,1862806,1862817,1862881,1862926-1862927,1862976-1862977,1863076,1863081,1863086,1863369,1863405,1863540,1863633-1863634,1863642,1863645,1864349,1864353,1864667,1864674,1864681,1864683,1865752,1866457
+/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853083,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854579-1854580,1854596,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855522,1855776,1855905,1855993,1856049,1856056,1856538,1856545,1857000,1857010,1857104,1857159,1857212,1857221,1857238,1857242,1857247,1857253,1857294,1857314,1857332,1857463,1857480,1857577,1857589,1857592,1857627,1857634-1857635,1857638,1857640,1857687,1857936,1858032,1858053,1858123,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1858931,1859020,1859231,1859292,1859294,1859350-1859351,1859359,1859365,1859533,1859609
,1859612,1859619,1859711,1859716,1859772,1859776,1859780,1859843,1859854,1859881,1860120,1860131,1860137,1860202,1860278,1860328,1860330,1860355,1860393,1860442,1860548,1860564-1860565,1860931,1861114,1861270,1861626,1861743,1861757,1861763,1861770,1861776,1861780,1862044,1862093,1862266,1862370,1862422,1862447-1862448,1862465,1862499,1862531,1862536-1862537,1862728,1862746,1862806,1862817,1862881,1862926-1862927,1862976-1862977,1863076,1863081,1863086,1863369,1863405,1863540,1863633-1863634,1863642,1863645,1864349,1864353,1864667,1864674,1864681,1864683,1865752,1866382,1866457,1866697,1866730
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java?rev=1866750&r1=1866749&r2=1866750&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
(original)
+++
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
Tue Sep 10 13:01:02 2019
@@ -872,19 +872,15 @@ public final class NodeDocument extends
if (validRevisions.containsKey(rev)) {
return true;
}
- if (Utils.isCommitted(commitValue) && !readRevision.isBranch()) {
- // no need to load commit root document, we can simply
- // tell by looking at the commit revision whether the
- // revision is valid/visible
- Revision commitRev = Utils.resolveCommitRevision(rev, commitValue);
- return !readRevision.isRevisionNewer(commitRev);
+ // get the commit value if it is not yet available
+ if (commitValue == null) {
+ commitValue = context.getCommitValue(rev, this);
}
-
- NodeDocument doc = getCommitRoot(rev);
- if (doc == null) {
+ if (commitValue == null) {
+ // this change is not committed, hence not valid/visible
return false;
}
- if (doc.isVisible(context, rev, commitValue, readRevision)) {
+ if (isVisible(context, rev, commitValue, readRevision)) {
validRevisions.put(rev, commitValue);
return true;
}
@@ -2047,22 +2043,15 @@ public final class NodeDocument extends
* to check.
*
* @param revision the revision to check.
- * @param commitValue the commit value of the revision to check or
- * <code>null</code> if unknown.
+ * @param commitValue the commit value of the revision to check.
* @param readRevision the read revision.
* @return <code>true</code> if the revision is visible, otherwise
* <code>false</code>.
*/
private boolean isVisible(@NotNull RevisionContext context,
@NotNull Revision revision,
- @Nullable String commitValue,
+ @NotNull String commitValue,
@NotNull RevisionVector readRevision) {
- if (commitValue == null) {
- commitValue = context.getCommitValue(revision, this);
- }
- if (commitValue == null) {
- return false;
- }
if (Utils.isCommitted(commitValue)) {
Branch b = context.getBranches().getBranch(readRevision);
if (b == null) {
Modified:
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java?rev=1866750&r1=1866749&r2=1866750&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
(original)
+++
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentTest.java
Tue Sep 10 13:01:02 2019
@@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.document;
+import java.lang.ref.ReferenceQueue;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@@ -23,6 +24,9 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -50,7 +54,9 @@ import static org.apache.jackrabbit.oak.
import static
org.apache.jackrabbit.oak.plugins.document.util.Utils.getIdFromPath;
import static
org.apache.jackrabbit.oak.plugins.document.util.Utils.getRootDocument;
import static org.hamcrest.CoreMatchers.everyItem;
+import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.lessThan;
+import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -473,6 +479,102 @@ public class NodeDocumentTest {
}
@Test
+ public void getNewestRevisionAfterGC() throws Exception {
+ getNewestRevisionAfterGC(false);
+ }
+
+ @Test
+ public void getNewestRevisionAfterGCWithBranchCommit() throws Exception {
+ getNewestRevisionAfterGC(true);
+ }
+
+ @Test
+ public void getNodeAtRevisionAfterGC() throws Exception {
+ getNodeAtRevisionAfterGC(false);
+ }
+
+ @Test
+ public void getNodeAtRevisionAfterGCWithBranchRevision() throws Exception {
+ getNodeAtRevisionAfterGC(true);
+ }
+
+ private void getNodeAtRevisionAfterGC(boolean withBranch) throws Exception
{
+ DocumentStore store = new MemoryDocumentStore();
+ Revision r = populateStoreAndGC(store);
+
+ // start fresh
+ DocumentNodeStore ns = createTestStore(store, 1, 0, 0);
+ String id = Utils.getIdFromPath("/bar/test");
+ NodeDocument doc = store.find(NODES, id);
+ assertNotNull(doc);
+
+ RevisionVector changeRev = new RevisionVector(r);
+ if (withBranch) {
+ changeRev = changeRev.asBranchRevision(1);
+ }
+ DocumentNodeState state = doc.getNodeAtRevision(ns, changeRev, null);
+ assertNotNull(state);
+ assertEquals(changeRev.asTrunkRevision(), state.getLastRevision());
+ assertNotNull(state.getProperty("p"));
+ }
+
+ private void getNewestRevisionAfterGC(boolean withBranch) throws Exception
{
+ DocumentStore store = new MemoryDocumentStore();
+ Revision r = populateStoreAndGC(store);
+
+ // start fresh
+ DocumentNodeStore ns = createTestStore(store, 1, 0, 0);
+ String id = Utils.getIdFromPath("/bar/test");
+ NodeDocument doc = store.find(NODES, id);
+ assertNotNull(doc);
+
+ RevisionVector baseRev = ns.getHeadRevision();
+ Revision change = ns.newRevision();
+ Branch branch = null;
+ if (withBranch) {
+ SortedSet<Revision> branchCommits = new
TreeSet<>(StableRevisionComparator.REVERSE);
+ branchCommits.add(change);
+ branch = new Branch(branchCommits, baseRev, new
ReferenceQueue<>(), null);
+ baseRev = baseRev.asBranchRevision(1);
+ }
+ Revision rev = doc.getNewestRevision(ns, baseRev, change, branch, new
HashSet<>());
+ assertEquals(r, rev);
+ }
+
+ private Revision populateStoreAndGC(DocumentStore store) throws Exception {
+ DocumentNodeStore ns = createTestStore(store, 1, 0);
+ NodeBuilder builder = ns.getRoot().builder();
+ builder.child("foo");
+ builder.child("bar").child("test").setProperty("p", "v");
+ merge(ns, builder);
+ // remember the revision
+ Revision r = ns.getHeadRevision().getRevision(1);
+ // perform changes that move the commit information
+ // to split documents
+ for (int i = 0; i < 100; i++) {
+ builder = ns.getRoot().builder();
+ builder.setProperty("p", "v-" + i);
+ merge(ns, builder);
+ }
+ ns.runBackgroundOperations();
+ String rootId = Utils.getIdFromPath("/");
+ NodeDocument rootDoc = store.find(NODES, rootId);
+ assertNotNull(rootDoc);
+ assertThat(rootDoc.getPreviousRanges().keySet(), not(empty()));
+
+ // trigger revision gc until split doc is removed
+ while (!rootDoc.getPreviousRanges().keySet().isEmpty()) {
+ ns.getVersionGarbageCollector().gc(1, TimeUnit.MILLISECONDS);
+ rootDoc = store.find(NODES, rootId);
+ assertNotNull(rootDoc);
+ }
+
+ ns.dispose();
+
+ return r;
+ }
+
+ @Test
public void getChanges() throws Exception {
final int numChanges = 200;
Random random = new Random();