jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1415120 - /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java
Date Thu, 29 Nov 2012 11:01:10 GMT
Author: meteatamel
Date: Thu Nov 29 11:01:08 2012
New Revision: 1415120

URL: http://svn.apache.org/viewvc?rev=1415120&view=rev
Log:
OAK-488 - Concurrency issue with FetchCommitsAction

Minor fixes to commit command's conflict detection

Modified:
    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/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=1415120&r1=1415119&r2=1415120&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
Thu Nov 29 11:01:08 2012
@@ -41,7 +41,6 @@ import org.slf4j.LoggerFactory;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
 import com.mongodb.DBObject;
 import com.mongodb.QueryBuilder;
 import com.mongodb.WriteResult;
@@ -270,14 +269,15 @@ public class CommitCommand extends BaseC
             // but don't count these retries against number of retries.
             if (conflictingCommitsExist(assumedHeadRevision)) {
                 String message = String.format("Encountered a concurrent conflicting update"
-                        + ", thus can't commit revision %s and will be retried with new revision",
revisionId);
+                        + ", thus can't commit revision %s with affected paths %s."
+                        + " Retry with a new revision.", revisionId, commit.getAffectedPaths());
                 logger.warn(message);
                 markAsFailed();
                 throw new ConflictingCommitException(message);
             } else {
-                String message = String.format("Encountered a concurrent but non-conflicting
update"
-                        + ", thus can't commit revision %s and will be retried with new revision",
revisionId);
-                logger.warn(message);
+                logger.warn("Encountered a concurrent but non-conflicting update"
+                        + ", thus can't commit revision {} with affected paths {}."
+                        + " Retry with a new revision.", revisionId, commit.getAffectedPaths());
                 markAsFailed();
                 return false;
             }
@@ -286,20 +286,16 @@ public class CommitCommand extends BaseC
     }
 
     private boolean conflictingCommitsExist(long baseRevisionId) {
-        QueryBuilder queryBuilder = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE);
-        queryBuilder = queryBuilder.and(MongoCommit.KEY_BASE_REVISION_ID).is(baseRevisionId);
+        QueryBuilder queryBuilder = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE)
+                .and(MongoCommit.KEY_BASE_REVISION_ID).is(baseRevisionId)
+                .and(MongoCommit.KEY_REVISION_ID).greaterThan(0L)
+                .and(MongoCommit.KEY_REVISION_ID).notEquals(revisionId);
         DBObject query = queryBuilder.get();
         DBCollection collection = nodeStore.getCommitCollection();
-        DBCursor dbCursor = collection.find(query);
-        while (dbCursor.hasNext()) {
-            MongoCommit commit = (MongoCommit)dbCursor.next();
-            if (this.commit.getRevisionId().equals(commit.getRevisionId())) {
-                continue;
-            }
-            for (String affectedPath : commit.getAffectedPaths()) {
-                if (affectedPaths.contains(affectedPath)) {
-                    return true;
-                }
+        MongoCommit conflictingCommit = (MongoCommit)collection.findOne(query);
+        for (String affectedPath : conflictingCommit.getAffectedPaths()) {
+            if (affectedPaths.contains(affectedPath)) {
+                return true;
             }
         }
         return false;



Mime
View raw message