jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1451604 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/ test/java/org/apache/jackrabbit/mongomk/prototype/
Date Fri, 01 Mar 2013 14:41:37 GMT
Author: thomasm
Date: Fri Mar  1 14:41:37 2013
New Revision: 1451604

URL: http://svn.apache.org/r1451604
Log:
OAK-619 Lock-free MongoMK implementation (property name escaping, bigger cache)

Modified:
    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/main/java/org/apache/jackrabbit/mongomk/prototype/Utils.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/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java?rev=1451604&r1=1451603&r2=1451604&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
Fri Mar  1 14:41:37 2013
@@ -52,7 +52,7 @@ public class MongoDocumentStore implemen
     private long time;
     
     private Cache<String, Map<String, Object>> cache =
-            new Cache<String, Map<String, Object>>(1024);
+            new Cache<String, Map<String, Object>>(1024 * 20);
 
     public MongoDocumentStore(DB db) {
         nodesCollection = db.getCollection(Collection.NODES.toString());

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=1451604&r1=1451603&r2=1451604&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
Fri Mar  1 14:41:37 2013
@@ -260,8 +260,7 @@ public class MongoMK implements MicroKer
             if (key.equals(UpdateOp.WRITE_COUNT)) {
                 writeCount += (Long) map.get(key);
             }
-            if (key.startsWith("_")) {
-                // TODO property name escaping
+            if (!Utils.isPropertyName(key)) {
                 continue;
             }
             Object v = map.get(key);
@@ -269,7 +268,8 @@ public class MongoMK implements MicroKer
             Map<String, String> valueMap = (Map<String, String>) v;
             if (valueMap != null) {
                 String value = getLatestValue(valueMap, rev);
-                n.setProperty(key, value);
+                String propertyName = Utils.unescapePropertyName(key);
+                n.setProperty(propertyName, value);
             }
         }
         n.setWriteCount(writeCount);

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=1451604&r1=1451603&r2=1451604&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
Fri Mar  1 14:41:37 2013
@@ -49,11 +49,7 @@ public class Node {
     }
 
     public void copyTo(Node newNode) {
-        for (Map.Entry<String, String> e : properties.entrySet()) {
-            if (!filter(e.getKey())) {
-                newNode.setProperty(e.getKey(), e.getValue());
-            }
-        }
+        newNode.properties.putAll(properties);
     }
 
     public String toString() {
@@ -74,7 +70,8 @@ public class Node {
         UpdateOp op = new UpdateOp(path, id, isNew);
         op.set(UpdateOp.ID, id);
         for (String p : properties.keySet()) {
-            op.addMapEntry(p + "." + rev.toString(), properties.get(p));
+            String key = Utils.escapePropertyName(p);
+            op.addMapEntry(key + "." + rev.toString(), properties.get(p));
         }
         return op;
     }
@@ -96,17 +93,6 @@ public class Node {
             json.key(p).encodedValue(properties.get(p));
         }
     }
-
-    /**
-     * Determines if the key is system generated
-     */
-    private static boolean filter(String key) {
-        //TODO We need to move node properties to a sub key
-        // so that all other top level props can be considered as
-        // system generated and handled in a better way,
-        // or escape properties that start with a _
-        return key.startsWith("_");
-    }
     
     /**
      * A list of children for a node.

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Utils.java?rev=1451604&r1=1451603&r2=1451604&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Utils.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Utils.java
Fri Mar  1 14:41:37 2013
@@ -61,5 +61,28 @@ public class Utils {
         ObjectId objId = new ObjectId();
         return objId._machine();
     }
+
+    public static String escapePropertyName(String propertyName) {
+        String key = propertyName;
+        if (key.startsWith("$") || key.startsWith("_")) {
+            key = "_" + key;
+        }
+        // '*' in a property name is illegal in JCR I believe
+        // TODO find a better solution
+        key = key.replace('.', '*');
+        return key;
+    }
+    
+    public static String unescapePropertyName(String key) {
+        if (key.startsWith("__") || key.startsWith("_$")) {
+            key = key.substring(1);
+        }
+        key = key.replace('*', '.');
+        return key;
+    }
+    
+    public static boolean isPropertyName(String key) {
+        return !key.startsWith("_") || key.startsWith("__") || key.startsWith("_$");
+    }
     
 }

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=1451604&r1=1451603&r2=1451604&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
Fri Mar  1 14:41:37 2013
@@ -80,6 +80,16 @@ public class SimpleTest {
     }
     
     @Test
+    public void escapePropertyName() {
+        MongoMK mk = createMK();
+        String rev = mk.commit(
+                "/", "+\"test\":{\"name.first\": \"Hello\", \"_id\": \"a\", \"$x\": \"1\"}",
null, null);
+        String test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
+        assertEquals("{\"$x\":\"1\",\"_id\":\"a\",\"name.first\":\"Hello\",\":childNodeCount\":0}",
test);
+        mk.dispose();
+    }
+    
+    @Test
     public void commit() {
         MongoMK mk = createMK();
         



Mime
View raw message