jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1415108 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl: action/FetchCommitsAction.java command/CommitCommand.java command/GetJournalCommand.java
Date Thu, 29 Nov 2012 09:44:41 GMT
Author: meteatamel
Date: Thu Nov 29 09:44:40 2012
New Revision: 1415108

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

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitsAction.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/GetJournalCommand.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitsAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitsAction.java?rev=1415108&r1=1415107&r2=1415108&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitsAction.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitsAction.java
Thu Nov 29 09:44:40 2012
@@ -111,6 +111,9 @@ public class FetchCommitsAction extends 
     private DBCursor fetchListOfValidCommits() {
         DBCollection commitCollection = nodeStore.getCommitCollection();
         QueryBuilder queryBuilder = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE);
+        if (fromRevisionId > -1) {
+            queryBuilder = queryBuilder.and(MongoCommit.KEY_REVISION_ID).greaterThanEquals(fromRevisionId);
+        }
         if (toRevisionId > -1) {
             queryBuilder = queryBuilder.and(MongoCommit.KEY_REVISION_ID).lessThanEquals(toRevisionId);
         }
@@ -121,13 +124,35 @@ public class FetchCommitsAction extends 
         }
 
         DBObject query = queryBuilder.get();
+        DBObject orderBy = new BasicDBObject(MongoCommit.KEY_REVISION_ID, -1);
 
         LOG.debug("Executing query: {}", query);
 
-        return maxEntries > 0? commitCollection.find(query).limit(maxEntries) : commitCollection.find(query);
+        return maxEntries > 0? commitCollection.find(query).limit(maxEntries).sort(orderBy)
+                : commitCollection.find(query).sort(orderBy);
     }
 
+    // FIXME - Revisit this method to make sure it works correctly in concurrent scenarios.
+    // The old method tried to read all commits reachable from current rev but the problem
+    // with that approach is that the current rev can end up being invalid later on which
+    // causes previous valid but unreachable commits to be missed. The new method simply
grabs all
+    // valid commits at the moment in order to not miss any legitimate valid commits but
+    // not sure if this is the right thing to do in all scenarios.
     private List<MongoCommit> convertToCommits(DBCursor dbCursor) {
+        List<MongoCommit> commits = new LinkedList<MongoCommit>();
+        while (dbCursor.hasNext()) {
+            MongoCommit commit = (MongoCommit) dbCursor.next();
+            commits.add(commit);
+        }
+
+        LOG.debug("Found list of valid revisions for max revision {}: {}",
+                toRevisionId, commits);
+
+        return commits;
+    }
+
+    // Keeping this until we're sure that the new method is correct.
+    private List<MongoCommit> convertToCommitsOld(DBCursor dbCursor) {
         Map<Long, MongoCommit> commits = new HashMap<Long, MongoCommit>();
         while (dbCursor.hasNext()) {
             MongoCommit commitMongo = (MongoCommit) dbCursor.next();

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=1415108&r1=1415107&r2=1415108&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 09:44:40 2012
@@ -76,12 +76,11 @@ public class CommitCommand extends BaseC
 
     @Override
     public Long execute() throws Exception {
-        logger.debug("Trying to commit: {}", commit.getDiff());
-
         boolean success = false;
         do {
             mongoSync = new ReadAndIncHeadRevisionAction(nodeStore).execute();
             revisionId = mongoSync.getNextRevisionId() - 1;
+            logger.debug("Trying to commit: {} @rev{}", commit.getDiff(), revisionId);
             readValidCommits();
             readBranchIdFromBaseCommit();
             createMongoNodes();

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java?rev=1415108&r1=1415107&r2=1415108&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
Thu Nov 29 09:44:40 2012
@@ -54,7 +54,7 @@ public class GetJournalCommand extends B
         List<MongoCommit> commits = getCommits(fromRevision, toRevision);
 
         MongoCommit toCommit = extractCommit(commits, toRevision);
-        if (toCommit.getBranchId() != null) {
+        if (toCommit != null && toCommit.getBranchId() != null) {
             throw new MicroKernelException("Branch revisions are not supported: " + toRevisionId);
         }
 



Mime
View raw message