jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1439323 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl: action/FetchHeadRevisionIdAction.java command/CommitCommand.java
Date Mon, 28 Jan 2013 09:59:50 GMT
Author: meteatamel
Date: Mon Jan 28 09:59:49 2013
New Revision: 1439323

URL: http://svn.apache.org/viewvc?rev=1439323&view=rev
Log:
OAK-571 - Limit usage of headRevId in sync collection to non-branches

Simplified commit and headRev fetching in light of changes for OAK-571

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

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=1439323&r1=1439322&r2=1439323&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 28 09:59:49 2013
@@ -27,14 +27,14 @@ import com.mongodb.DBObject;
 import com.mongodb.QueryBuilder;
 
 /**
- * An action for fetching the head revision.
+ * An action for fetching the head revision for trunk or a branch.
  */
 public class FetchHeadRevisionIdAction extends BaseAction<Long> {
 
     private final String branchId;
 
     /**
-     * Constructs a new {@code FetchHeadRevisionIdAction}.
+     * Constructs a new {@code FetchHeadRevisionIdAction} for trunk.
      *
      * @param nodeStore Node store.
      */
@@ -43,7 +43,7 @@ public class FetchHeadRevisionIdAction e
     }
 
     /**
-     * Constructs a new {@code FetchHeadRevisionIdAction}.
+     * Constructs a new {@code FetchHeadRevisionIdAction} for branch.
      *
      * @param nodeStore Node store.
      * @param branchId Branch id.
@@ -58,16 +58,14 @@ public class FetchHeadRevisionIdAction e
         DBCollection headCollection = nodeStore.getSyncCollection();
         MongoSync syncMongo = (MongoSync)headCollection.findOne();
         long headRevisionId = syncMongo.getHeadRevisionId();
-
-        DBCollection collection = nodeStore.getCommitCollection();
-        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);
+            return headRevisionId;
         }
 
+        DBCollection collection = nodeStore.getCommitCollection();
+        QueryBuilder qb = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE)
+                .and(MongoCommit.KEY_REVISION_ID).lessThanEquals(headRevisionId)
+                .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);

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=1439323&r1=1439322&r2=1439323&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 28 09:59:49 2013
@@ -95,14 +95,7 @@ public class CommitCommand extends BaseC
             readBranchIdFromBaseCommit();
             createMongoNodes();
             prepareCommit();
-            // 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();
-            }
+            readAndMergeExistingNodes();
             prepareMongoNodes();
             new SaveNodesAction(nodeStore, nodes.values()).execute();
             new SaveCommitAction(nodeStore, commit).execute();
@@ -175,6 +168,23 @@ public class CommitCommand extends BaseC
         commit.removeField("_id"); // In case this is a retry.
     }
 
+    private void readAndMergeExistingNodes() throws Exception {
+        // If base revision is older than the head revision, need to read
+        // and merge nodes at the head revision.
+        long headRevisionId;
+        if (branchId == null) {
+            headRevisionId = mongoSync.getHeadRevisionId();
+        } else {
+            headRevisionId = new FetchHeadRevisionIdAction(nodeStore, branchId).execute();
+        }
+
+        if (baseRevisionId < headRevisionId) {
+            readExistingNodes();
+            mergeNodes();
+        }
+    }
+
+
 //    private void readExistingNodes() {
 //        FetchNodesAction action = new FetchNodesAction(nodeStore, affectedPaths,
 //                mongoSync.getHeadRevisionId());



Mime
View raw message