jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1494076 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/ main/java/org/apache/jackrabbit/mongomk/util/ test/java/org/apache/jackrabbit/mongomk/
Date Tue, 18 Jun 2013 09:15:24 GMT
Author: mreutegg
Date: Tue Jun 18 09:15:24 2013
New Revision: 1494076

URL: http://svn.apache.org/r1494076
Log:
OAK-619 Lock-free MongoMK implementation
- Add more DocumentStore tests

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoMK.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/Utils.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java?rev=1494076&r1=1494075&r2=1494076&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
Tue Jun 18 09:15:24 2013
@@ -92,7 +92,7 @@ public class MemoryDocumentStore impleme
                 Utils.deepCopyMap(n, copy);
             }
             list.add(copy);
-            if (list.size() > limit) {
+            if (list.size() >= limit) {
                 break;
             }
         }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoMK.java?rev=1494076&r1=1494075&r2=1494076&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoMK.java
Tue Jun 18 09:15:24 2013
@@ -94,7 +94,7 @@ public class MongoMK implements MicroKer
     /**
      * The threshold where special handling for many child node starts.
      */
-    private static final int MANY_CHILDREN_THRESHOLD = Integer.getInteger(
+    static final int MANY_CHILDREN_THRESHOLD = Integer.getInteger(
             "oak.mongoMK.manyChildren", 50);
 
     /**
@@ -620,8 +620,8 @@ public class MongoMK implements MicroKer
         // TODO use offset, to avoid O(n^2) and running out of memory
         // to do that, use the *name* of the last entry of the previous batch of children
         // as the starting point
-        String from = getPathLowerLimit(path);
-        String to = getPathUpperLimit(path);
+        String from = Utils.getKeyLowerLimit(path);
+        String to = Utils.getKeyUpperLimit(path);
         List<Map<String, Object>> list = store.query(DocumentStore.Collection.NODES,

                 from, to, limit);
         Children c = new Children(path, rev);
@@ -641,20 +641,6 @@ public class MongoMK implements MicroKer
         }
         return c;
     }
-    
-    private static String getPathLowerLimit(String path) {
-        String from = PathUtils.concat(path, "a");
-        from = Utils.getIdFromPath(from);
-        from = from.substring(0, from.length() - 1);
-        return from;
-    }
-    
-    private static String getPathUpperLimit(String path) {
-        String to = PathUtils.concat(path, "z");
-        to = Utils.getIdFromPath(to);
-        to = to.substring(0, to.length() - 2) + "0";
-        return to;
-    }
 
     private Node readNode(String path, Revision rev) {
         String id = Utils.getIdFromPath(path);
@@ -856,8 +842,8 @@ public class MongoMK implements MicroKer
         long minTimestamp = Math.min(fromRev.getTimestamp(), toRev.getTimestamp());
         Revision rev = isRevisionNewer(fromRev, toRev) ? toRev : fromRev;
         long minValue = Commit.getModified(minTimestamp);
-        String fromKey = getPathLowerLimit(path);
-        String toKey = getPathUpperLimit(path);
+        String fromKey = Utils.getKeyLowerLimit(path);
+        String toKey = Utils.getKeyUpperLimit(path);
         List<Map<String, Object>> list = store.query(DocumentStore.Collection.NODES,
fromKey, toKey, 
                 UpdateOp.MODIFIED, minValue, Integer.MAX_VALUE);
         for (Map<String, Object> e : list) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/Utils.java?rev=1494076&r1=1494075&r2=1494076&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/Utils.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/Utils.java
Tue Jun 18 09:15:24 2013
@@ -23,6 +23,8 @@ import java.util.Set;
 import java.util.TreeMap;
 
 import com.mongodb.BasicDBObject;
+
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.bson.types.ObjectId;
 
 /**
@@ -202,4 +204,31 @@ public class Utils {
         return document.toString().replaceAll(", _", ",\n_").replaceAll("}, ", "},\n");
     }
 
+    /**
+     * Returns the lower key limit to retrieve the children of the given
+     * <code>path</code>.
+     *
+     * @param path a path.
+     * @return the lower key limit.
+     */
+    public static String getKeyLowerLimit(String path) {
+        String from = PathUtils.concat(path, "a");
+        from = getIdFromPath(from);
+        from = from.substring(0, from.length() - 1);
+        return from;
+    }
+
+    /**
+     * Returns the upper key limit to retrieve the children of the given
+     * <code>path</code>.
+     *
+     * @param path a path.
+     * @return the upper key limit.
+     */
+    public static String getKeyUpperLimit(String path) {
+        String to = PathUtils.concat(path, "z");
+        to = getIdFromPath(to);
+        to = to.substring(0, to.length() - 2) + "0";
+        return to;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java?rev=1494076&r1=1494075&r2=1494076&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
Tue Jun 18 09:15:24 2013
@@ -29,6 +29,9 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.jackrabbit.mongomk.DocumentStore.Collection;
+import org.apache.jackrabbit.mongomk.util.Utils;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -65,9 +68,14 @@ public class MongoDocumentStoreTest {
         }
     }
 
+    @Before
+    @After
+    public void cleanUp() {
+        dropCollections();
+    }
+
     @Test
     public void addGetAndRemove() throws Exception {
-        dropCollections();
         DocumentStore docStore = openDocumentStore();
 
         UpdateOp updateOp = new UpdateOp("/", "/", true);
@@ -90,13 +98,10 @@ public class MongoDocumentStoreTest {
         docStore.remove(Collection.NODES, "/");
         obj = docStore.find(Collection.NODES, "/");
         assertTrue(obj == null);
-        dropCollections();
     }
 
     @Test
     public void batchAdd() throws Exception {
-        dropCollections();
-
         DocumentStore docStore = openDocumentStore();
         int nUpdates = 10;
         List<UpdateOp> updateOps = new ArrayList<UpdateOp>();
@@ -110,13 +115,10 @@ public class MongoDocumentStoreTest {
             updateOps.add(updateOp);
         }
         docStore.create(Collection.NODES, updateOps);
-
-        dropCollections();
     }
 
     @Test
     public void addLotsOfNodes() throws Exception {
-
         char[] nPrefix = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
         int nNodes = NODE_COUNT;
 
@@ -138,14 +140,10 @@ public class MongoDocumentStoreTest {
             log("Done: " + (end - start) + "ms");
 
         }
-        dropCollections();
-
     }
 
     @Test
     public void containsMapEntry() {
-        dropCollections();
-
         DocumentStore docStore = openDocumentStore();
         UpdateOp op = new UpdateOp("/node", "/node", true);
         op.setMapEntry("map", "key", "value");
@@ -178,8 +176,22 @@ public class MongoDocumentStoreTest {
         doc = docStore.find(Collection.NODES, "/node");
         assertTrue(doc.containsKey("prop"));
         assertEquals("value", doc.get("prop"));
+    }
 
-        dropCollections();
+    @Test
+    public void queryWithLimit() throws Exception {
+        DocumentStore docStore = openDocumentStore();
+        Revision rev = Revision.newRevision(0);
+        List<UpdateOp> inserts = new ArrayList<UpdateOp>();
+        for (int i = 0; i < MongoMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
+            Node n = new Node("/node-" + i, rev);
+            inserts.add(n.asOperation(true));
+        }
+        docStore.create(Collection.NODES, inserts);
+        List<Map<String, Object>> docs = docStore.query(Collection.NODES,
+                Utils.getKeyLowerLimit("/"),  Utils.getKeyUpperLimit("/"),
+                MongoMK.MANY_CHILDREN_THRESHOLD);
+        assertEquals(MongoMK.MANY_CHILDREN_THRESHOLD, docs.size());
     }
 
     @Test



Mime
View raw message