jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1436344 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl: action/FetchHeadRevisionIdAction.java command/CommitCommand.java command/CommitCommandNew.java
Date Mon, 21 Jan 2013 13:41:57 GMT
Author: meteatamel
Date: Mon Jan 21 13:41:56 2013
New Revision: 1436344

URL: http://svn.apache.org/viewvc?rev=1436344&view=rev
Log:
OAK-565 - CommitCommand readExistingNodes/mergeNodes called unnecessarily

Avoid unnecessary read and merge of head revision nodes. This fix needs to be revisited as
OAK-571 is fixed.

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java?rev=1436344&r1=1436343&r2=1436344&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
Mon Jan 21 13:41:56 2013
@@ -31,13 +31,26 @@ import com.mongodb.QueryBuilder;
  */
 public class FetchHeadRevisionIdAction extends BaseAction<Long> {
 
+    private final String branchId;
+
     /**
      * Constructs a new {@code FetchHeadRevisionIdAction}.
      *
      * @param nodeStore Node store.
      */
     public FetchHeadRevisionIdAction(MongoNodeStore nodeStore) {
+        this(nodeStore, null);
+    }
+
+    /**
+     * Constructs a new {@code FetchHeadRevisionIdAction}.
+     *
+     * @param nodeStore Node store.
+     * @param branchId Branch id.
+     */
+    public FetchHeadRevisionIdAction(MongoNodeStore nodeStore, String branchId) {
         super(nodeStore);
+        this.branchId = branchId;
     }
 
     @Override
@@ -46,15 +59,19 @@ public class FetchHeadRevisionIdAction e
         MongoSync syncMongo = (MongoSync)headCollection.findOne();
         long headRevisionId = syncMongo.getHeadRevisionId();
 
-        // Find the first revision id that's not part of a branch.
         DBCollection collection = nodeStore.getCommitCollection();
-        DBObject query = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE)
-                .and(MongoCommit.KEY_REVISION_ID).lessThanEquals(headRevisionId)
-                .and(new BasicDBObject(MongoNode.KEY_BRANCH_ID, new BasicDBObject("$exists",
false)))
-                .get();
+        QueryBuilder qb = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE)
+                .and(MongoCommit.KEY_REVISION_ID).lessThanEquals(headRevisionId);
+        if (branchId == null) {
+            qb = qb.and(new BasicDBObject(MongoNode.KEY_BRANCH_ID, new BasicDBObject("$exists",
false)));
+        } else {
+            qb = qb.and(MongoNode.KEY_BRANCH_ID).is(branchId);
+        }
+
+        DBObject query = qb.get();
         DBObject fields = new BasicDBObject(MongoCommit.KEY_REVISION_ID, 1);
         DBObject orderBy = new BasicDBObject(MongoCommit.KEY_REVISION_ID, -1);
         MongoCommit commit = (MongoCommit)collection.findOne(query, fields, orderBy);
-        return commit.getRevisionId();
+        return commit != null? commit.getRevisionId() : 0L;
     }
 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java?rev=1436344&r1=1436343&r2=1436344&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java
Mon Jan 21 13:41:56 2013
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.mongomk.api
 import org.apache.jackrabbit.mongomk.api.model.Commit;
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.action.FetchCommitsAction;
+import org.apache.jackrabbit.mongomk.impl.action.FetchHeadRevisionIdAction;
 import org.apache.jackrabbit.mongomk.impl.action.FetchNodesAction;
 import org.apache.jackrabbit.mongomk.impl.action.ReadAndIncHeadRevisionAction;
 import org.apache.jackrabbit.mongomk.impl.action.SaveAndSetHeadRevisionAction;
@@ -93,8 +94,14 @@ public class CommitCommand extends BaseC
             readBranchIdFromBaseCommit();
             createMongoNodes();
             prepareCommit();
-            readExistingNodes();
-            mergeNodes();
+            // If base revision is older than the head revision, need to read
+            // and merge nodes at the head revision.
+            FetchHeadRevisionIdAction action = new FetchHeadRevisionIdAction(nodeStore, branchId);
+            long headRevisionId = action.execute();
+            if (baseRevisionId < headRevisionId) {
+                readExistingNodes();
+                mergeNodes();
+            }
             prepareMongoNodes();
             new SaveNodesAction(nodeStore, nodes).execute();
             new SaveCommitAction(nodeStore, commit).execute();

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java?rev=1436344&r1=1436343&r2=1436344&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java
Mon Jan 21 13:41:56 2013
@@ -29,6 +29,7 @@ import org.apache.jackrabbit.mongomk.api
 import org.apache.jackrabbit.mongomk.api.model.Commit;
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.action.FetchCommitAction;
+import org.apache.jackrabbit.mongomk.impl.action.FetchHeadRevisionIdAction;
 import org.apache.jackrabbit.mongomk.impl.action.ReadAndIncHeadRevisionAction;
 import org.apache.jackrabbit.mongomk.impl.action.SaveAndSetHeadRevisionAction;
 import org.apache.jackrabbit.mongomk.impl.action.SaveCommitAction;
@@ -96,8 +97,14 @@ public class CommitCommandNew extends Ba
             readBranchIdFromBaseCommit();
             createMongoNodes();
             prepareCommit();
-            readExistingNodes();
-            mergeNodes();
+            // If base revision is older than the head revision, need to read
+            // and merge nodes at the head revision.
+            FetchHeadRevisionIdAction action = new FetchHeadRevisionIdAction(nodeStore, branchId);
+            long headRevisionId = action.execute();
+            if (baseRevisionId < headRevisionId) {
+                readExistingNodes();
+                mergeNodes();
+            }
             prepareMongoNodes();
             new SaveNodesAction(nodeStore, nodes.values()).execute();
             new SaveCommitAction(nodeStore, commit).execute();



Mime
View raw message