jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1446078 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/ test/java/org/apache/jackrabbit/mongomk/prototype/
Date Thu, 14 Feb 2013 09:18:35 GMT
Author: meteatamel
Date: Thu Feb 14 09:18:34 2013
New Revision: 1446078

URL: http://svn.apache.org/r1446078
Log:
OAK-619 Lock-free MongoMK implementation

Added a new create method for batch inserts

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/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.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=1446078&r1=1446077&r2=1446078&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
Thu Feb 14 09:18:34 2013
@@ -16,19 +16,21 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
+import java.util.List;
 import java.util.Map;
 
 /**
  * The interface for the backend storage for documents.
  */
 public interface DocumentStore {
-    
+
     enum Collection { NODES }
 
     Map<String, Object> find(Collection collection, String key);
 
     void remove(Collection collection, String key);
-    
+
     Map<String, Object> createOrUpdate(Collection collection, UpdateOp update);
 
+    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=1446078&r1=1446077&r2=1446078&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
Thu Feb 14 09:18:34 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentSkipListMap;
@@ -27,7 +28,7 @@ import org.apache.jackrabbit.mongomk.pro
  * replicas).
  */
 public class MemoryDocumentStore implements DocumentStore {
-    
+
     /**
      * The 'nodes' collection. It contains all the node data, with one document
      * per node, and the path as the primary key. Each document possibly
@@ -39,13 +40,13 @@ public class MemoryDocumentStore impleme
      * removed or updated the node, lazily when reading, or in a background
      * process.
      */
-    private ConcurrentSkipListMap<String, Map<String, Object>> nodes = 
+    private ConcurrentSkipListMap<String, Map<String, Object>> nodes =
             new ConcurrentSkipListMap<String, Map<String, Object>>();
-    
+
     /**
      * Get a document. The returned map is a clone (the caller
      * can modify it without affecting the stored version).
-     * 
+     *
      * @param collection the collection
      * @param path the path
      * @return the map, or null if not found
@@ -62,20 +63,20 @@ public class MemoryDocumentStore impleme
             return copy;
         }
     }
-    
+
     /**
      * Remove a document.
-     * 
+     *
      * @param collection the collection
      * @param path the path
      */
     public void remove(Collection collection, String path) {
         getMap(collection).remove(path);
     }
-    
+
     /**
      * Get the in-memory map for this collection.
-     * 
+     *
      * @param collection the collection
      * @return the map
      */
@@ -87,11 +88,11 @@ public class MemoryDocumentStore impleme
             throw new IllegalArgumentException(collection.name());
         }
     }
-    
+
     /**
      * Create or update a document. For MongoDb, this is using "findAndModify" with
      * the "upsert" flag (insert or update).
-     * 
+     *
      * @param collection the collection
      * @param update the update operation
      * @return the old document, or null if there was no
@@ -100,7 +101,7 @@ public class MemoryDocumentStore impleme
         ConcurrentSkipListMap<String, Map<String, Object>> map = getMap(collection);
         Map<String, Object> n;
         Map<String, Object> oldNode;
-        
+
         // get the node if it's there
         oldNode = n = map.get(update.key);
 
@@ -122,7 +123,7 @@ public class MemoryDocumentStore impleme
             }
             oldNode = old;
         }
-        // update the document 
+        // update the document
         // (document level operations are synchronized)
         synchronized (n) {
             for (Entry<String, Operation> e : update.changes.entrySet()) {
@@ -165,7 +166,12 @@ public class MemoryDocumentStore impleme
         }
         return oldNode;
     }
-    
+
+    @Override
+    public void create(Collection collection, List<UpdateOp> updateOps) {
+        // TODO Auto-generated method stub
+    }
+
     public String toString() {
         StringBuilder buff = new StringBuilder();
         buff.append("Nodes:\n");
@@ -179,5 +185,4 @@ public class MemoryDocumentStore impleme
         }
         return buff.toString();
     }
-    
-}
+}
\ 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=1446078&r1=1446077&r2=1446078&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
Thu Feb 14 09:18:34 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -33,7 +34,8 @@ import com.mongodb.WriteResult;
 
 public class MongoDocumentStore implements DocumentStore {
 
-    private static final String KEY_PATH = "_id";
+    public static final String KEY_PATH = "_id";
+
     private static final Logger LOG = LoggerFactory.getLogger(MongoDocumentStore.class);
 
     private final DBCollection nodesCollection;
@@ -110,6 +112,44 @@ public class MongoDocumentStore implemen
         return convertFromDBObject(oldNode);
     }
 
+    @Override
+    public void create(Collection collection, List<UpdateOp> updateOps) {
+        DBObject[] inserts = new DBObject[updateOps.size()];
+
+        for (int i = 0; i < updateOps.size(); i++) {
+            inserts[i] = new BasicDBObject();
+            for (Entry<String, Operation> entry : updateOps.get(i).changes.entrySet())
{
+                String k = entry.getKey();
+                Operation op = entry.getValue();
+                switch (op.type) {
+                    case SET: {
+                        inserts[i].put(k, op.value);
+                        break;
+                    }
+                    case INCREMENT: {
+                        inserts[i].put(k, op.value);
+                        break;
+                    }
+                    case ADD_MAP_ENTRY: {
+                        DBObject value = new BasicDBObject(op.subKey.toString(), op.value.toString());
+                        inserts[i].put(k, value);
+                        break;
+                    }
+                    case REMOVE_MAP_ENTRY: {
+                        // TODO
+                        break;
+                    }
+                }
+            }
+        }
+
+        DBCollection dbCollection = getDBCollection(collection);
+        WriteResult writeResult = dbCollection.insert(inserts, WriteConcern.SAFE);
+        if (writeResult.getError() != null) {
+            LOG.error("Batch create failed: {}", writeResult.getError());
+        }
+    }
+
     private void ensureIndex() {
         // the _id field is the primary key, so we don't need to define it
         // the following code is just a template in case we need more indexes

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java?rev=1446078&r1=1446077&r2=1446078&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
Thu Feb 14 09:18:34 2013
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.mongomk.pr
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -82,6 +84,26 @@ public class MongoDocumentStoreTest {
     }
 
     @Test
+    public void batchAdd() throws Exception {
+        dropCollections();
+
+        DocumentStore docStore = openDocumentStore();
+        int nUpdates = 10;
+        List<UpdateOp> updateOps = new ArrayList<UpdateOp>();
+        for (int i = 0; i < nUpdates; i++) {
+            UpdateOp updateOp = new UpdateOp("/node" + i);
+            updateOp.set(MongoDocumentStore.KEY_PATH, "/node" + i);
+            updateOp.addMapEntry("property1", "key1", "value1");
+            updateOp.increment("property2", 1);
+            updateOp.set("property3", "value3");
+            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'};



Mime
View raw message