jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1447617 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/ test/java/org/apache/jackrabbit/mongomk/prototype/
Date Tue, 19 Feb 2013 08:07:34 GMT
Author: thomasm
Date: Tue Feb 19 08:07:33 2013
New Revision: 1447617

URL: http://svn.apache.org/r1447617
Log:
OAK-619 Lock-free MongoMK implementation (WIP)

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java?rev=1447617&r1=1447616&r2=1447617&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
Tue Feb 19 08:07:33 2013
@@ -28,7 +28,7 @@ public interface DocumentStore {
 
     Map<String, Object> find(Collection collection, String key);
 
-    List<Map<String, Object>> query(Collection collection, String fromKey, String
toKey);
+    List<Map<String, Object>> query(Collection collection, String fromKey, String
toKey, int limit);
     
     void remove(Collection collection, String key);
 

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java?rev=1447617&r1=1447616&r2=1447617&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
Tue Feb 19 08:07:33 2013
@@ -66,7 +66,7 @@ public class MemoryDocumentStore impleme
         return copy;
     }
     
-    public List<Map<String, Object>> query(Collection collection, String fromKey,
String toKey) {
+    public List<Map<String, Object>> query(Collection collection, String fromKey,
String toKey, int limit) {
         ConcurrentSkipListMap<String, Map<String, Object>> map = getMap(collection);
         ConcurrentNavigableMap<String, Map<String, Object>> sub = map.subMap(fromKey,
toKey);
         ArrayList<Map<String, Object>> list = new ArrayList<Map<String,
Object>>();
@@ -76,6 +76,9 @@ public class MemoryDocumentStore impleme
                 copy.putAll(n);
             }
             list.add(copy);
+            if (list.size() > limit) {
+                break;
+            }
         }
         return list;
     }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java?rev=1447617&r1=1447616&r2=1447617&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
Tue Feb 19 08:07:33 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -27,6 +28,7 @@ import org.slf4j.LoggerFactory;
 import com.mongodb.BasicDBObject;
 import com.mongodb.DB;
 import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
 import com.mongodb.DBObject;
 import com.mongodb.QueryBuilder;
 import com.mongodb.WriteConcern;
@@ -47,18 +49,30 @@ public class MongoDocumentStore implemen
 
     @Override
     public Map<String, Object> find(Collection collection, String path) {
-        DBObject n = getNode(collection, path);
-        if (n == null) {
+        DBCollection dbCollection = getDBCollection(collection);
+        DBObject doc = dbCollection.findOne(getByPathQuery(path));
+        if (doc == null) {
             return null;
         }
-        return convertFromDBObject(n);
+        return convertFromDBObject(doc);
     }
     
     @Override
     public List<Map<String, Object>> query(Collection collection,
-            String fromKey, String toKey) {
-        // TODO retrieve children
-        return null;
+            String fromKey, String toKey, int limit) {
+        DBCollection dbCollection = getDBCollection(collection);
+        QueryBuilder queryBuilder = QueryBuilder.start(KEY_PATH);
+        queryBuilder.greaterThanEquals(fromKey);
+        queryBuilder.lessThan(toKey);
+        DBObject query = queryBuilder.get();
+        DBCursor cursor = dbCollection.find(query);
+        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+        for (int i=0; i<limit && cursor.hasNext(); i++) {
+            DBObject o = cursor.next();
+            Map<String, Object> map = convertFromDBObject(o);
+            list.add(map);
+        }
+        return list;
     }
 
     @Override
@@ -188,11 +202,6 @@ public class MongoDocumentStore implemen
         }
     }
 
-    private DBObject getNode(Collection collection, String path) {
-        DBCollection dbCollection = getDBCollection(collection);
-        return dbCollection.findOne(getByPathQuery(path));
-    }
-
     private static DBObject getByPathQuery(String path) {
         return QueryBuilder.start(KEY_PATH).is(path).get();
     }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java?rev=1447617&r1=1447616&r2=1447617&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
Tue Feb 19 08:07:33 2013
@@ -131,9 +131,9 @@ public class MongoMK implements MicroKer
         backgroundThread = new Thread(new Runnable() {
             public void run() {
                 while (!isDisposed.get()) {
-                    synchronized (this) {
+                    synchronized (isDisposed) {
                         try {
-                            wait(ASYNC_DELAY);
+                            isDisposed.wait(ASYNC_DELAY);
                         } catch (InterruptedException e) {
                             // ignore
                         }
@@ -165,8 +165,8 @@ public class MongoMK implements MicroKer
     
     public void dispose() {
         if (!isDisposed.getAndSet(true)) {
-            synchronized (backgroundThread) {
-                backgroundThread.notifyAll();
+            synchronized (isDisposed) {
+                isDisposed.notifyAll();
             }
             try {
                 backgroundThread.join();
@@ -208,14 +208,19 @@ public class MongoMK implements MicroKer
         return x.compareRevisionTime(requestRevision) >= 0;
     }
     
-    public Node.Children readChildren(String path, Revision rev) {
-        String from = Node.convertPathToDocumentId(path + "/");
-        String to = from.substring(0, from.length() - 1) + "0";
-        List<Map<String, Object>> list = store.query(DocumentStore.Collection.NODES,
from, to);
+    public Node.Children readChildren(String path, Revision rev, int limit) {
+        String from = PathUtils.concat(path, "a");
+        from = Node.convertPathToDocumentId(from);
+        from = from.substring(0, from.length() - 1);
+        String to = PathUtils.concat(path, "z/z");
+        to = Node.convertPathToDocumentId(to);
+        to = to.substring(0, to.length() - 3);
+        List<Map<String, Object>> list = store.query(DocumentStore.Collection.NODES,
from, to, limit);
         Node.Children c = new Node.Children(path, rev);
         for (Map<String, Object> e : list) {
+            // TODO put the whole node in the cache
             String id = e.get("_id").toString();
-            String p = id.substring(1);
+            String p = id.substring(2);
             c.children.add(p);
         }
         return c;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java?rev=1447617&r1=1447616&r2=1447617&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
Tue Feb 19 08:07:33 2013
@@ -71,10 +71,15 @@ public class SimpleTest {
         assertEquals("{\"name\":\"Hello\"}", test);
         
         rev = mk.commit("/test", "+\"a\":{\"name\": \"World\"}", null, null);
+        rev = mk.commit("/test", "+\"b\":{\"name\": \"!\"}", null, null);
         test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
-        Children c = mk.readChildren("/", Revision.fromString(rev));
-        assertEquals("/: []", c.toString());
-        // assertEquals("{\"name\":\"Hello\",{\"a\":\"name\":\"World\"}}", test);
+        Children c;
+        c = mk.readChildren("/", 
+                Revision.fromString(rev), Integer.MAX_VALUE);
+        assertEquals("/: [/test]", c.toString());
+        c = mk.readChildren("/test", 
+                Revision.fromString(rev), Integer.MAX_VALUE);
+        assertEquals("/test: [/test/a, /test/b]", c.toString());
         
         // System.out.println(test);
         mk.dispose();



Mime
View raw message