jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1523609 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java test/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentSplitTest.java
Date Mon, 16 Sep 2013 12:23:23 GMT
Author: mreutegg
Date: Mon Sep 16 12:23:22 2013
New Revision: 1523609

URL: http://svn.apache.org/r1523609
Log:
OAK-926: MongoMK: split documents when they are too large
- Parse PREVIOUS into Revision/Range on demand
- More tests

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

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=1523609&r1=1523608&r2=1523609&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
Mon Sep 16 12:23:22 2013
@@ -118,6 +118,11 @@ public class NodeDocument extends Docume
 
     final DocumentStore store;
 
+    /**
+     * Parsed and sorted set of previous revisions.
+     */
+    private SortedMap<Revision, Range> previous;
+
     private final long time = System.currentTimeMillis();
 
     NodeDocument(@Nonnull DocumentStore store) {
@@ -151,19 +156,23 @@ public class NodeDocument extends Docume
 
     /**
      * Returns <code>true</code> if the given <code>revision</code>
is marked
-     * committed in <strong>this</strong> document including previous documents.
+     * committed.
      *
      * @param revision the revision.
      * @return <code>true</code> if committed; <code>false</code>
otherwise.
      */
     public boolean isCommitted(@Nonnull Revision revision) {
+        NodeDocument commitRootDoc = getCommitRoot(checkNotNull(revision));
+        if (commitRootDoc == null) {
+            return false;
+        }
         String rev = checkNotNull(revision).toString();
-        String value = getLocalRevisions().get(rev);
+        String value = commitRootDoc.getLocalRevisions().get(rev);
         if (value != null) {
             return Utils.isCommitted(value);
         }
         // check previous docs
-        for (NodeDocument prev : getPreviousDocs(revision, REVISIONS)) {
+        for (NodeDocument prev : commitRootDoc.getPreviousDocs(revision, REVISIONS)) {
             if (prev.containsRevision(revision)) {
                 return prev.isCommitted(revision);
             }
@@ -659,20 +668,26 @@ public class NodeDocument extends Docume
                     main.removeMapEntry(property, r);
                     old.setMapEntry(property, r, entry.getValue());
                 }
-                splitOps.add(old);
-                splitOps.add(main);
             }
+            splitOps.add(old);
+            splitOps.add(main);
         }
         return splitOps;
     }
 
-    @Override
+    /**
+     * Returns previous revision ranges for this document. The revision keys are
+     * sorted descending, newest first!
+     *
+     * @return the previous ranges for this document.
+     */
     @Nonnull
-    protected Map<?, ?> transformAndSeal(@Nonnull Map<Object, Object> map,
-                                         @Nullable String key,
-                                         int level) {
-        if (level == 1) {
-            if (PREVIOUS.equals(key)) {
+    SortedMap<Revision, Range> getPreviousRanges() {
+        if (previous == null) {
+            Map<String, String> map = getLocalMap(PREVIOUS);
+            if (map.isEmpty()) {
+                previous = EMPTY_RANGE_MAP;
+            } else {
                 SortedMap<Revision, Range> transformed = new TreeMap<Revision, Range>(
                         new Comparator<Revision>() {
                             @Override
@@ -687,30 +702,14 @@ public class NodeDocument extends Docume
                                 return c;
                             }
                         });
-                for (Map.Entry<Object, Object> entry : map.entrySet()) {
-                    Revision high = Revision.fromString(entry.getKey().toString());
-                    Revision low = Revision.fromString(entry.getValue().toString());
+                for (Map.Entry<String, String> entry : map.entrySet()) {
+                    Revision high = Revision.fromString(entry.getKey());
+                    Revision low = Revision.fromString(entry.getValue());
                     transformed.put(high, new Range(high, low));
                 }
-                return Collections.unmodifiableSortedMap(transformed);
+                previous = Collections.unmodifiableSortedMap(transformed);
             }
         }
-        return super.transformAndSeal(map, key, level);
-    }
-
-    /**
-     * Returns previous revision ranges for this document. The revision keys are
-     * sorted descending, newest first!
-     *
-     * @return the previous ranges for this document.
-     */
-    @Nonnull
-    SortedMap<Revision, Range> getPreviousRanges() {
-        @SuppressWarnings("unchecked")
-        SortedMap<Revision, Range> previous = (SortedMap<Revision, Range>) get(PREVIOUS);
-        if (previous == null) {
-            previous = EMPTY_RANGE_MAP;
-        }
         return previous;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentSplitTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentSplitTest.java?rev=1523609&r1=1523608&r2=1523609&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentSplitTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentSplitTest.java
Mon Sep 16 12:23:22 2013
@@ -103,4 +103,29 @@ public class DocumentSplitTest extends B
             assertNotNull(node);
         }
     }
+
+    @Test
+    public void splitCommitRoot() throws Exception {
+        DocumentStore store = mk.getDocumentStore();
+        mk.commit("/", "+\"foo\":{}+\"bar\":{}", null, null);
+        NodeDocument doc = store.find(Collection.NODES, Utils.getIdFromPath("/foo"));
+        assertNotNull(doc);
+        Set<String> commitRoots = Sets.newHashSet();
+        commitRoots.addAll(doc.getLocalCommitRoot().keySet());
+        // create nodes
+        while (commitRoots.size() <= NodeDocument.REVISIONS_SPLIT_OFF_SIZE) {
+            commitRoots.add(mk.commit("/", "^\"foo/prop\":" + commitRoots.size() +
+                    "^\"bar/prop\":" + commitRoots.size(), null, null));
+        }
+        mk.runBackgroundOperations();
+        doc = store.find(Collection.NODES, Utils.getIdFromPath("/foo"));
+        assertNotNull(doc);
+        Map<String, String> commits = doc.getLocalCommitRoot();
+        // one remaining in the local commit root map
+        assertEquals(1, commits.size());
+        for (String r : commitRoots) {
+            Revision rev = Revision.fromString(r);
+            assertTrue(doc.isCommitted(rev));
+        }
+    }
 }



Mime
View raw message