jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1415555 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl: command/NodeExistsCommand.java instruction/CommitCommandInstructionVisitor.java
Date Fri, 30 Nov 2012 09:22:06 GMT
Author: meteatamel
Date: Fri Nov 30 09:22:05 2012
New Revision: 1415555

URL: http://svn.apache.org/viewvc?rev=1415555&view=rev
Log:
OAK-440 - Concurrency issue when 3 microkernels are writing in the same db

Reduced FetchNodesAction calls to speed up commits

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/NodeExistsCommand.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/NodeExistsCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/NodeExistsCommand.java?rev=1415555&r1=1415554&r2=1415555&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/NodeExistsCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/NodeExistsCommand.java
Fri Nov 30 09:22:05 2012
@@ -36,6 +36,7 @@ public class NodeExistsCommand extends B
     private String branchId;
     private String path;
     private List<MongoCommit> validCommits;
+    private MongoNode node;
 
     /**
      * Constructs a new {@code NodeExistsCommandMongo}.
@@ -71,15 +72,7 @@ public class NodeExistsCommand extends B
 
     @Override
     public Boolean execute() throws Exception {
-        if (PathUtils.denotesRoot(path)) {
-            return true;
-        }
-
-        // Check that all the paths up to the root actually exist.
-        return pathExists();
-    }
-
-    private boolean pathExists() throws Exception {
+        // To check a path really exists, all the paths from root need to be checked.
         Set<String> paths = new HashSet<String>();
         char[] path = this.path.toCharArray();
         StringBuilder current = new StringBuilder();
@@ -91,10 +84,12 @@ public class NodeExistsCommand extends B
             }
             current.append(path[i]);
         }
+        paths.add(current.toString());
 
         if (revisionId == null) {
             revisionId = new GetHeadRevisionCommand(nodeStore).execute();
         }
+
         FetchNodesAction action = new FetchNodesAction(nodeStore, paths, revisionId);
         action.setBranchId(branchId);
         action.setValidCommits(validCommits);
@@ -106,34 +101,22 @@ public class NodeExistsCommand extends B
             String parentPath = PathUtils.getParentPath(currentPath);
             MongoNode parentNode = pathAndNodeMap.get(parentPath);
             if (parentNode == null || !parentNode.childExists(childName)) {
+                node = null;
                 return false;
             }
             currentPath = PathUtils.getParentPath(currentPath);
         }
+        node = pathAndNodeMap.get(this.path);
         return true;
     }
 
-//    private boolean pathExists() throws Exception {
-//        while (!PathUtils.denotesRoot(path)) {
-//            readParentNode(revisionId, branchId);
-//            if (parentNode == null || !childExists()) {
-//                return false;
-//            }
-//            path = PathUtils.getParentPath(path);
-//        }
-//
-//        return true;
-//    }
-//
-//    private void readParentNode(Long revisionId, String branchId) throws Exception {
-//        String parentPath = PathUtils.getParentPath(path);
-//        GetNodesCommand command = new GetNodesCommand(nodeStore, parentPath, revisionId);
-//        command.setBranchId(branchId);
-//        parentNode = command.execute();
-//    }
-//
-//    private boolean childExists() {
-//        String childName = PathUtils.getName(path);
-//        return parentNode.getChildNodeEntry(childName) != null;
-//    }
+    /**
+     * After {@link NodeExistsCommand} executed, this method can be used to access
+     * the node with the path.
+     *
+     * @return Node or null if it does not exist.
+     */
+    public MongoNode getNode() {
+        return node;
+    }
 }
\ No newline at end of file

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=1415555&r1=1415554&r2=1415555&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
Fri Nov 30 09:22:05 2012
@@ -261,20 +261,9 @@ public class CommitCommandInstructionVis
         if (!exists) {
             throw new NotFoundException(path + " @rev" + headRevisionId);
         }
-
-        // Fetch the node without its descendants.
-        FetchNodesAction query = new FetchNodesAction(nodeStore,
-                path, false /*fetchDescendants*/, headRevisionId);
-        query.setBranchId(branchId);
-        query.setValidCommits(validCommits);
-        Map<String, MongoNode> nodes = query.execute();
-
-        if (nodes.containsKey(path)) {
-            node = nodes.get(path);
-            node.removeField("_id");
-            pathNodeMap.put(path, node);
-        }
-
+        node = existCommand.getNode();
+        node.removeField("_id");
+        pathNodeMap.put(path, node);
         return node;
     }
 



Mime
View raw message