jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1526193 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml: ImportHandler.java ImporterImpl.java
Date Wed, 25 Sep 2013 14:38:47 GMT
Author: chetanm
Date: Wed Sep 25 14:38:47 2013
New Revision: 1526193

URL: http://svn.apache.org/r1526193
Log:
OAK-1037 - Improve performance of XmlImport

Import logic perform check if a node with given uuid already exist or not. This check is costly
 if performed against a tree which has lots of transient changes. To speed up the process
the logic
 is now broken into two part

1. Look for a node with given id using an unmodified root
2. Also make note of uuid of trees newly created and look into that

This improves the import performance by factor of 10.

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java?rev=1526193&r1=1526192&r2=1526193&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
Wed Sep 25 14:38:47 2013
@@ -57,6 +57,8 @@ public class ImportHandler extends Defau
     private static final Logger log = LoggerFactory.getLogger(ImportHandler.class);
 
     private final Root root;
+    private final Root initialRoot;
+
     private final SessionContext sessionContext;
     private final Importer importer;
     private final NamespaceHelper helper;
@@ -72,9 +74,10 @@ public class ImportHandler extends Defau
         this.isWorkspaceImport = isWorkspaceImport;
 
         SessionDelegate sd = sessionContext.getSessionDelegate();
+        initialRoot = sd.getContentSession().getLatestRoot();
         root = (isWorkspaceImport) ? sd.getContentSession().getLatestRoot() : sd.getRoot();
         helper = new NamespaceHelper(sessionContext.getSession());
-        importer = new ImporterImpl(absPath, sessionContext, root, uuidBehavior, isWorkspaceImport);
+        importer = new ImporterImpl(absPath, sessionContext, root, initialRoot, uuidBehavior,
isWorkspaceImport);
     }
 
     //---------------------------------------------------------< ErrorHandler >

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1526193&r1=1526192&r2=1526193&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
Wed Sep 25 14:38:47 2013
@@ -19,8 +19,10 @@ package org.apache.jackrabbit.oak.jcr.xm
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.Stack;
 import java.util.UUID;
 
@@ -73,10 +75,28 @@ public class ImporterImpl implements Imp
 
     private final String userID;
     private final AccessManager accessManager;
-    private final IdentifierManager idManager;
+
+    /**
+     * There are two IdentifierManagers used.
+     *
+     * baseStateIdManager - Associated with the initial root on which
+     *   no modifications are performed
+     *
+     * currentStateIdManager - Associated with current root on which all import
+     *   operations are being performed
+     *
+     */
+    private final IdentifierManager baseStateIdManager;
+    private final IdentifierManager currentStateIdManager;
     private final EffectiveNodeTypeProvider effectiveNodeTypeProvider;
     private final DefinitionProvider definitionProvider;
 
+    /**
+     * Set of newly created uuid from nodes which are
+     * created in this import
+     */
+    private final Set<String> uuids = new HashSet<String>();
+
     private final Stack<Tree> parents;
 
     /**
@@ -107,6 +127,7 @@ public class ImporterImpl implements Imp
     public ImporterImpl(String absPath,
                         SessionContext sessionContext,
                         Root root,
+                        Root initialRoot,
                         int uuidBehavior,
                         boolean isWorkspaceImport) throws RepositoryException {
         if (!PathUtils.isAbsolute(absPath)) {
@@ -139,7 +160,8 @@ public class ImporterImpl implements Imp
         }
         ntTypesRoot = root.getTree(NODE_TYPES_PATH);
         accessManager = sessionContext.getAccessManager();
-        idManager = new IdentifierManager(root);
+        baseStateIdManager = new IdentifierManager(initialRoot);
+        currentStateIdManager = new IdentifierManager(root);
         effectiveNodeTypeProvider = sessionContext.getWorkspace().getNodeTypeManager();
         definitionProvider = sessionContext.getWorkspace().getNodeTypeManager();
         // TODO: end
@@ -192,14 +214,10 @@ public class ImporterImpl implements Imp
     }
 
     private Tree resolveUUIDConflict(Tree parent,
+                                     Tree conflicting,
                                      String conflictingId,
                                      NodeInfo nodeInfo) throws RepositoryException {
         Tree tree;
-        Tree conflicting = idManager.getTree(conflictingId);
-        if (conflicting != null && !conflicting.exists()) {
-            conflicting = null;
-        }
-
         if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW) {
             // create new with new uuid
             tree = createTree(parent, nodeInfo, UUID.randomUUID().toString());
@@ -367,10 +385,28 @@ public class ImporterImpl implements Imp
                 // no potential uuid conflict, always add new node
                 tree = createTree(parent, nodeInfo, id);
             } else {
-                Tree conflicting = idManager.getTree(id);
+
+                //1. First check from base state that tree corresponding to
+                //this id exist
+                Tree conflicting = baseStateIdManager.getTree(id);
+
+                if(conflicting == null){
+                    //1.a. Check if id is found in newly created nodes
+                    if(uuids.contains(id)){
+                        conflicting = currentStateIdManager.getTree(id);
+                    }
+                }else{
+                    //1.b Re obtain the conflicting tree from Id Manager
+                    //associated with current root. Such that any operation
+                    //on it gets reflected in later operations
+                    //In case a tree with same id was removed earlier then it
+                    //would return null
+                    conflicting = currentStateIdManager.getTree(id);
+                }
+
                 if (conflicting != null && conflicting.exists()) {
                     // resolve uuid conflict
-                    tree = resolveUUIDConflict(parent, id, nodeInfo);
+                    tree = resolveUUIDConflict(parent, conflicting, id, nodeInfo);
                     if (tree == null) {
                         // no new node has been created, so skip this node
                         parents.push(null); // push null onto stack for skipped node
@@ -429,6 +465,23 @@ public class ImporterImpl implements Imp
                 pnImporter = null;
             }
         }
+
+        collectUUIDs(parent);
+    }
+
+    private void collectUUIDs(Tree tree) {
+        if(tree == null){
+            return;
+        }
+
+        String uuid = TreeUtil.getString(tree, JcrConstants.JCR_UUID);
+        if(uuid != null){
+            uuids.add(uuid);
+        }
+
+        for(Tree child : tree.getChildren()){
+            collectUUIDs(child);
+        }
     }
 
     @Override



Mime
View raw message