jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1539296 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk: Commit.java MongoNodeStore.java NodeDocument.java
Date Wed, 06 Nov 2013 10:18:31 GMT
Author: mreutegg
Date: Wed Nov  6 10:18:31 2013
New Revision: 1539296

URL: http://svn.apache.org/r1539296
Log:
OAK-1080: MongoMK: improved concurrency
- set _lastRev on insert, in all other cases update _lastRev with background thread

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java?rev=1539296&r1=1539295&r2=1539296&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java
Wed Nov  6 10:18:31 2013
@@ -212,6 +212,10 @@ public class Commit {
             } else {
                 NodeDocument.setCommitRoot(op, revision, commitRootDepth);
                 if (op.isNew()) {
+                    // for new nodes we can safely set _lastRev on insert.
+                    // for existing nodes the _lastRev is updated by the
+                    // background thread to avoid concurrent updates
+                    NodeDocument.setLastRev(op, revision);
                     newNodes.add(op);
                 } else {
                     changedNodes.add(op);
@@ -237,6 +241,9 @@ public class Commit {
                             // (because there might be a conflict)
                             NodeDocument.unsetRevision(commitRoot, revision);
                         }
+                        // setting _lastRev is only safe on insert. now the
+                        // background thread needs to take care of it
+                        NodeDocument.unsetLastRev(op, revision.getClusterId());
                         changedNodes.add(op);
                     }
                     newNodes.clear();
@@ -442,9 +449,10 @@ public class Commit {
             }
             UpdateOp op = operations.get(path);
             boolean isNew = op != null && op.isNew();
-            boolean isWritten = op != null;
+            boolean pendingLastRev = op == null
+                    || !NodeDocument.hasLastRev(op, revision.getClusterId());
             boolean isDelete = op != null && op.isDelete();
-            nodeStore.applyChanges(revision, path, isNew, isDelete, isWritten, isBranchCommit,
added, removed);
+            nodeStore.applyChanges(revision, path, isNew, isDelete, pendingLastRev, isBranchCommit,
added, removed);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java?rev=1539296&r1=1539295&r2=1539296&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
Wed Nov  6 10:18:31 2013
@@ -644,14 +644,14 @@ public final class MongoNodeStore
      * @param path the path
      * @param isNew whether this is a new node
      * @param isDelete whether the node is deleted
-     * @param isWritten whether the MongoDB documented was added / updated
+     * @param pendingLastRev whether the node has a pending _lastRev to write
      * @param isBranchCommit whether this is from a branch commit
      * @param added the list of added child nodes
      * @param removed the list of removed child nodes
      *
      */
     public void applyChanges(Revision rev, String path,
-                             boolean isNew, boolean isDelete, boolean isWritten,
+                             boolean isNew, boolean isDelete, boolean pendingLastRev,
                              boolean isBranchCommit, ArrayList<String> added,
                              ArrayList<String> removed) {
         UnsavedModifications unsaved = unsavedLastRevisions;
@@ -659,17 +659,19 @@ public final class MongoNodeStore
             Revision branchRev = rev.asBranchRevision();
             unsaved = branches.getBranch(branchRev).getModifications(branchRev);
         }
-        // write back _lastRev with background thread
-        Revision prev = unsaved.put(path, rev);
-        if (prev != null) {
-            if (isRevisionNewer(prev, rev)) {
-                // revert
-                unsaved.put(path, prev);
-                String msg = String.format("Attempt to update " +
-                        "unsavedLastRevision for %s with %s, which is " +
-                        "older than current %s.",
-                        path, rev, prev);
-                throw new MicroKernelException(msg);
+        if (isBranchCommit || pendingLastRev) {
+            // write back _lastRev with background thread
+            Revision prev = unsaved.put(path, rev);
+            if (prev != null) {
+                if (isRevisionNewer(prev, rev)) {
+                    // revert
+                    unsaved.put(path, prev);
+                    String msg = String.format("Attempt to update " +
+                            "unsavedLastRevision for %s with %s, which is " +
+                            "older than current %s.",
+                            path, rev, prev);
+                    throw new MicroKernelException(msg);
+                }
             }
         }
         String key = path + "@" + rev;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java?rev=1539296&r1=1539295&r2=1539296&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
Wed Nov  6 10:18:31 2013
@@ -813,6 +813,16 @@ public class NodeDocument extends Docume
                 revision.toString());
     }
 
+    public static boolean hasLastRev(@Nonnull UpdateOp op, int clusterId) {
+        return checkNotNull(op).getChanges().containsKey(
+                new Key(LAST_REV, new Revision(0, 0, clusterId)));
+    }
+
+    public static void unsetLastRev(@Nonnull UpdateOp op, int clusterId) {
+        checkNotNull(op).unsetMapEntry(LAST_REV,
+                new Revision(0, 0, clusterId));
+    }
+
     public static void setCommitRoot(@Nonnull UpdateOp op,
                                      @Nonnull Revision revision,
                                      int commitRootDepth) {



Mime
View raw message