jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1447406 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/ test/java/org/apache/jackrabbit/mongomk/prototype/
Date Mon, 18 Feb 2013 18:00:42 GMT
Author: thomasm
Date: Mon Feb 18 18:00:42 2013
New Revision: 1447406

URL: http://svn.apache.org/r1447406
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/main/java/org/apache/jackrabbit/mongomk/prototype/Node.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=1447406&r1=1447405&r2=1447406&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
Mon Feb 18 18:00:42 2013
@@ -28,11 +28,14 @@ public interface DocumentStore {
 
     Map<String, Object> find(Collection collection, String key);
 
+    List<Map<String, Object>> query(Collection collection, String fromKey, String
toKey);
+    
     void remove(Collection collection, String key);
 
+    void create(Collection collection, List<UpdateOp> updateOps);
+    
     Map<String, Object> createOrUpdate(Collection collection, UpdateOp update); 
     
     void dispose();
 
-    void create(Collection collection, List<UpdateOp> updateOps);
 }

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=1447406&r1=1447405&r2=1447406&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
Mon Feb 18 18:00:42 2013
@@ -16,9 +16,11 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentNavigableMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 
 import org.apache.jackrabbit.mongomk.prototype.UpdateOp.Operation;
@@ -60,8 +62,22 @@ public class MemoryDocumentStore impleme
         Map<String, Object> copy = Utils.newMap();
         synchronized (n) {
             copy.putAll(n);
-            return copy;
         }
+        return copy;
+    }
+    
+    public List<Map<String, Object>> query(Collection collection, String fromKey,
String toKey) {
+        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>>();
+        for (Map<String, Object> n : sub.values()) {
+            Map<String, Object> copy = Utils.newMap();
+            synchronized (n) {
+                copy.putAll(n);
+            }
+            list.add(copy);
+        }
+        return list;
     }
 
     /**
@@ -192,4 +208,5 @@ public class MemoryDocumentStore impleme
     public void dispose() {
         // ignore
     }
+
 }
\ No newline at end of file

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=1447406&r1=1447405&r2=1447406&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
Mon Feb 18 18:00:42 2013
@@ -53,6 +53,13 @@ public class MongoDocumentStore implemen
         }
         return convertFromDBObject(n);
     }
+    
+    @Override
+    public List<Map<String, Object>> query(Collection collection,
+            String fromKey, String toKey) {
+        // TODO retrieve children
+        return null;
+    }
 
     @Override
     public void remove(Collection collection, String path) {

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=1447406&r1=1447405&r2=1447406&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
Mon Feb 18 18:00:42 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.mongomk.pr
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -206,6 +207,19 @@ public class MongoMK implements MicroKer
         // TODO currently we only compare the timestamps
         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);
+        Node.Children c = new Node.Children(path, rev);
+        for (Map<String, Object> e : list) {
+            String id = e.get("_id").toString();
+            String p = id.substring(1);
+            c.children.add(p);
+        }
+        return c;
+    }
 
     private Node readNode(String path, Revision rev) {
         String id = Node.convertPathToDocumentId(path);
@@ -303,7 +317,8 @@ public class MongoMK implements MicroKer
         Revision rev = Revision.fromString(revisionId);
         Node n = getNode(path, rev);
         JsopStream json = new JsopStream();
-        n.append(json, true);
+        boolean includeId = filter != null && filter.contains(":id");
+        n.append(json, includeId);
         return json.toString();
     }
 

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Node.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Node.java?rev=1447406&r1=1447405&r2=1447406&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Node.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Node.java
Mon Feb 18 18:00:42 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
+import java.util.ArrayList;
 import java.util.Map;
 
 import org.apache.jackrabbit.mk.json.JsopWriter;
@@ -82,5 +83,23 @@ public class Node {
         }
         json.endObject();
     }
+    
+    static class Children {
+        
+        final String path;
+        final Revision rev;
+        
+        final ArrayList<String> children = new ArrayList<String>();
+        
+        Children(String path, Revision rev) {
+            this.path = path;
+            this.rev = rev;
+        }
+        
+        public String toString() {
+            return path + ": " + children.toString();
+        }
+        
+    }
 
 }

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=1447406&r1=1447405&r2=1447406&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
Mon Feb 18 18:00:42 2013
@@ -20,10 +20,14 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 
 import org.apache.jackrabbit.mongomk.prototype.DocumentStore.Collection;
+import org.apache.jackrabbit.mongomk.prototype.Node.Children;
 import org.junit.Test;
 
 import com.google.common.collect.Lists;
 
+/**
+ * A set of simple tests.
+ */
 public class SimpleTest {
 
     @Test
@@ -61,10 +65,21 @@ public class SimpleTest {
     @Test
     public void commit() {
         MongoMK mk = new MongoMK();
+        
         String rev = mk.commit("/", "+\"test\":{\"name\": \"Hello\"}", null, null);
         String test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
         assertEquals("{\"name\":\"Hello\"}", test);
+        
+        rev = mk.commit("/test", "+\"a\":{\"name\": \"World\"}", 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);
+        
         // System.out.println(test);
         mk.dispose();
     }
+    
+    // TODO run Damians tests
+    
 }



Mime
View raw message