jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1445664 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
Date Wed, 13 Feb 2013 15:25:48 GMT
Author: meteatamel
Date: Wed Feb 13 15:25:47 2013
New Revision: 1445664

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

Added an index on path and also added a lots of nodes test

Modified:
    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/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java?rev=1445664&r1=1445663&r2=1445664&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
Wed Feb 13 15:25:47 2013
@@ -40,6 +40,7 @@ public class MongoDocumentStore implemen
 
     public MongoDocumentStore(DB db) {
         nodesCollection = db.getCollection(Collection.NODES.toString());
+        ensureIndex();
     }
 
     @Override
@@ -99,10 +100,26 @@ public class MongoDocumentStore implemen
             update.append("$inc", incUpdates);
         }
 
-        DBObject oldNode = dbCollection.findAndModify(query, null /*fields*/, null /*sort*/,
false /*remove*/, update, false /*returnNew*/, true /*upsert*/);
+//        dbCollection.update(query, update, true /*upsert*/, false /*multi*/,
+//                WriteConcern.SAFE);
+//        return null;
+
+        DBObject oldNode = dbCollection.findAndModify(query, null /*fields*/,
+                null /*sort*/, false /*remove*/, update, false /*returnNew*/,
+                true /*upsert*/);
         return convertFromDBObject(oldNode);
     }
 
+    private void ensureIndex() {
+        DBObject index = new BasicDBObject();
+        index.put(KEY_PATH, 1L);
+
+        DBObject options = new BasicDBObject();
+        options.put("unique", Boolean.TRUE);
+
+        nodesCollection.ensureIndex(index, options);
+    }
+
     private Map<String, Object> convertFromDBObject(DBObject n) {
         Map<String, Object> copy = Utils.newMap();
         synchronized (n) {

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=1445664&r1=1445663&r2=1445664&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
Wed Feb 13 15:25:47 2013
@@ -20,9 +20,13 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
 import org.apache.jackrabbit.mongomk.prototype.DocumentStore.Collection;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class MongoDocumentStoreTest extends AbstractMongoConnectionTest {
@@ -52,4 +56,66 @@ public class MongoDocumentStoreTest exte
         obj = docStore.find(Collection.NODES, "/");
         assertTrue(obj == null);
     }
+
+    @Test
+    @Ignore
+    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 = 2000;
+
+        for (int nThreads = 1; nThreads < 32; nThreads = nThreads * 2) {
+            DocumentStore docStore = new MongoDocumentStore(mongoConnection.getDB());
+
+            System.out.println("Adding and updating " + nNodes + " nodes in each " + nThreads
+ " threads");
+            long start = System.currentTimeMillis();
+
+            ExecutorService executor = Executors.newFixedThreadPool(nThreads);
+            for (int j = 0; j < nThreads; j++) {
+                executor.submit(new AddAndUpdateNodesTask(docStore, "node" + nPrefix[j],
nNodes));
+            }
+            executor.shutdown();
+            executor.awaitTermination(1, TimeUnit.MINUTES);
+
+            long end = System.currentTimeMillis();
+            System.out.println("Done: " + (end - start) + "ms");
+            dropCollections(mongoConnection.getDB());
+        }
+    }
+
+    private static class AddAndUpdateNodesTask implements Runnable {
+
+        private final DocumentStore docStore;
+        private final String nodeName;
+        private final int nNodes;
+
+        public AddAndUpdateNodesTask(DocumentStore docStore, String nodeName, int nNodes)
{
+            this.docStore = docStore;
+            this.nodeName = nodeName;
+            this.nNodes = nNodes;
+        }
+
+        @Override
+        public void run() {
+            addNodes();
+            updateNodes();
+        }
+
+        private void addNodes() {
+            for (int i = 0; i < nNodes; i++) {
+                UpdateOp updateOp = new UpdateOp("/" + nodeName + i);
+                updateOp.addMapEntry("property1", "key1", "value1");
+                updateOp.set("property3", "value3");
+                docStore.createOrUpdate(Collection.NODES, updateOp);
+            }
+        }
+
+        private void updateNodes() {
+            for (int i = 0; i < nNodes; i++) {
+                UpdateOp updateOp = new UpdateOp("/" + nodeName + i);
+                updateOp.addMapEntry("property1", "key2", "value2");
+                updateOp.set("property4", "value4");
+                docStore.createOrUpdate(Collection.NODES, updateOp);
+            }
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message