Index: src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java =================================================================== --- src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java (revision 1439323) +++ src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommand.java (working copy) @@ -97,13 +97,14 @@ prepareCommit(); readAndMergeExistingNodes(); prepareMongoNodes(); - new SaveNodesAction(nodeStore, nodes.values()).execute(); - new SaveCommitAction(nodeStore, commit).execute(); - success = saveAndSetHeadRevision(); + success = saveNodesAndCommits(); if (success) { - cacheNodes(); - } else { - retries++; + success = saveAndSetHeadRevision(); + if (success) { + cacheNodes(); + } else { + retries++; + } } } while (!success); @@ -115,6 +116,17 @@ return revisionId; } + private boolean saveNodesAndCommits() throws Exception { + long headRevisionId = new FetchHeadRevisionIdAction(nodeStore, branchId).execute(); + if (branchId == null && headRevisionId != mongoSync.getHeadRevisionId()) { + // Head revision moved on in trunk in the meantime, no need to save + return false; + } + new SaveNodesAction(nodeStore, nodes.values()).execute(); + new SaveCommitAction(nodeStore, commit).execute(); + return true; + } + @Override public int getNumOfRetries() { return 100; @@ -184,7 +196,6 @@ } } - // private void readExistingNodes() { // FetchNodesAction action = new FetchNodesAction(nodeStore, affectedPaths, // mongoSync.getHeadRevisionId());