jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1431409 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/impl/ main/java/org/apache/jackrabbit/mongomk/impl/action/ main/java/org/apache/jackrabbit/mongomk/impl/command/ main/java/org/apache/jackrabbit/mo...
Date Thu, 10 Jan 2013 15:14:22 GMT
Author: mreutegg
Date: Thu Jan 10 15:14:22 2013
New Revision: 1431409

URL: http://svn.apache.org/viewvc?rev=1431409&view=rev
Log:
OAK-507: MicroKernel.commit() throws NotFoundException for an existing node

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
    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/action/FetchNodesActionNew.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
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitRemoveTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
Thu Jan 10 15:14:22 2013
@@ -200,6 +200,17 @@ public class MongoNodeStore implements N
     }
 
     /**
+     * Evicts the commit from the {@link #commitCache}.
+     *
+     * @param commit the commit.
+     */
+    public void evict(MongoCommit commit) {
+        if (commitCache.remove(commit.getRevisionId()) != null) {
+            LOG.debug("Removed commit {} from cache", commit.getRevisionId());
+        }
+    }
+
+    /**
      * Returns the commit from the cache or null if the commit is not in the cache.
      *
      * @param revisionId Commit revision id.
@@ -225,7 +236,7 @@ public class MongoNodeStore implements N
         String key = path + "*" + branchId + "*" + revisionId;
         if (!nodeCache.containsKey(key)) {
             LOG.debug("Adding node to cache: {}", key);
-            nodeCache.put(key, node);
+            nodeCache.put(key, node.copy());
         }
     }
 

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=1431409&r1=1431408&r2=1431409&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 Jan 10 15:14:22 2013
@@ -85,18 +85,22 @@ public class FetchCommitsAction extends 
      * Sets the max number of entries that should be fetched.
      *
      * @param maxEntries The max number of entries.
+     * @return this action.
      */
-    public void setMaxEntries(int maxEntries) {
+    public FetchCommitsAction setMaxEntries(int maxEntries) {
         this.maxEntries = maxEntries;
+        return this;
     }
 
     /**
      * Sets whether the branch commits are included in the query.
      *
      * @param includeBranchCommits Whether the branch commits are included.
+     * @return this action.
      */
-    public void includeBranchCommits(boolean includeBranchCommits) {
+    public FetchCommitsAction includeBranchCommits(boolean includeBranchCommits) {
         this.includeBranchCommits = includeBranchCommits;
+        return this;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
Thu Jan 10 15:14:22 2013
@@ -203,14 +203,14 @@ public class FetchNodesActionNew extends
             // Assuming that revision ids are ordered and nodes are fetched in
             // sorted order, first check if the path is already in the map.
             if (nodes.containsKey(path)) {
-                LOG.debug("Converted nodes @{} with path {} was not put into map"
-                        + " because a newer version is available", revisionId, path);
+                LOG.debug("Converted node @{} with path {} was not put into map"
+                        + " because a newer version is available", node.getRevisionId(),
path);
                 continue;
             } else {
                 long revisionId = node.getRevisionId();
-                LOG.debug("Converting node {} ({})", path, revisionId);
+                LOG.debug("Converting node {} (@{})", path, revisionId);
 
-                if (!commits.containsKey(revisionId) && nodeStore.getFromCache(revisionId)
!= null) {
+                if (!commits.containsKey(revisionId) && nodeStore.getFromCache(revisionId)
== null) {
                     LOG.debug("Fetching commit @{}", revisionId);
                     FetchCommitAction action = new FetchCommitAction(nodeStore, revisionId);
                     try {

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=1431409&r1=1431408&r2=1431409&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 Jan 10 15:14:22 2013
@@ -60,6 +60,8 @@ public class CommitCommand extends BaseC
     private MongoSync mongoSync;
     private Set<MongoNode> nodes;
     private Long revisionId;
+    private final Long initialBaseRevisionId;
+    private Long baseRevisionId;
     private String branchId;
 
     /**
@@ -71,14 +73,21 @@ public class CommitCommand extends BaseC
     public CommitCommand(MongoNodeStore nodeStore, Commit commit) {
         super(nodeStore);
         this.commit = (MongoCommit)commit;
+        this.initialBaseRevisionId = commit.getBaseRevisionId();
     }
 
     @Override
     public Long execute() throws Exception {
+        int retries = 0;
         boolean success = false;
         do {
             mongoSync = new ReadAndIncHeadRevisionAction(nodeStore).execute();
             revisionId = mongoSync.getNextRevisionId() - 1;
+            if (initialBaseRevisionId != null) {
+                baseRevisionId = initialBaseRevisionId;
+            } else {
+                baseRevisionId = mongoSync.getHeadRevisionId();
+            }
             logger.debug("Committing @{} with diff: {}", revisionId, commit.getDiff());
             readValidCommits();
             readBranchIdFromBaseCommit();
@@ -90,9 +99,16 @@ public class CommitCommand extends BaseC
             new SaveNodesAction(nodeStore, nodes).execute();
             new SaveCommitAction(nodeStore, commit).execute();
             success = saveAndSetHeadRevision();
+            if (!success) {
+                retries++;
+            }
         } while (!success);
 
-        logger.debug("Commit @{}: success", revisionId);
+        String msg = "Commit @{}: success";
+        if (retries > 0) {
+            msg += " with {} retries.";
+        }
+        logger.debug(msg, revisionId, retries);
         return revisionId;
     }
 
@@ -133,7 +149,7 @@ public class CommitCommand extends BaseC
 
     private void createMongoNodes() throws Exception {
         CommitCommandInstructionVisitor visitor = new CommitCommandInstructionVisitor(
-                nodeStore, mongoSync.getHeadRevisionId(), validCommits);
+                nodeStore, baseRevisionId, validCommits);
         visitor.setBranchId(branchId);
 
         for (Instruction instruction : commit.getInstructions()) {
@@ -273,7 +289,7 @@ public class CommitCommand extends BaseC
                 markAsFailed();
                 throw new ConflictingCommitException(message);
             } else {
-                logger.warn("Commit @{}: failed due to a conflicting commit."
+                logger.info("Commit @{}: failed due to a concurrent commit."
                         + " Affected paths: {}", revisionId, commit.getAffectedPaths());
                 markAsFailed();
                 return false;
@@ -303,6 +319,7 @@ public class CommitCommand extends BaseC
         DBObject query = QueryBuilder.start("_id").is(commit.getObjectId("_id")).get();
         DBObject update = new BasicDBObject("$set", new BasicDBObject(MongoCommit.KEY_FAILED,
Boolean.TRUE));
         WriteResult writeResult = commitCollection.update(query, update);
+        nodeStore.evict(commit);
         if (writeResult.getError() != null) {
             // FIXME This is potentially a bug that we need to handle.
             throw new Exception(String.format("Update wasn't successful: %s", writeResult));

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=1431409&r1=1431408&r2=1431409&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
Thu Jan 10 15:14:22 2013
@@ -29,7 +29,6 @@ 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.FetchNodesActionNew;
 import org.apache.jackrabbit.mongomk.impl.action.ReadAndIncHeadRevisionAction;
 import org.apache.jackrabbit.mongomk.impl.action.SaveAndSetHeadRevisionAction;
 import org.apache.jackrabbit.mongomk.impl.action.SaveCommitAction;
@@ -63,8 +62,10 @@ public class CommitCommandNew extends Ba
     private Set<String> affectedPaths;
     private Map<String, MongoNode> existingNodes;
     private MongoSync mongoSync;
-    private Set<MongoNode> nodes;
+    private Map<String, MongoNode> nodes;
     private Long revisionId;
+    private final Long initialBaseRevisionId;
+    private Long baseRevisionId;
     private String branchId;
 
     /**
@@ -76,14 +77,21 @@ public class CommitCommandNew extends Ba
     public CommitCommandNew(MongoNodeStore nodeStore, Commit commit) {
         super(nodeStore);
         this.commit = (MongoCommit)commit;
+        this.initialBaseRevisionId = commit.getBaseRevisionId();
     }
 
     @Override
     public Long execute() throws Exception {
+        int retries = 0;
         boolean success = false;
         do {
             mongoSync = new ReadAndIncHeadRevisionAction(nodeStore).execute();
             revisionId = mongoSync.getNextRevisionId() - 1;
+            if (initialBaseRevisionId != null) {
+                baseRevisionId = initialBaseRevisionId;
+            } else {
+                baseRevisionId = mongoSync.getHeadRevisionId();
+            }
             logger.debug("Committing @{} with diff: {}", revisionId, commit.getDiff());
             readBranchIdFromBaseCommit();
             createMongoNodes();
@@ -91,15 +99,21 @@ public class CommitCommandNew extends Ba
             readExistingNodes();
             mergeNodes();
             prepareMongoNodes();
-            new SaveNodesAction(nodeStore, nodes).execute();
+            new SaveNodesAction(nodeStore, nodes.values()).execute();
             new SaveCommitAction(nodeStore, commit).execute();
             success = saveAndSetHeadRevision();
             if (success) {
                 cacheNodes();
+            } else {
+                retries++;
             }
         } while (!success);
 
-        logger.debug("Commit @{}: success", revisionId);
+        String msg = "Commit @{}: success";
+        if (retries > 0) {
+            msg += " with {} retries.";
+        }
+        logger.debug(msg, revisionId, retries);
         return revisionId;
     }
 
@@ -134,16 +148,15 @@ public class CommitCommandNew extends Ba
 
     private void createMongoNodes() throws Exception {
         CommitCommandInstructionVisitor visitor = new CommitCommandInstructionVisitor(
-                nodeStore, mongoSync.getHeadRevisionId(), null);
+                nodeStore, baseRevisionId, null);
         visitor.setBranchId(branchId);
 
         for (Instruction instruction : commit.getInstructions()) {
             instruction.accept(visitor);
         }
 
-        Map<String, MongoNode> pathNodeMap = visitor.getPathNodeMap();
-        affectedPaths = pathNodeMap.keySet();
-        nodes = new HashSet<MongoNode>(pathNodeMap.values());
+        nodes = visitor.getPathNodeMap();
+        affectedPaths = nodes.keySet();
     }
 
     private void prepareCommit() throws Exception {
@@ -164,58 +177,56 @@ public class CommitCommandNew extends Ba
 //    }
 
     // FIXME - Performance, This seems to be faster for commits than the old method.
-    private void readExistingNodes() {
+    private void readExistingNodes() throws Exception {
         if (affectedPaths == null || affectedPaths.isEmpty()) {
             existingNodes = Collections.emptyMap();
         }
 
         existingNodes = new HashMap<String, MongoNode>();
         for (String path : affectedPaths) {
-            FetchNodesActionNew action = new FetchNodesActionNew(nodeStore, path,
-                    0, mongoSync.getHeadRevisionId());
-            action.setBranchId(branchId);
-            Map<String, MongoNode> result = action.execute();
-            MongoNode node = result.get(path);
-            if (node != null) {
-                existingNodes.put(path, node);
+            NodeExistsCommand command = new NodeExistsCommand(
+                    nodeStore, path, mongoSync.getHeadRevisionId());
+            command.setBranchId(branchId);
+            if (command.execute()) {
+                existingNodes.put(path, command.getNode());
             }
         }
     }
 
     private void mergeNodes() {
-        for (MongoNode existingNode : existingNodes.values()) {
-            for (MongoNode committingNode : nodes) {
-                if (existingNode.getPath().equals(committingNode.getPath())) {
-                    if(logger.isDebugEnabled()){
-                        logger.debug("Found existing node to merge: {}", existingNode.getPath());
-                        logger.debug("Existing node: {}", existingNode);
-                        logger.debug("Committing node: {}", committingNode);
-                    }
-                    Map<String, Object> existingProperties = existingNode.getProperties();
-                    if (!existingProperties.isEmpty()) {
-                        committingNode.setProperties(existingProperties);
-
-                        logger.debug("Merged properties for {}: {}", existingNode.getPath(),
-                                existingProperties);
-                    }
-
-                    List<String> existingChildren = existingNode.getChildren();
-                    if (existingChildren != null) {
-                        committingNode.setChildren(existingChildren);
+        for (MongoNode committingNode : nodes.values()) {
+            MongoNode existingNode = existingNodes.get(committingNode.getPath());
+            if (existingNode != null) {
+                if(logger.isDebugEnabled()){
+                    logger.debug("Found existing node to merge: {}", existingNode.getPath());
+                    logger.debug("Existing node: {}", existingNode);
+                    logger.debug("Committing node: {}", committingNode);
+                }
+                Map<String, Object> existingProperties = existingNode.getProperties();
+                if (!existingProperties.isEmpty()) {
+                    committingNode.setProperties(existingProperties);
 
-                        logger.debug("Merged children for {}: {}", existingNode.getPath(),
existingChildren);
-                    }
+                    logger.debug("Merged properties for {}: {}", existingNode.getPath(),
+                            existingProperties);
+                }
 
-                    logger.debug("Merged node for {}: {}", existingNode.getPath(), committingNode);
+                List<String> existingChildren = existingNode.getChildren();
+                if (existingChildren != null) {
+                    committingNode.setChildren(existingChildren);
 
-                    break;
+                    logger.debug("Merged children for {}: {}", existingNode.getPath(), existingChildren);
                 }
+
+                logger.debug("Merged node for {}: {}", existingNode.getPath(), committingNode);
+            } else {
+                // FIXME: this may also mean a node we modify has
+                // been removed in the meantime
             }
         }
     }
 
     private void prepareMongoNodes() {
-        for (MongoNode committingNode : nodes) {
+        for (MongoNode committingNode : nodes.values()) {
             logger.debug("Preparing children (added and removed) of {}", committingNode.getPath());
             logger.debug("Committing node: {}", committingNode);
 
@@ -294,8 +305,7 @@ public class CommitCommandNew extends Ba
                 markAsFailed();
                 throw new ConflictingCommitException(message);
             } else {
-                logger.warn("Commit @{}: failed due to a conflicting commit."
-                        + " Affected paths: {}", revisionId, commit.getAffectedPaths());
+                logger.info("Commit @{}: failed due to a concurrent commit." + " Affected
paths: {}", revisionId, commit.getAffectedPaths());
                 markAsFailed();
                 return false;
             }
@@ -324,6 +334,7 @@ public class CommitCommandNew extends Ba
         DBObject query = QueryBuilder.start("_id").is(commit.getObjectId("_id")).get();
         DBObject update = new BasicDBObject("$set", new BasicDBObject(MongoCommit.KEY_FAILED,
Boolean.TRUE));
         WriteResult writeResult = commitCollection.update(query, update);
+        nodeStore.evict(commit);
         if (writeResult.getError() != null) {
             // FIXME This is potentially a bug that we need to handle.
             throw new Exception(String.format("Update wasn't successful: %s", writeResult));
@@ -331,7 +342,7 @@ public class CommitCommandNew extends Ba
     }
 
     private void cacheNodes() {
-        for (MongoNode node : nodes) {
+        for (MongoNode node : nodes.values()) {
             nodeStore.cache(node);
         }
     }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
Thu Jan 10 15:14:22 2013
@@ -41,7 +41,8 @@ import org.apache.jackrabbit.oak.commons
  */
 public class CommitCommandInstructionVisitor implements InstructionVisitor {
 
-    private final long headRevisionId;
+    // the revision this commit is based on
+    private final long baseRevisionId;
     private final MongoNodeStore nodeStore;
     private final Map<String, MongoNode> pathNodeMap;
     private final List<MongoCommit> validCommits;
@@ -52,13 +53,14 @@ public class CommitCommandInstructionVis
      * Creates {@code CommitCommandInstructionVisitor}
      *
      * @param nodeStore Node store.
-     * @param headRevisionId Head revision.
+     * @param baseRevisionId the revision this commit is based on
      * @param validCommits
      */
-    public CommitCommandInstructionVisitor(MongoNodeStore nodeStore, long headRevisionId,
-            List<MongoCommit> validCommits) {
+    public CommitCommandInstructionVisitor(MongoNodeStore nodeStore,
+                                           long baseRevisionId,
+                                           List<MongoCommit> validCommits) {
         this.nodeStore = nodeStore;
-        this.headRevisionId = headRevisionId;
+        this.baseRevisionId = baseRevisionId;
         this.validCommits = validCommits;
         pathNodeMap = new HashMap<String, MongoNode>();
     }
@@ -93,9 +95,7 @@ public class CommitCommandInstructionVis
         }
 
         String parentNodePath = PathUtils.getParentPath(nodePath);
-        // FIXME - Performance
-        //MongoNode parent = getStoredNode(parentNodePath);
-        MongoNode parent = getStagedNode(parentNodePath);
+        MongoNode parent = getStoredNode(parentNodePath);
         if (parent.childExists(nodeName)) {
             throw new RuntimeException("There's already a child node with name '" + nodeName
+ "'");
         }
@@ -107,9 +107,7 @@ public class CommitCommandInstructionVis
     public void visit(SetPropertyInstruction instruction) {
         String key = instruction.getKey();
         Object value = instruction.getValue();
-        // FIXME - Performance
-        //MongoNode node = getStoredNode(instruction.getPath());
-        MongoNode node = getStagedNode(instruction.getPath());
+        MongoNode node = getStoredNode(instruction.getPath());
         if (value == null) {
             node.removeProp(key);
         } else {
@@ -123,14 +121,12 @@ public class CommitCommandInstructionVis
         checkAbsolutePath(nodePath);
 
         String parentPath = PathUtils.getParentPath(nodePath);
-        MongoNode parent = getStagedNode(parentPath);
         String nodeName = PathUtils.getName(nodePath);
-        // See OAK-507
-//        MongoNode parent = getStoredNode(parentPath);
-//        if (!parent.childExists(nodeName)) {
-//            throw new RuntimeException("Node " + nodeName
-//                    + " does not exists at parent path: " + parentPath);
-//        }
+        MongoNode parent = getStoredNode(parentPath);
+        if (!parent.childExists(nodeName)) {
+            throw new RuntimeException("Node " + nodeName
+                    + " does not exists at parent path: " + parentPath);
+        }
         parent.removeChild(nodeName);
     }
 
@@ -161,8 +157,10 @@ public class CommitCommandInstructionVis
         }
 
         // First, copy the existing nodes.
-        Map<String, MongoNode> nodesToCopy = new FetchNodesActionNew(nodeStore,
-                srcPath, FetchNodesActionNew.LIMITLESS_DEPTH, headRevisionId).execute();
+        FetchNodesActionNew action = new FetchNodesActionNew(nodeStore,
+                srcPath, FetchNodesActionNew.LIMITLESS_DEPTH, baseRevisionId);
+        action.setBranchId(branchId);
+        Map<String, MongoNode> nodesToCopy = action.execute();
         for (MongoNode nodeMongo : nodesToCopy.values()) {
             String oldPath = nodeMongo.getPath();
             String oldPathRel = PathUtils.relativize(srcPath, oldPath);
@@ -208,8 +206,10 @@ public class CommitCommandInstructionVis
         }
 
         // First, copy the existing nodes.
-        Map<String, MongoNode> nodesToCopy = new FetchNodesActionNew(nodeStore,
-                srcPath, FetchNodesActionNew.LIMITLESS_DEPTH, headRevisionId).execute();
+        FetchNodesActionNew action = new FetchNodesActionNew(nodeStore,
+                srcPath, FetchNodesActionNew.LIMITLESS_DEPTH, baseRevisionId);
+        action.setBranchId(branchId);
+        Map<String, MongoNode> nodesToCopy = action.execute();
         for (MongoNode nodeMongo : nodesToCopy.values()) {
             String oldPath = nodeMongo.getPath();
             String oldPathRel = PathUtils.relativize(srcPath, oldPath);
@@ -258,7 +258,7 @@ public class CommitCommandInstructionVis
 
         // First need to check that the path is indeed valid.
         NodeExistsCommand existCommand = new NodeExistsCommand(nodeStore,
-                path, headRevisionId);
+                path, baseRevisionId);
         existCommand.setBranchId(branchId);
         boolean exists = false;
         try {
@@ -266,7 +266,7 @@ public class CommitCommandInstructionVis
         } catch (Exception ignore) {}
 
         if (!exists) {
-            throw new NotFoundException(path + " @rev" + headRevisionId);
+            throw new NotFoundException(path + " @rev" + baseRevisionId);
         }
         node = existCommand.getNode();
         node.removeField("_id");

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java
Thu Jan 10 15:14:22 2013
@@ -131,6 +131,13 @@ public class MongoNode extends BasicDBOb
         put(KEY_REVISION_ID, revisionId);
     }
 
+    @Override
+    public MongoNode copy() {
+        MongoNode copy = new MongoNode();
+        copy.putAll((Map) super.copy());
+        return copy;
+    }
+
     //--------------------------------------------------------------------------
     //
     // These properties are used to keep track of changes but not persisted

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java
Thu Jan 10 15:14:22 2013
@@ -330,19 +330,17 @@ public class MongoMKBranchMergeTest exte
     }
 
     private String addNodes(String rev, String...nodes) {
-        String newRev = rev;
         for (String node : nodes) {
-            newRev = mk.commit("", "+\"" + node + "\":{}", rev, "");
+            rev = mk.commit("", "+\"" + node + "\":{}", rev, "");
         }
-        return newRev;
+        return rev;
     }
 
     private String removeNodes(String rev, String...nodes) {
-        String newRev = rev;
         for (String node : nodes) {
-            newRev = mk.commit("", "-\"" + node + "\"", rev, "");
+            rev = mk.commit("", "-\"" + node + "\"", rev, "");
         }
-        return newRev;
+        return rev;
     }
 
     private String setProp(String rev, String prop, Object value) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java
Thu Jan 10 15:14:22 2013
@@ -19,10 +19,10 @@ package org.apache.jackrabbit.mongomk.im
 import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 /**
  * <code>MongoMKBranchTest</code> performs a test to check if commits
@@ -60,4 +60,19 @@ public class MongoMKBranchTest extends B
         JSONObject obj = (JSONObject) parser.parse(json);
         assertFalse(obj.containsKey("foo"));
     }
+
+    @Test
+    public void movesInBranch() throws Exception {
+        String branchRev = mk.branch(null);
+        branchRev = mk.commit("/", "+\"a\":{}", branchRev, null);
+        branchRev = mk.commit("/a", "^\"foo\":1", branchRev, null);
+        branchRev = mk.commit("/", ">\"a\" : \"b\"", branchRev, null);
+        branchRev = mk.commit("/", ">\"b\" : \"a\"", branchRev, null);
+        mk.merge(branchRev, null);
+
+        String json = mk.getNodes("/a", null, 0, 0, -1, null);
+        JSONParser parser = new JSONParser();
+        JSONObject obj = (JSONObject) parser.parse(json);
+        assertTrue(obj.containsKey("foo"));
+    }
 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
Thu Jan 10 15:14:22 2013
@@ -75,7 +75,6 @@ public class MongoMKCommitAddTest extend
     }
 
     @Test
-    @Ignore // FIXME - due to CommitCommandInstructionVisitor add node change.
     public void addDuplicateNode() throws Exception {
         mk.commit("/", "+\"a\" : {}", null, null);
         try {
@@ -138,7 +137,6 @@ public class MongoMKCommitAddTest extend
     }
 
     @Test
-    @Ignore // FIXME - due to CommitCommandInstructionVisitor add node change.
     public void setPropertyWithoutAddingNode() throws Exception {
         try {
             mk.commit("/", "^\"a/key1\" : \"value1\"", null, null);

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitRemoveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitRemoveTest.java?rev=1431409&r1=1431408&r2=1431409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitRemoveTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitRemoveTest.java
Thu Jan 10 15:14:22 2013
@@ -6,7 +6,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
-import org.junit.Ignore;
+import org.json.simple.JSONObject;
 import org.junit.Test;
 
 /**
@@ -28,8 +28,6 @@ public class MongoMKCommitRemoveTest ext
     }
 
     @Test
-    @Ignore
-    // According to OAK-507, this should not fail.
     public void removeNonExistentNode() throws Exception {
         try {
             mk.commit("/", "-\"a\"", null, null);
@@ -48,9 +46,10 @@ public class MongoMKCommitRemoveTest ext
     @Test
     public void removeAndAddNode() throws Exception {
         String base = mk.commit("", "+\"/a\":{}", null, null);
-        mk.commit("", "-\"/a\"", base, null);
+        String rev = mk.commit("", "-\"/a\"", base, null);
         assertTrue(mk.nodeExists("/a", base));
-        mk.commit("", "+\"/a\":{}", base, null);
+        assertFalse(mk.nodeExists("/a", rev));
+        mk.commit("", "+\"/a\":{}", rev, null);
     }
 
     @Test



Mime
View raw message