Author: mreutegg
Date: Mon Feb 10 09:03:11 2014
New Revision: 1566532

URL: http://svn.apache.org/r1566532
Log:
OAK-1394: Event generation too slow with DocumentNodeStore

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitQueue.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKDiffTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
 Mon Feb 10 09:03:11 2014
@@ -153,7 +153,6 @@ public class Commit {
         if (!operations.isEmpty()) {
             updateParentChildStatus();
             applyToDocumentStore();
-            applyToCache(false);
         }
     }
 
@@ -161,7 +160,6 @@ public class Commit {
         if (!operations.isEmpty()) {
             updateParentChildStatus();
             applyToDocumentStore(baseRevision);
-            applyToCache(true);
         }
     }
 
@@ -442,18 +440,15 @@ public class Commit {
     }
 
     /**
-     * Apply the changes to the DocumentMK (to update the cache).
+     * Apply the changes to the DocumentNodeStore (to update the cache).
      * 
+     * @param before the revision right before this commit.
      * @param isBranchCommit whether this is a commit to a branch
      */
-    public void applyToCache(boolean isBranchCommit) {
+    public void applyToCache(Revision before, boolean isBranchCommit) {
         HashMap<String, ArrayList<String>> nodesWithChangedChildren = new 
HashMap<String, ArrayList<String>>();
-        ArrayList<String> addOrRemove = new ArrayList<String>();
-        addOrRemove.addAll(addedNodes);
-        addOrRemove.addAll(removedNodes);
-        for (String p : addOrRemove) {
+        for (String p : modifiedNodes) {
             if (PathUtils.denotesRoot(p)) {
-                // special case: root node was added
                 continue;
             }
             String parent = PathUtils.getParentPath(p);
@@ -464,16 +459,22 @@ public class Commit {
             }
             list.add(p);
         }
+        List<String> added = new ArrayList<String>();
+        List<String> removed = new ArrayList<String>();
+        List<String> changed = new ArrayList<String>();
         for (String path : modifiedNodes) {
-            ArrayList<String> added = new ArrayList<String>();
-            ArrayList<String> removed = new ArrayList<String>();
-            ArrayList<String> changed = nodesWithChangedChildren.get(path);
-            if (changed != null) {
-                for (String s : changed) {
+            added.clear();
+            removed.clear();
+            changed.clear();
+            ArrayList<String> changes = nodesWithChangedChildren.get(path);
+            if (changes != null) {
+                for (String s : changes) {
                     if (addedNodes.contains(s)) {
                         added.add(s);
                     } else if (removedNodes.contains(s)) {
                         removed.add(s);
+                    } else {
+                        changed.add(s);
                     }
                 }
             }
@@ -482,7 +483,8 @@ public class Commit {
             boolean pendingLastRev = op == null
                     || !NodeDocument.hasLastRev(op, revision.getClusterId());
             boolean isDelete = op != null && op.isDelete();
-            nodeStore.applyChanges(revision, path, isNew, isDelete, 
pendingLastRev, isBranchCommit, added, removed);
+            nodeStore.applyChanges(revision, before, path, isNew, isDelete,
+                    pendingLastRev, isBranchCommit, added, removed, changed);
         }
     }
 

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitQueue.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitQueue.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitQueue.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitQueue.java
 Mon Feb 10 09:03:11 2014
@@ -74,12 +74,13 @@ class CommitQueue {
         return revs;
     }
 
-    void done(@Nonnull Revision rev, boolean isBranch, @Nullable CommitInfo 
info) {
-        checkNotNull(rev);
+    void done(@Nonnull Commit commit, boolean isBranch, @Nullable CommitInfo 
info) {
+        checkNotNull(commit);
         if (isBranch) {
-            removeCommit(rev);
+            commit.applyToCache(commit.getBaseRevision(), true);
+            removeCommit(commit.getRevision());
         } else {
-            afterTrunkCommit(rev, info);
+            afterTrunkCommit(commit, info);
         }
     }
 
@@ -101,8 +102,10 @@ class CommitQueue {
         }
     }
 
-    private void afterTrunkCommit(Revision rev, CommitInfo info) {
+    private void afterTrunkCommit(@Nonnull Commit commit,
+                                  @Nullable CommitInfo info) {
         assert !commits.isEmpty();
+        Revision rev = commit.getRevision();
 
         boolean isHead;
         Entry commitEntry;
@@ -120,16 +123,12 @@ class CommitQueue {
                 LOG.debug("removed {}, head is now {}", rev, commits.isEmpty() 
? null : commits.firstKey());
                 // remember before revision
                 Revision before = store.getHeadRevision();
+                // apply changes to cache based on before revision
+                commit.applyToCache(before, false);
                 // update head revision
                 store.setHeadRevision(rev);
                 NodeState root = store.getRoot();
-                // TODO: correct?
-                dispatcher.contentChanged(store.getRoot(before), null);
-                try {
-                    dispatcher.contentChanged(root, info);
-                } finally {
-                    dispatcher.contentChanged(root, null);
-                }
+                dispatcher.contentChanged(root, info);
             } finally {
                 // notify next if there is any
                 notifyHead();

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 Mon Feb 10 09:03:11 2014
@@ -226,7 +226,7 @@ final class DocumentNodeState extends Ab
                         return true;
                     } else if (getChildNodeCount(LOCAL_DIFF_THRESHOLD) > 
LOCAL_DIFF_THRESHOLD) {
                         // use DocumentNodeStore compare when there are many 
children
-                        return dispatch(store.diff(this.node, mBase.node), 
mBase, diff);
+                        return dispatch(store.diffChildren(this.node, 
mBase.node), mBase, diff);
                     }
                 }
             }
@@ -240,12 +240,12 @@ final class DocumentNodeState extends Ab
     private boolean dispatch(@Nonnull String jsonDiff,
                              @Nonnull DocumentNodeState base,
                              @Nonnull NodeStateDiff diff) {
-        if (jsonDiff.trim().isEmpty()) {
-            return true;
-        }
         if (!AbstractNodeState.comparePropertiesAgainstBaseState(this, base, 
diff)) {
             return false;
         }
+        if (jsonDiff.trim().isEmpty()) {
+            return true;
+        }
         JsopTokenizer t = new JsopTokenizer(jsonDiff);
         boolean continueComparison = true;
         while (continueComparison) {

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=1566532&r1=1566531&r2=1566532&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
 Mon Feb 10 09:03:11 2014
@@ -232,9 +232,9 @@ public final class DocumentNodeStore
     /**
      * Diff cache.
      *
-     * Key: PathRev, value: Diff
+     * Key: PathRev, value: StringValue
      */
-    private final Cache<CacheValue, Diff> diffCache;
+    private final Cache<CacheValue, StringValue> diffCache;
     private final CacheStats diffCacheStats;
 
     /**
@@ -316,7 +316,8 @@ public final class DocumentNodeStore
             Node n = new Node("/", head);
             commit.addNode(n);
             commit.applyToDocumentStore();
-            commit.applyToCache(false);
+            // use dummy Revision as before
+            commit.applyToCache(new Revision(0, 0, clusterId), false);
             setHeadRevision(commit.getRevision());
             // make sure _lastRev is written back to store
             backgroundWrite();
@@ -453,7 +454,7 @@ public final class DocumentNodeStore
 
     void done(@Nonnull Commit c, boolean isBranch, @Nullable CommitInfo info) {
         try {
-            commitQueue.done(c.getRevision(), isBranch, info);
+            commitQueue.done(c, isBranch, info);
         } finally {
             backgroundOperationLock.readLock().unlock();
         }
@@ -618,7 +619,6 @@ public final class DocumentNodeStore
         // this gives us a chance to detect whether there are more
         // child nodes than requested.
         int rawLimit = (int) Math.min(Integer.MAX_VALUE, ((long) limit) + 1);
-        Set<Revision> validRevisions = new HashSet<Revision>();
         for (;;) {
             c.children.clear();
             docs = readChildDocs(path, name, rawLimit);
@@ -626,10 +626,11 @@ public final class DocumentNodeStore
             for (NodeDocument doc : docs) {
                 numReturned++;
                 // filter out deleted children
-                if (doc.isDeleted(this, rev, validRevisions)) {
+                String p = Utils.getPathFromId(doc.getId());
+                Node child = getNode(p, rev);
+                if (child == null) {
                     continue;
                 }
-                String p = Utils.getPathFromId(doc.getId());
                 if (c.children.size() < limit) {
                     // add to children until limit is reached
                     c.children.add(p);
@@ -767,7 +768,8 @@ public final class DocumentNodeStore
     /**
      * Apply the changes of a node to the cache.
      *
-     * @param rev the revision
+     * @param rev the commit revision
+     * @param before the revision right before the commit.
      * @param path the path
      * @param isNew whether this is a new node
      * @param isDelete whether the node is deleted
@@ -775,12 +777,13 @@ public final class DocumentNodeStore
      * @param isBranchCommit whether this is from a branch commit
      * @param added the list of added child nodes
      * @param removed the list of removed child nodes
+     * @param changed the list of changed child nodes.
      *
      */
-    public void applyChanges(Revision rev, String path,
+    public void applyChanges(Revision rev, Revision before, String path,
                              boolean isNew, boolean isDelete, boolean 
pendingLastRev,
-                             boolean isBranchCommit, ArrayList<String> added,
-                             ArrayList<String> removed) {
+                             boolean isBranchCommit, List<String> added,
+                             List<String> removed, List<String> changed) {
         UnsavedModifications unsaved = unsavedLastRevisions;
         if (isBranchCommit) {
             Revision branchRev = rev.asBranchRevision();
@@ -788,34 +791,34 @@ public final class DocumentNodeStore
         }
         if (isBranchCommit || pendingLastRev) {
             // write back _lastRev with background thread
-            Revision prev = unsaved.put(path, rev);
-            if (prev != null) {
-                if (isRevisionNewer(prev, rev)) {
-                    // revert
-                    unsaved.put(path, prev);
-                    String msg = String.format("Attempt to update " +
-                            "unsavedLastRevision for %s with %s, which is " +
-                            "older than current %s.",
-                            path, rev, prev);
-                    throw new MicroKernelException(msg);
-                }
-            }
+            unsaved.put(path, rev);
         }
-        CacheValue key = childNodeCacheKey(path, rev, null);
-        Node.Children c = nodeChildrenCache.getIfPresent(key);
-        if (isNew || (!isDelete && c != null)) {
-            Node.Children c2 = new Node.Children();
-            TreeSet<String> set = new TreeSet<String>();
-            if (c != null) {
-                set.addAll(c.children);
-            }
+        if (isNew) {
+            CacheValue key = childNodeCacheKey(path, rev, null);
+            Node.Children c = new Node.Children();
+            TreeSet<String> set = new TreeSet<String>(added);
             set.removeAll(removed);
-            for (String name : added) {
-                set.add(Utils.unshareString(name));
+            for (String p : added) {
+                set.add(Utils.unshareString(p));
+            }
+            c.children.addAll(set);
+            nodeChildrenCache.put(key, c);
+        } else if (!isDelete) {
+            // update diff cache for modified nodes
+            PathRev key = diffCacheKey(path, before, rev);
+            JsopWriter w = new JsopStream();
+            for (String p : added) {
+                w.tag('+').key(p).object().endObject().newline();
+            }
+            for (String p : removed) {
+                w.tag('-').value(p).newline();
             }
-            c2.children.addAll(set);
-            nodeChildrenCache.put(key, c2);
+            for (String p : changed) {
+                w.tag('^').key(p).object().endObject().newline();
+            }
+            diffCache.put(key, new StringValue(w.toString()));
         }
+        // update docChildrenCache
         if (!added.isEmpty()) {
             CacheValue docChildrenKey = new StringValue(path);
             NodeDocument.Children docChildren = 
docChildrenCache.getIfPresent(docChildrenKey);
@@ -1050,25 +1053,24 @@ public final class DocumentNodeStore
     }
 
     /**
-     * Compares the given {@code state} against the {@code base} state and
-     * reports the differences as a json diff string.
+     * Compares the given {@code node} against the {@code base} state and
+     * reports the differences on the children as a json diff string. This
+     * method does not report any property changes between the two nodes.
      *
-     * @param node the state to compare.
-     * @param base the base state to compare against.
+     * @param node the node to compare.
+     * @param base the base node to compare against.
      * @return the json diff.
      */
-    String diff(final @Nonnull Node node,
-                final @Nonnull Node base) {
-        PathRev key = new PathRev(
-                checkNotNull(node).getLastRevision() + "-" + node.getPath(),
-                checkNotNull(base).getLastRevision());
+    String diffChildren(final @Nonnull Node node, final @Nonnull Node base) {
+        PathRev key = diffCacheKey(node.getPath(),
+                base.getLastRevision(), node.getLastRevision());
         try {
-            return diffCache.get(key, new Callable<Diff>() {
+            return diffCache.get(key, new Callable<StringValue>() {
                 @Override
-                public Diff call() throws Exception {
-                    return new Diff(diffImpl(base, node));
+                public StringValue call() throws Exception {
+                    return new StringValue(diffImpl(base, node));
                 }
-            }).diff;
+            }).toString();
         } catch (ExecutionException e) {
             if (e.getCause() instanceof MicroKernelException) {
                 throw (MicroKernelException) e.getCause();
@@ -1084,26 +1086,27 @@ public final class DocumentNodeStore
         if (fromRevisionId.equals(toRevisionId)) {
             return "";
         }
-        PathRev key = new PathRev(toRevisionId + "-" + path,
-                Revision.fromString(fromRevisionId));
+        Revision fromRev = Revision.fromString(fromRevisionId);
+        Revision toRev = Revision.fromString(toRevisionId);
+        final Node from = getNode(path, fromRev);
+        final Node to = getNode(path, toRev);
+        if (from == null || to == null) {
+            // TODO implement correct behavior if the node does'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, from != null, toRev, to != null);
+            throw new MicroKernelException(msg);
+        }
+        PathRev key = diffCacheKey(path, fromRev, toRev);
         try {
-            return diffCache.get(key, new Callable<Diff>() {
+            JsopWriter writer = new JsopStream();
+            diffProperties(from, to, writer);
+            return writer.toString() + diffCache.get(key, new 
Callable<StringValue>() {
                 @Override
-                public Diff call() throws Exception {
-                    Revision fromRev = Revision.fromString(fromRevisionId);
-                    Revision toRev = Revision.fromString(toRevisionId);
-                    Node from = getNode(path, fromRev);
-                    Node to = getNode(path, toRev);
-                    if (from == null || to == null) {
-                        // TODO implement correct behavior if the node 
does'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, from != null, toRev, to != 
null);
-                        throw new MicroKernelException(msg);
-                    }
-                    return new Diff(diffImpl(from, to));
+                public StringValue call() throws Exception {
+                    return new StringValue(diffImpl(from, to));
                 }
-            }).diff;
+            });
         } catch (ExecutionException e) {
             if (e.getCause() instanceof MicroKernelException) {
                 throw (MicroKernelException) e.getCause();
@@ -1238,6 +1241,7 @@ public final class DocumentNodeStore
             try {
                 backgroundWrite();
                 backgroundRead();
+                dispatcher.contentChanged(getRoot(), null);
             } finally {
                 writeLock.unlock();
             }
@@ -1284,7 +1288,7 @@ public final class DocumentNodeStore
 
                     // the latest revisions of the current cluster node
                     // happened before the latest revisions of other cluster 
nodes
-                    revisionComparator.add(Revision.newRevision(clusterId), 
headSeen);
+                    revisionComparator.add(newRevision(), headSeen);
                 }
                 hasNewRevisions = true;
                 lastKnownRevision.put(machineId, r);
@@ -1296,7 +1300,7 @@ public final class DocumentNodeStore
             // TODO only invalidate affected items
             docChildrenCache.invalidateAll();
             // the head revision is after other revisions
-            setHeadRevision(Revision.newRevision(clusterId));
+            setHeadRevision(newRevision());
         }
         revisionComparator.purge(Revision.getCurrentTimestamp() - 
REMEMBER_REVISION_ORDER_MILLIS);
     }
@@ -1375,15 +1379,13 @@ public final class DocumentNodeStore
 
     //-----------------------------< internal 
>---------------------------------
 
-    private String diffImpl(Node from, Node to)
-            throws MicroKernelException {
-        JsopWriter w = new JsopStream();
-        for (String p : from.getPropertyNames()) {
+    private static void diffProperties(Node from, Node to, JsopWriter w) {
+        for (String name : from.getPropertyNames()) {
             // changed or removed properties
-            String fromValue = from.getProperty(p);
-            String toValue = to.getProperty(p);
+            String fromValue = from.getProperty(name);
+            String toValue = to.getProperty(name);
             if (!fromValue.equals(toValue)) {
-                w.tag('^').key(p);
+                w.tag('^').key(PathUtils.concat(from.getPath(), name));
                 if (toValue == null) {
                     w.value(null);
                 } else {
@@ -1391,12 +1393,19 @@ public final class DocumentNodeStore
                 }
             }
         }
-        for (String p : to.getPropertyNames()) {
+        for (String name : to.getPropertyNames()) {
             // added properties
-            if (from.getProperty(p) == null) {
-                w.tag('^').key(p).encodedValue(to.getProperty(p)).newline();
+            if (from.getProperty(name) == null) {
+                w.tag('^').key(PathUtils.concat(from.getPath(), name))
+                        .encodedValue(to.getProperty(name)).newline();
             }
         }
+    }
+
+    private String diffImpl(Node from, Node to)
+            throws MicroKernelException {
+        JsopWriter w = new JsopStream();
+        diffProperties(from, to, w);
         // TODO this does not work well for large child node lists
         // use a document store index instead
         int max = MANY_CHILDREN_THRESHOLD;
@@ -1513,11 +1522,17 @@ public final class DocumentNodeStore
     }
 
     private static PathRev childNodeCacheKey(@Nonnull String path,
-                                            @Nonnull Revision readRevision,
-                                            @Nullable String name) {
+                                             @Nonnull Revision readRevision,
+                                             @Nullable String name) {
         return new PathRev((name == null ? "" : name) + path, readRevision);
     }
 
+    private static PathRev diffCacheKey(@Nonnull String path,
+                                        @Nonnull Revision from,
+                                        @Nonnull Revision to) {
+        return new PathRev(from + path, to);
+    }
+
     private static DocumentRootBuilder asDocumentRootBuilder(NodeBuilder 
builder)
             throws IllegalArgumentException {
         if (!(builder instanceof DocumentRootBuilder)) {
@@ -1564,25 +1579,6 @@ public final class DocumentNodeStore
     }
 
     /**
-     * A (cached) result of the diff operation.
-     */
-    private static class Diff implements CacheValue {
-
-        final String diff;
-
-        Diff(String diff) {
-            this.diff = diff;
-        }
-
-        @Override
-        public int getMemory() {
-            return 16                               // shallow size
-                    + 40 + diff.length() * 2;       // diff string
-        }
-
-    }
-
-    /**
      * A background thread.
      */
     static class BackgroundOperation implements Runnable {

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java
 Mon Feb 10 09:03:11 2014
@@ -125,8 +125,8 @@ public class DocumentNodeStoreBranch
      * @return the result state.
      */
     private DocumentNodeState persist(Changes op,
-                                   DocumentNodeState base,
-                                   CommitInfo info) {
+                                      DocumentNodeState base,
+                                      CommitInfo info) {
         boolean success = false;
         Commit c = store.newCommit(base.getRevision());
         Revision rev;

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
 Mon Feb 10 09:03:11 2014
@@ -131,7 +131,7 @@ public class MongoDocumentStore implemen
             nodesCache = builder.buildCache(builder.getDocumentCacheSize());
         }
 
-        cacheStats = new CacheStats(nodesCache, "MongoMk-Documents", 
builder.getWeigher(),
+        cacheStats = new CacheStats(nodesCache, "DocumentMk-Documents", 
builder.getWeigher(),
                 builder.getDocumentCacheSize());
     }
 

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CommitQueueTest.java
 Mon Feb 10 09:03:11 2014
@@ -26,7 +26,6 @@ import java.util.concurrent.atomic.Atomi
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import org.apache.jackrabbit.oak.spi.commit.ChangeDispatcher;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -44,19 +43,17 @@ public class CommitQueueTest {
     @Test
     public void concurrentCommits() throws Exception {
         final DocumentNodeStore store = new 
DocumentMK.Builder().getNodeStore();
-        ChangeDispatcher dispatcher = new ChangeDispatcher(store.getRoot());
         AtomicBoolean running = new AtomicBoolean(true);
-        final CommitQueue queue = new CommitQueue(store, dispatcher);
         final List<Exception> exceptions = Collections.synchronizedList(new 
ArrayList<Exception>());
 
-        Closeable observer = dispatcher.addObserver(new Observer() {
+        Closeable observer = store.addObserver(new Observer() {
             private Revision before = new Revision(0, 0, store.getClusterId());
 
             @Override
             public void contentChanged(@Nonnull NodeState root, @Nullable 
CommitInfo info) {
                 DocumentNodeState after = (DocumentNodeState) root;
                 Revision r = after.getRevision();
-//                System.out.println("seen: " + r);
+                System.out.println("seen: " + r);
                 if (r.compareRevisionTime(before) < 0) {
                     exceptions.add(new Exception(
                             "Inconsistent revision sequence. Before: " +
@@ -75,7 +72,7 @@ public class CommitQueueTest {
                 public void run() {
                     try {
                         for (int i = 0; i < COMMITS_PER_WRITER; i++) {
-                            Revision rev = queue.createRevision();
+                            Commit commit = store.newCommit(null);
                             try {
                                 Thread.sleep(0, random.nextInt(1000));
                             } catch (InterruptedException e) {
@@ -83,10 +80,10 @@ public class CommitQueueTest {
                             }
                             if (random.nextInt(5) == 0) {
                                 // cancel 20% of the commits
-                                queue.canceled(rev);
+                                store.canceled(commit);
                             } else {
                                 boolean isBranch = random.nextInt(5) == 0;
-                                queue.done(rev, isBranch, null);
+                                store.done(commit, isBranch, null);
                             }
                         }
                     } catch (Exception e) {

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKDiffTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKDiffTest.java?rev=1566532&r1=1566531&r2=1566532&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKDiffTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKDiffTest.java
 Mon Feb 10 09:03:11 2014
@@ -37,8 +37,8 @@ public class DocumentMKDiffTest extends 
         String rev2 = mk.commit("/", "^\"node1/node2/prop1\":\"val1 new\" 
^\"node1/node2/prop2\":null", null, null);
 
         String diff = mk.diff(rev1, rev2, "/node1/node2", 0);
-        assertTrue(diff.contains("^\"prop2\":null"));
-        assertTrue(diff.contains("^\"prop1\":\"val1 new\""));
+        assertTrue(diff.contains("^\"/node1/node2/prop2\":null"));
+        assertTrue(diff.contains("^\"/node1/node2/prop1\":\"val1 new\""));
     }
 
     @Test
@@ -196,7 +196,7 @@ public class DocumentMKDiffTest extends 
         assertTrue(reverseDiff.length() > 0);
 
         // Commit the reverseDiff and check property is gone.
-        mk.commit("/level1", reverseDiff, null, null);
+        mk.commit("", reverseDiff, null, null);
         assertTrue(mk.nodeExists("/level1", null));
         obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyNotExists(obj, "prop1");
@@ -221,7 +221,7 @@ public class DocumentMKDiffTest extends 
         assertTrue(reverseDiff.length() > 0);
 
         // Commit the reverseDiff and check property is added back.
-        mk.commit("/level1", reverseDiff, null, null);
+        mk.commit("", reverseDiff, null, null);
         obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyExists(obj, "prop1");
     }
@@ -244,7 +244,7 @@ public class DocumentMKDiffTest extends 
         assertTrue(reverseDiff.length() > 0);
 
         // Commit the reverseDiff and check property is set back.
-        mk.commit("/level1", reverseDiff, null, null);
+        mk.commit("", reverseDiff, null, null);
         obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyValue(obj, "prop1", "value1");
     }


Reply via email to