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 2015/09/03 16:25:51 UTC

svn commit: r1701032 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java

Author: mreutegg
Date: Thu Sep  3 14:25:50 2015
New Revision: 1701032

URL: http://svn.apache.org/r1701032
Log:
OAK-3344: Commit may add collision marker for committed revision

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java?rev=1701032&r1=1701031&r2=1701032&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java Thu Sep  3 14:25:50 2015
@@ -102,7 +102,7 @@ class Collision {
                                           @Nonnull Revision revision,
                                           @Nonnull DocumentStore store) {
         String p = document.getPath();
-        String commitRootPath = null;
+        String commitRootPath;
         // first check if we can mark the commit with the given revision
         if (document.containsRevision(revision)) {
             if (document.isCommitted(revision)) {
@@ -132,14 +132,25 @@ class Collision {
             return true;
         }
         NodeDocument.addCollision(op, revision);
-        commitRoot = store.createOrUpdate(Collection.NODES, op);
-        // check again on old document right before our update was applied
-        if (commitRoot.isCommitted(revision)) {
+        String commitValue = commitRoot.getLocalRevisions().get(revision);
+        if (commitValue == null) {
+            // no revision entry yet
+            // apply collision marker only if entry is still not there
+            op.containsMapEntry(NodeDocument.REVISIONS, revision, false);
+        } else {
+            // not yet merged branch commit
+            // apply collision marker only if branch commit is still not merged
+            op.equals(NodeDocument.REVISIONS, revision, commitValue);
+        }
+        commitRoot = store.findAndUpdate(Collection.NODES, op);
+        if (commitRoot == null) {
+            // commit state changed meanwhile
+            // -> assume revision is now committed
             return false;
         }
         // otherwise collision marker was set successfully
         LOG.debug("Marked collision on: {} for {} ({})",
-                new Object[]{commitRootPath, p, revision});
+                commitRootPath, p, revision);
         return true;
     }
 

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java?rev=1701032&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java Thu Sep  3 14:25:50 2015
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document.mongo;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
+import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Revision;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
+import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.COLLISIONS;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for OAK-3344
+ */
+public class CollisionMarkerTest extends AbstractMongoConnectionTest {
+
+    private DocumentNodeStore ns1;
+    private DocumentNodeStore ns2;
+
+    @Override
+    public void setUpConnection() throws Exception {
+        mongoConnection = MongoUtils.getConnection();
+        MongoUtils.dropCollections(mongoConnection.getDB());
+        mk = newDocumentMK(mongoConnection);
+        ns1 = mk.getNodeStore();
+    }
+
+    @After
+    public void tearDown() {
+        ns2.dispose();
+    }
+
+    @Test
+    public void conditionalCollisionUpdate() throws Exception {
+        NodeBuilder b1 = ns1.getRoot().builder();
+        b1.child("test");
+        b1.child("node");
+        merge(ns1, b1);
+
+        ns1.runBackgroundOperations();
+        // initialize second node store after background ops
+        // on ns1. this makes sure ns2 sees all changes done so far
+        ns2 = newDocumentMK(MongoUtils.getConnection()).getNodeStore();
+
+        b1 = ns1.getRoot().builder();
+        b1.child("node").child("foo");
+        b1.child("test").setProperty("p", 1);
+        merge(ns1, b1);
+        Revision head = ns1.getHeadRevision();
+
+        NodeBuilder b2 = ns2.getRoot().builder();
+        b2.child("node").child("bar");
+        b2.child("test").setProperty("p", 2);
+        try {
+            merge(ns2, b2);
+            fail("must fail with CommitFailedException");
+        } catch (CommitFailedException e) {
+            // expected
+        }
+
+        String rootId = Utils.getIdFromPath("/");
+        NodeDocument root = ns2.getDocumentStore().find(NODES, rootId);
+        assertFalse("root document must not have a collision marker for a" +
+                " committed revision", root.getValueMap(COLLISIONS).containsKey(head));
+    }
+
+    private static DocumentMK newDocumentMK(MongoConnection c) {
+        // set async delay to a high value to make sure
+        // the commit root is outdated when ns2 commits
+        DocumentMK mk = new DocumentMK.Builder().setAsyncDelay(60000)
+                .setLeaseCheck(false)
+                .setMongoDB(c.getDB()).open();
+        // do not retry on conflicts
+        mk.getNodeStore().setMaxBackOffMillis(0);
+        return mk;
+    }
+
+    private static void merge(NodeStore store, NodeBuilder builder)
+            throws CommitFailedException {
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CollisionMarkerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native