jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1524345 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk: MongoMK.java NodeDocument.java
Date Wed, 18 Sep 2013 09:10:31 GMT
Author: mreutegg
Date: Wed Sep 18 09:10:31 2013
New Revision: 1524345

URL: http://svn.apache.org/r1524345
Log:
OAK-926: MongoMK: split documents when they are too large
- Speed up and simplify evaluation of deleted status of a node

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java?rev=1524345&r1=1524344&r2=1524345&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
Wed Sep 18 09:10:31 2013
@@ -572,11 +572,11 @@ public class MongoMK implements MicroKer
         Iterable<NodeDocument> docs;
         Children c = new Children();
         int rawLimit = limit;
+        Set<Revision> validRevisions = new HashSet<Revision>();
         do {
             c.children.clear();
             c.hasMore = true;
             docs = readChildren(path, rawLimit);
-            Set<Revision> validRevisions = new HashSet<Revision>();
             int numReturned = 0;
             for (NodeDocument doc : docs) {
                 numReturned++;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java?rev=1524345&r1=1524344&r2=1524345&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
Wed Sep 18 09:10:31 2013
@@ -384,7 +384,8 @@ public class NodeDocument extends Docume
      */
     @CheckForNull
     public Node getNodeAtRevision(RevisionContext context, Revision readRevision) {
-        Revision min = getLiveRevision(context, readRevision, new HashSet<Revision>());
+        Set<Revision> validRevisions = new HashSet<Revision>();
+        Revision min = getLiveRevision(context, readRevision, validRevisions);
         if (min == null) {
             // deleted
             return null;
@@ -396,13 +397,16 @@ public class NodeDocument extends Docume
                 continue;
             }
             // first check local map, which contains most recent values
-            String value = getLatestValue(context, getLocalMap(key), min, readRevision);
+            Value value = getLatestValue(context, getLocalMap(key),
+                    min, readRevision, validRevisions);
             if (value == null) {
                 // check complete revision history
-                value = getLatestValue(context, getValueMap(key), min, readRevision);
+                value = getLatestValue(context, getValueMap(key),
+                        min, readRevision, validRevisions);
             }
             String propertyName = Utils.unescapePropertyName(key);
-            n.setProperty(propertyName, value);
+            String v = value != null ? value.value : null;
+            n.setProperty(propertyName, v);
         }
 
         // when was this node last modified?
@@ -463,27 +467,7 @@ public class NodeDocument extends Docume
     public boolean isDeleted(RevisionContext context,
                              Revision readRevision,
                              Set<Revision> validRevisions) {
-        Map<String, String> valueMap = getDeleted();
-        if (valueMap.isEmpty()) {
-            return false;
-        }
-        Revision mostRecent = null;
-        boolean deleted = false;
-        for (Map.Entry<String, String> entry : valueMap.entrySet()) {
-            Revision r = Revision.fromString(entry.getKey());
-            if (isRevisionNewer(context, r, readRevision)) {
-                // ignore -> newer than readRevision
-                continue;
-            }
-            if (mostRecent != null && isRevisionNewer(context, mostRecent, r)) {
-                continue;
-            }
-            if (isValidRevision(context, r, readRevision, validRevisions)) {
-                mostRecent = r;
-                deleted = "true".equals(entry.getValue());
-            }
-        }
-        return mostRecent == null || deleted;
+        return getLiveRevision(context, readRevision, validRevisions) == null;
     }
 
     /**
@@ -500,50 +484,15 @@ public class NodeDocument extends Docume
     @CheckForNull
     public Revision getLiveRevision(RevisionContext context, Revision maxRev,
                                     Set<Revision> validRevisions) {
-        Map<String, String> valueMap = getDeleted();
-        if (valueMap.isEmpty()) {
-            return null;
-        }
-        // first, search the newest deleted revision
-        Revision deletedRev = null;
-        for (String r : valueMap.keySet()) {
-            String value = valueMap.get(r);
-            if (!"true".equals(value)) {
-                // only look at deleted revisions now
-                continue;
-            }
-            Revision propRev = Revision.fromString(r);
-            if (isRevisionNewer(context, propRev, maxRev)
-                    || !isValidRevision(context, propRev, maxRev, validRevisions)) {
-                continue;
-            }
-            if (deletedRev == null || isRevisionNewer(context, propRev, deletedRev)) {
-                deletedRev = propRev;
-            }
-        }
-        // now search the oldest non-deleted revision that is newer than the
-        // newest deleted revision
-        Revision liveRev = null;
-        for (String r : valueMap.keySet()) {
-            String value = valueMap.get(r);
-            if ("true".equals(value)) {
-                // ignore deleted revisions
-                continue;
-            }
-            Revision propRev = Revision.fromString(r);
-            if (deletedRev != null && isRevisionNewer(context, deletedRev, propRev))
{
-                // the node was deleted later on
-                continue;
-            }
-            if (isRevisionNewer(context, propRev, maxRev)
-                    || !isValidRevision(context, propRev, maxRev, validRevisions)) {
-                continue;
-            }
-            if (liveRev == null || isRevisionNewer(context, liveRev, propRev)) {
-                liveRev = propRev;
-            }
+        // check local deleted map first
+        Value value = getLatestValue(context, getLocalDeleted(),
+                null, maxRev, validRevisions);
+        if (value == null) {
+            // need to check complete map
+            value = getLatestValue(context, getDeleted(),
+                    null, maxRev, validRevisions);
         }
-        return liveRev;
+        return value != null && value.value.equals("false") ? value.revision : null;
     }
 
     /**
@@ -997,34 +946,37 @@ public class NodeDocument extends Docume
 
     /**
      * Get the latest property value that is larger or equal the min revision,
-     * and smaller or equal the max revision.
+     * and smaller or equal the readRevision revision.
      *
      * @param valueMap the revision-value map
      * @param min the minimum revision (null meaning unlimited)
-     * @param max the maximum revision
+     * @param readRevision the maximum revision
+     * @param validRevisions set of revision considered valid against the given
+     *                       readRevision.
      * @return the value, or null if not found
      */
     @CheckForNull
-    private static String getLatestValue(@Nonnull RevisionContext context,
-                                         @Nonnull Map<String, String> valueMap,
-                                         @Nullable Revision min,
-                                         @Nonnull Revision max) {
+    private Value getLatestValue(@Nonnull RevisionContext context,
+                                 @Nonnull Map<String, String> valueMap,
+                                 @Nullable Revision min,
+                                 @Nonnull Revision readRevision,
+                                 @Nonnull Set<Revision> validRevisions) {
         String value = null;
         Revision latestRev = null;
-        for (String r : valueMap.keySet()) {
-            Revision propRev = Revision.fromString(r);
+        for (Map.Entry<String, String> entry : valueMap.entrySet()) {
+            Revision propRev = Revision.fromString(entry.getKey());
             if (min != null && isRevisionNewer(context, min, propRev)) {
                 continue;
             }
             if (latestRev != null && !isRevisionNewer(context, propRev, latestRev))
{
                 continue;
             }
-            if (includeRevision(context, propRev, max)) {
+            if (isValidRevision(context, propRev, readRevision, validRevisions)) {
                 latestRev = propRev;
-                value = valueMap.get(r);
+                value = entry.getValue();
             }
         }
-        return value;
+        return value != null ? new Value(value, latestRev) : null;
     }
 
     @Nonnull
@@ -1036,4 +988,15 @@ public class NodeDocument extends Docume
     private Map<String, String> getCommitRoot() {
         return ValueMap.create(this, COMMIT_ROOT);
     }
+
+    private static final class Value {
+
+        final String value;
+        final Revision revision;
+
+        Value(@Nonnull String value, @Nonnull Revision revision) {
+            this.value = checkNotNull(value);
+            this.revision = checkNotNull(revision);
+        }
+    }
 }



Mime
View raw message