jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1436589 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/api/model/ main/java/org/apache/jackrabbit/mongomk/impl/ main/java/org/apache/jackrabbit/mongomk/impl/command/ main/java/org/apache/jackrabbit/mong...
Date Mon, 21 Jan 2013 20:14:13 GMT
Author: mreutegg
Date: Mon Jan 21 20:14:13 2013
New Revision: 1436589

URL: http://svn.apache.org/viewvc?rev=1436589&view=rev
Log:
OAK-573: OneLevelDiffCommand inefficient for commits with many affected paths

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Commit.java
    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/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/command/GetNodesCommand.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/OneLevelDiffCommand.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoAssert.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Commit.java?rev=1436589&r1=1436588&r2=1436589&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/api/model/Commit.java
Mon Jan 21 20:14:13 2013
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mongomk.api.model;
 
 import java.util.List;
+import java.util.SortedSet;
 
 import org.apache.jackrabbit.mongomk.api.instruction.Instruction;
 
@@ -30,7 +31,7 @@ public interface Commit {
      *
      * @return The paths affected by the commit.
      */
-    List<String> getAffectedPaths();
+    SortedSet<String> getAffectedPaths();
 
     /**
      * Returns the base revision id the commit is based on.

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=1436589&r1=1436588&r2=1436589&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
Mon Jan 21 20:14:13 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.mongomk.impl;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
 
@@ -298,7 +297,7 @@ public class MongoNodeStore implements N
         options.put("unique", Boolean.TRUE);
         commitCollection.ensureIndex(index, options);
         MongoCommit commit = new MongoCommit();
-        commit.setAffectedPaths(Arrays.asList(new String[] { "/" }));
+        commit.setAffectedPaths(Collections.singleton("/"));
         commit.setBaseRevisionId(0L);
         commit.setDiff(INITIAL_COMMIT_DIFF);
         commit.setMessage(INITIAL_COMMIT_MESSAGE);

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=1436589&r1=1436588&r2=1436589&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
Mon Jan 21 20:14:13 2013
@@ -169,7 +169,7 @@ public class CommitCommand extends BaseC
     }
 
     private void prepareCommit() throws Exception {
-        commit.setAffectedPaths(new LinkedList<String>(affectedPaths));
+        commit.setAffectedPaths(affectedPaths);
         commit.setBaseRevisionId(mongoSync.getHeadRevisionId());
         commit.setRevisionId(revisionId);
         if (commit.getBranchId() == null && branchId != null) {

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=1436589&r1=1436588&r2=1436589&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
Mon Jan 21 20:14:13 2013
@@ -167,7 +167,7 @@ public class CommitCommandNew extends Ba
     }
 
     private void prepareCommit() throws Exception {
-        commit.setAffectedPaths(new LinkedList<String>(affectedPaths));
+        commit.setAffectedPaths(affectedPaths);
         commit.setBaseRevisionId(mongoSync.getHeadRevisionId());
         commit.setRevisionId(revisionId);
         if (commit.getBranchId() == null && branchId != null) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetNodesCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetNodesCommand.java?rev=1436589&r1=1436588&r2=1436589&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetNodesCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetNodesCommand.java
Mon Jan 21 20:14:13 2013
@@ -21,6 +21,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.jackrabbit.mongomk.api.model.Node;
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
@@ -141,7 +142,7 @@ public class GetNodesCommand extends Bas
         for (ListIterator<MongoCommit> iterator = lastCommits.listIterator(); iterator.hasPrevious();)
{
             MongoCommit commitMongo = iterator.previous();
             long revisionId = commitMongo.getRevisionId();
-            List<String> affectedPaths = commitMongo.getAffectedPaths();
+            Set<String> affectedPaths = commitMongo.getAffectedPaths();
             for (String path : affectedPaths) {
                 problematicNodes.put(path, revisionId);
             }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java?rev=1436589&r1=1436588&r2=1436589&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
Mon Jan 21 20:14:13 2013
@@ -139,7 +139,7 @@ public class MergeCommand extends BaseCo
 
         for (int i = commits.size() - 1; i >= 0; i--) {
             MongoCommit commit = commits.get(i);
-            List<String> affectedPaths = commit.getAffectedPaths();
+            Set<String> affectedPaths = commit.getAffectedPaths();
             for (String affectedPath : affectedPaths) {
                 if (branchId.equals(commit.getBranchId())) {
                     if (affectedPathsTrunk.contains(affectedPath)) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/OneLevelDiffCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/OneLevelDiffCommand.java?rev=1436589&r1=1436588&r2=1436589&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/OneLevelDiffCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/OneLevelDiffCommand.java
Mon Jan 21 20:14:13 2013
@@ -81,13 +81,13 @@ public class OneLevelDiffCommand extends
         // find out what changed below path
         List<MongoCommit> commits = getCommits(fromCommit, toCommit);
         Set<String> affectedPaths = new HashSet<String>();
+        String from = (PathUtils.denotesRoot(path) ? path : path + "/") + "\u0000";
+        String to = (PathUtils.denotesRoot(path) ? path : path + "/") + "\uFFFF";
         for (MongoCommit mc : commits) {
-            for (String p : mc.getAffectedPaths()) {
-                if (p.startsWith(path)) {
-                    int d = PathUtils.getDepth(p);
-                    if (d > pathDepth) {
-                        affectedPaths.add(PathUtils.getAncestorPath(p, d - pathDepth - 1));
-                    }
+            for (String p : mc.getAffectedPaths().subSet(from, to)) {
+                int d = PathUtils.getDepth(p);
+                if (d > pathDepth) {
+                    affectedPaths.add(PathUtils.getAncestorPath(p, d - pathDepth - 1));
                 }
             }
         }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java?rev=1436589&r1=1436588&r2=1436589&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java
Mon Jan 21 20:14:13 2013
@@ -28,6 +28,9 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 
@@ -52,7 +55,7 @@ public class MongoCommit extends BasicDB
     public static final String KEY_TIMESTAMP = "ts";
 
     private final List<Instruction> instructions;
-    private List<String> affectedPaths;
+    private SortedSet<String> affectedPaths;
 
     private static final long serialVersionUID = 6656294757102309827L;
 
@@ -72,16 +75,17 @@ public class MongoCommit extends BasicDB
 
     @Override
     @SuppressWarnings("unchecked")
-    public List<String> getAffectedPaths() {
+    public SortedSet<String> getAffectedPaths() {
         if (affectedPaths == null) {
-            affectedPaths = inflate((byte[]) get(KEY_AFFECTED_PATH));
+            affectedPaths = new TreeSet<String>(
+                    inflate((byte[]) get(KEY_AFFECTED_PATH)));
         }
-        return affectedPaths;
+        return Collections.unmodifiableSortedSet(affectedPaths);
     }
 
-    public void setAffectedPaths(List<String> affectedPaths) {
-        this.affectedPaths = affectedPaths;
-        put(KEY_AFFECTED_PATH, compress(affectedPaths));
+    public void setAffectedPaths(Set<String> affectedPaths) {
+        this.affectedPaths = new TreeSet<String>(affectedPaths);
+        put(KEY_AFFECTED_PATH, compress(this.affectedPaths));
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoAssert.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoAssert.java?rev=1436589&r1=1436588&r2=1436589&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoAssert.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoAssert.java
Mon Jan 21 20:14:13 2013
@@ -21,6 +21,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.jackrabbit.mongomk.api.model.Commit;
 import org.apache.jackrabbit.mongomk.api.model.Node;
@@ -51,7 +52,7 @@ public class MongoAssert {
         MongoCommit result = (MongoCommit) commitCollection.findOne(query);
         Assert.assertNotNull(result);
 
-        List<String> actualPaths = result.getAffectedPaths();
+        Set<String> actualPaths = result.getAffectedPaths();
         Assert.assertEquals(new HashSet<String>(Arrays.asList(expectedPaths)), new
HashSet<String>(actualPaths));
     }
 



Mime
View raw message