You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2016/07/21 07:12:36 UTC

svn commit: r1753645 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document: DocumentMK.java DocumentNodeStore.java

Author: mreutegg
Date: Thu Jul 21 07:12:36 2016
New Revision: 1753645

URL: http://svn.apache.org/viewvc?rev=1753645&view=rev
Log:
OAK-4584: Move DocumentMK specific methods from DocumentNodeStore

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1753645&r1=1753644&r2=1753645&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java Thu Jul 21 07:12:36 2016
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.plugins.document;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 
 import java.io.InputStream;
 import java.net.UnknownHostException;
@@ -197,7 +198,6 @@ public class DocumentMK {
         final DocumentNodeState before = nodeStore.getNode(path, fromRev);
         final DocumentNodeState after = nodeStore.getNode(path, toRev);
         if (before == null || after == null) {
-            // TODO implement correct behavior if the node doesn't/didn't exist
             String msg = String.format("Diff is only supported if the node exists in both cases. " +
                             "Node [%s], fromRev [%s] -> %s, toRev [%s] -> %s",
                     path, fromRev, before != null, toRev, after != null);
@@ -261,7 +261,6 @@ public class DocumentMK {
                 json.key(name).object().endObject();
             }
             if (c.hasMore) {
-                // TODO use a better way to notify there are more children
                 json.key(":childNodeCount").value(Long.MAX_VALUE);
             } else {
                 json.key(":childNodeCount").value(c.children.size());
@@ -306,7 +305,6 @@ public class DocumentMK {
 
     public String merge(String branchRevisionId, String message)
             throws DocumentStoreException {
-        // TODO improve implementation if needed
         RevisionVector revision = RevisionVector.fromString(branchRevisionId);
         if (!revision.isBranch()) {
             throw new DocumentStoreException("Not a branch: " + branchRevisionId);
@@ -408,7 +406,7 @@ public class DocumentMK {
                         throw new DocumentStoreException("Node not found: " + path + " in revision " + baseRevId);
                     }
                     commit.removeNode(path, toRemove);
-                    nodeStore.markAsDeleted(toRemove, commit, true);
+                    markAsDeleted(toRemove, commit, true);
                     break;
                 case '^':
                     t.read(':');
@@ -426,7 +424,6 @@ public class DocumentMK {
                     commit.updateProperty(p, propertyName, value);
                     break;
                 case '>': {
-                    // TODO support moving nodes that were modified within this commit
                     t.read(':');
                     String targetPath = t.readString();
                     if (!PathUtils.isAbsolute(targetPath)) {
@@ -438,11 +435,10 @@ public class DocumentMK {
                     } else if (nodeExists(targetPath, baseRevId)) {
                         throw new DocumentStoreException("Node already exists: " + targetPath + " in revision " + baseRevId);
                     }
-                    nodeStore.moveNode(source, targetPath, commit);
+                    moveNode(source, targetPath, commit);
                     break;
                 }
                 case '*': {
-                    // TODO support copying nodes that were modified within this commit
                     t.read(':');
                     String targetPath = t.readString();
                     if (!PathUtils.isAbsolute(targetPath)) {
@@ -454,7 +450,7 @@ public class DocumentMK {
                     } else if (nodeExists(targetPath, baseRevId)) {
                         throw new DocumentStoreException("Node already exists: " + targetPath + " in revision " + baseRevId);
                     }
-                    nodeStore.copyNode(source, targetPath, commit);
+                    copyNode(source, targetPath, commit);
                     break;
                 }
                 default:
@@ -483,6 +479,44 @@ public class DocumentMK {
         commit.addNode(n);
     }
 
+    private void copyNode(DocumentNodeState source, String targetPath, Commit commit) {
+        moveOrCopyNode(false, source, targetPath, commit);
+    }
+
+    private void moveNode(DocumentNodeState source, String targetPath, Commit commit) {
+        moveOrCopyNode(true, source, targetPath, commit);
+    }
+
+    private void markAsDeleted(DocumentNodeState node, Commit commit, boolean subTreeAlso) {
+        commit.removeNode(node.getPath(), node);
+
+        if (subTreeAlso) {
+            // recurse down the tree
+            for (DocumentNodeState child : nodeStore.getChildNodes(node, null, Integer.MAX_VALUE)) {
+                markAsDeleted(child, commit, true);
+            }
+        }
+    }
+
+    private void moveOrCopyNode(boolean move,
+                                DocumentNodeState source,
+                                String targetPath,
+                                Commit commit) {
+        RevisionVector destRevision = commit.getBaseRevision().update(commit.getRevision());
+        DocumentNodeState newNode = new DocumentNodeState(nodeStore, targetPath, destRevision);
+        source.copyTo(newNode);
+
+        commit.addNode(newNode);
+        if (move) {
+            markAsDeleted(source, commit, false);
+        }
+        for (DocumentNodeState child : nodeStore.getChildNodes(source, null, Integer.MAX_VALUE)) {
+            String childName = PathUtils.getName(child.getPath());
+            String destChildPath = concat(targetPath, childName);
+            moveOrCopyNode(move, child, destChildPath, commit);
+        }
+    }
+
     //----------------------------< Builder >-----------------------------------
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1753645&r1=1753644&r2=1753645&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Thu Jul 21 07:12:36 2016
@@ -845,26 +845,6 @@ public final class DocumentNodeStore
         splitCandidates.put(id, id);
     }
 
-    void copyNode(DocumentNodeState source, String targetPath, Commit commit) {
-        moveOrCopyNode(false, source, targetPath, commit);
-    }
-
-    void moveNode(DocumentNodeState source, String targetPath, Commit commit) {
-        moveOrCopyNode(true, source, targetPath, commit);
-    }
-
-    void markAsDeleted(DocumentNodeState node, Commit commit, boolean subTreeAlso) {
-        commit.removeNode(node.getPath(), node);
-
-        if (subTreeAlso) {
-            // recurse down the tree
-            // TODO causes issue with large number of children
-            for (DocumentNodeState child : getChildNodes(node, null, Integer.MAX_VALUE)) {
-                markAsDeleted(child, commit, true);
-            }
-        }
-    }
-
     @CheckForNull
     AbstractDocumentNodeState getSecondaryNodeState(@Nonnull final String path,
                               @Nonnull final RevisionVector rootRevision,
@@ -2378,33 +2358,6 @@ public final class DocumentNodeStore
         return System.currentTimeMillis();
     }
 
-    private void moveOrCopyNode(boolean move,
-                                DocumentNodeState source,
-                                String targetPath,
-                                Commit commit) {
-        // TODO Optimize - Move logic would not work well with very move of very large subtrees
-        // At minimum we can optimize by traversing breadth wise and collect node id
-        // and fetch them via '$in' queries
-
-        // TODO Transient Node - Current logic does not account for operations which are part
-        // of this commit i.e. transient nodes. If its required it would need to be looked
-        // into
-
-        RevisionVector destRevision = commit.getBaseRevision().update(commit.getRevision());
-        DocumentNodeState newNode = new DocumentNodeState(this, targetPath, destRevision);
-        source.copyTo(newNode);
-
-        commit.addNode(newNode);
-        if (move) {
-            markAsDeleted(source, commit, false);
-        }
-        for (DocumentNodeState child : getChildNodes(source, null, Integer.MAX_VALUE)) {
-            String childName = PathUtils.getName(child.getPath());
-            String destChildPath = concat(targetPath, childName);
-            moveOrCopyNode(move, child, destChildPath, commit);
-        }
-    }
-
     /**
      * Creates and returns a MarkSweepGarbageCollector if the current BlobStore
      * supports garbage collection