jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1583951 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/ test/java/org/apache/jackrabbit/oak/plugins/document/
Date Wed, 02 Apr 2014 10:04:46 GMT
Author: mreutegg
Date: Wed Apr  2 10:04:46 2014
New Revision: 1583951

URL: http://svn.apache.org/r1583951
Log:
OAK-1662: Node not accessible after document split

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java?rev=1583951&r1=1583950&r2=1583951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
Wed Apr  2 10:04:46 2014
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
@@ -53,7 +54,7 @@ public class Commit {
     private final Revision revision;
     private HashMap<String, UpdateOp> operations = new LinkedHashMap<String, UpdateOp>();
     private JsopWriter diff = new JsopStream();
-    private List<Revision> collisions = new ArrayList<Revision>();
+    private Set<Revision> collisions = new LinkedHashSet<Revision>();
 
     /**
      * List of all node paths which have been modified in this commit. In addition to the
nodes

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1583951&r1=1583950&r2=1583951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Wed Apr  2 10:04:46 2014
@@ -1210,7 +1210,7 @@ public final class DocumentNodeStore
     @Override
     public NodeState merge(@Nonnull NodeBuilder builder,
                            @Nonnull CommitHook commitHook,
-                           @Nullable CommitInfo info)
+                           @Nonnull CommitInfo info)
             throws CommitFailedException {
         return asDocumentRootBuilder(builder).merge(commitHook, info);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java?rev=1583951&r1=1583950&r2=1583951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
Wed Apr  2 10:04:46 2014
@@ -581,29 +581,45 @@ public final class NodeDocument extends 
      * @return the revision, or null if deleted
      */
     @CheckForNull
-    public Revision getNewestRevision(RevisionContext context,
-                                      Revision changeRev,
-                                      CollisionHandler handler) {
-        // no need to look at all commits. the primary document
-        // always contains at least one commit, including all
-        // branch commits which are not yet merged
+    public Revision getNewestRevision(final RevisionContext context,
+                                      final Revision changeRev,
+                                      final CollisionHandler handler) {
+        final Map<Revision, String> validRevisions = Maps.newHashMap();
+        Predicate<Revision> predicate = new Predicate<Revision>() {
+            @Override
+            public boolean apply(Revision input) {
+                if (input.equals(changeRev)) {
+                    return false;
+                }
+                if (isValidRevision(context, input, null, changeRev, validRevisions)) {
+                    return true;
+                }
+                handler.concurrentModification(input);
+                return false;
+            }
+        };
+
+        Revision newestRev = null;
+        // check local commits first
         SortedMap<Revision, String> revisions = getLocalRevisions();
         SortedMap<Revision, String> commitRoots = getLocalCommitRoot();
-        Revision newestRev = null;
-        for (Revision r : Iterables.mergeSorted(
+        Iterator<Revision> it = filter(Iterables.mergeSorted(
                 Arrays.asList(revisions.keySet(), commitRoots.keySet()),
-                revisions.comparator())) {
-            if (!r.equals(changeRev)) {
-                if (isValidRevision(context, r, null, changeRev, new HashMap<Revision,
String>())) {
-                    newestRev = r;
-                    // found newest revision, no need to check more revisions
-                    // revisions are sorted newest first
-                    break;
-                } else {
-                    handler.concurrentModification(r);
-                }
+                revisions.comparator()), predicate).iterator();
+        if (it.hasNext()) {
+            newestRev = it.next();
+        } else {
+            // check full history (only needed in rare cases)
+            it = filter(Iterables.mergeSorted(
+                    Arrays.asList(
+                            getValueMap(REVISIONS).keySet(),
+                            getValueMap(COMMIT_ROOT).keySet()),
+                    revisions.comparator()), predicate).iterator();
+            if (it.hasNext()) {
+                newestRev = it.next();
             }
         }
+
         if (newestRev == null) {
             return null;
         }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1583951&r1=1583950&r2=1583951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Wed Apr  2 10:04:46 2014
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.kernel.
 import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.util.TimingDocumentStoreWrapper;
 import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
@@ -237,4 +238,33 @@ public class DocumentNodeStoreTest {
 
         mk.dispose();
     }
+
+    // OAK-1662
+    @Test
+    public void getNewestRevision() throws Exception {
+        DocumentStore docStore = new MemoryDocumentStore();
+        DocumentNodeStore ns1 = new DocumentMK.Builder()
+                .setDocumentStore(docStore).setAsyncDelay(0)
+                .setClusterId(1).getNodeStore();
+        ns1.getRoot();
+        ns1.runBackgroundOperations();
+        DocumentNodeStore ns2 = new DocumentMK.Builder()
+                .setDocumentStore(docStore).setAsyncDelay(0)
+                .setClusterId(2).getNodeStore();
+        ns2.getRoot();
+
+        NodeBuilder b1 = ns1.getRoot().builder();
+        for (int i = 0; i < NodeDocument.NUM_REVS_THRESHOLD; i++) {
+            b1.setProperty("p", String.valueOf(i));
+            ns1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+        }
+        ns1.runBackgroundOperations();
+
+        NodeBuilder b2 = ns2.getRoot().builder();
+        b2.setProperty("q", "value");
+        ns2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        ns1.dispose();
+        ns2.dispose();
+    }
 }



Mime
View raw message