jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1433984 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/mk/wrapper/TimingWrapper.java oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
Date Wed, 16 Jan 2013 15:28:40 GMT
Author: meteatamel
Date: Wed Jan 16 15:28:40 2013
New Revision: 1433984

URL: http://svn.apache.org/viewvc?rev=1433984&view=rev
Log:
OAK-535 - MergeCommand reads complete tree into memory

-Further optimization to MergeCommand optimization. Basically, even if there have been commits
on trunk since the branch was created, MergeCommand now checks whether those commits are conflicting
with branch commits and if not, it simply reapplies branch commits to trunk.
-Added average time for MK operations in TimingWrapper

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/mk/wrapper/TimingWrapper.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/mk/wrapper/TimingWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/mk/wrapper/TimingWrapper.java?rev=1433984&r1=1433983&r2=1433984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/mk/wrapper/TimingWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/mk/wrapper/TimingWrapper.java
Wed Jan 16 15:28:40 2013
@@ -346,8 +346,10 @@ public class TimingWrapper implements Mi
                 double c = count.getValue().count;
                 double max = count.getValue().max;
                 double total = count.getValue().total;
+                double avg = total / c;
                 if (c > 0) {
-                    log(count.getKey() + " --> count:" + c + " max: " + max + " total:
" + total);
+                    log(count.getKey() + " --> count:" + c + " avg: " + avg
+                            + " max: " + max + " total: " + total);
                 }
             }
             System.out.println("Time: " + ((now - startTime) / 1000L));

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=1433984&r1=1433983&r2=1433984&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
Wed Jan 16 15:28:40 2013
@@ -16,9 +16,11 @@
  */
 package org.apache.jackrabbit.mongomk.impl.command;
 
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.jackrabbit.mk.model.tree.DiffBuilder;
 import org.apache.jackrabbit.mk.model.tree.NodeState;
@@ -27,6 +29,7 @@ import org.apache.jackrabbit.mongomk.api
 import org.apache.jackrabbit.mongomk.api.model.Node;
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.action.FetchCommitAction;
+import org.apache.jackrabbit.mongomk.impl.action.FetchCommitsAction;
 import org.apache.jackrabbit.mongomk.impl.action.FetchHeadRevisionIdAction;
 import org.apache.jackrabbit.mongomk.impl.json.JsopParser;
 import org.apache.jackrabbit.mongomk.impl.json.NormalizingJsopHandler;
@@ -83,22 +86,11 @@ public class MergeCommand extends BaseCo
         long branchRootId = Long.parseLong(branchId.substring(0, branchId.indexOf("-")));
 
         Commit newCommit;
-        if (currentHead <= branchRootId) {
-            // no commits to trunk since branch was created
-            StringBuilder diff = new StringBuilder();
-            for (long rev = branchRootId + 1; rev <= commit.getRevisionId(); rev++) {
-                try {
-                    Commit c = new FetchCommitAction(nodeStore, rev).execute();
-                    if (branchId.equals(c.getBranchId())) {
-                        diff.append(normalizeDiff(c.getPath(), c.getDiff()));
-                    }
-                } catch (Exception e) {
-                    // commit does not exist
-                }
-            }
+        String diff = getNonConflictingCommitsDiff(Math.max(currentHead, commit.getRevisionId()),
+                branchRootId, branchId);
+        if (diff != null) {
             newCommit = CommitBuilder.build("/", diff.toString(),
                     MongoUtil.fromMongoRepresentation(currentHead), message);
-
         } else {
             Node ourRoot = getNode("/", rootNodeId, branchId);
 
@@ -108,7 +100,7 @@ public class MergeCommand extends BaseCo
                 ourRoot = mergeNodes(ourRoot, currentHeadNode, branchRootId);
             }
 
-            String diff = new DiffBuilder(MongoUtil.wrap(currentHeadNode),
+            diff = new DiffBuilder(MongoUtil.wrap(currentHeadNode),
                     MongoUtil.wrap(ourRoot), "/", -1,
                     new SimpleMongoNodeStore(), "").build();
 
@@ -128,6 +120,51 @@ public class MergeCommand extends BaseCo
     }
 
     /**
+     * Checks whether there have been no conflicting commits on trunk since the
+     * branch was created and if so, returns the branch diff to be applied against
+     * trunk. Otherwise, it returns null.
+     *
+     * @param currentHead
+     * @param branchRootId
+     * @param branchId
+     * @return
+     */
+    private String getNonConflictingCommitsDiff(long currentHead, long branchRootId, String
branchId) {
+        FetchCommitsAction action = new FetchCommitsAction(nodeStore, branchRootId + 1, currentHead);
+        List<MongoCommit> commits = action.execute();
+
+        Set<String> affectedPathsBranch = new HashSet<String>();
+        Set<String> affectedPathsTrunk = new HashSet<String>();
+        StringBuilder diff = new StringBuilder();
+
+        for (int i = commits.size() - 1; i >= 0; i--) {
+            MongoCommit commit = commits.get(i);
+            List<String> affectedPaths = commit.getAffectedPaths();
+            for (String affectedPath : affectedPaths) {
+                if (branchId.equals(commit.getBranchId())) {
+                    if (affectedPathsTrunk.contains(affectedPath)) {
+                        return null;
+                    }
+                    affectedPathsBranch.add(affectedPath);
+                } else if (commit.getBranchId() == null){
+                    if (affectedPathsBranch.contains(affectedPath)) {
+                        return null;
+                    }
+                    affectedPathsTrunk.add(affectedPath);
+                }
+            }
+            if (branchId.equals(commit.getBranchId())) {
+                try {
+                    diff.append(normalizeDiff(commit.getPath(), commit.getDiff()));
+                } catch (Exception e) {
+                    LOG.error("Normalization error", e);
+                }
+            }
+        }
+        return diff.length() > 0 ? diff.toString() : null;
+    }
+
+    /**
      * Normalizes a JSOP diff by appending the path to all pathStrings of the
      * operations.
      *



Mime
View raw message