jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1446093 - 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:59:57 GMT
Author: thomasm
Date: Thu Feb 14 09:59:57 2013
New Revision: 1446093

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

Added:
    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
    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

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=1446093&r1=1446092&r2=1446093&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:59:57 2013
@@ -30,7 +30,9 @@ public interface DocumentStore {
 
     void remove(Collection collection, String key);
 
-    Map<String, Object> createOrUpdate(Collection collection, UpdateOp update);
+    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=1446093&r1=1446092&r2=1446093&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:59:57 2013
@@ -185,4 +185,9 @@ public class MemoryDocumentStore impleme
         }
         return buff.toString();
     }
+
+    @Override
+    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=1446093&r1=1446092&r2=1446093&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:59:57 2013
@@ -189,4 +189,10 @@ public class MongoDocumentStore implemen
     private static DBObject getByPathQuery(String path) {
         return QueryBuilder.start(KEY_PATH).is(path).get();
     }
+    
+    @Override
+    public void dispose() {
+        nodesCollection.getDB().getMongo().close();
+    }
+
 }
\ No newline at end of file

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=1446093&r1=1446092&r2=1446093&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
Thu Feb 14 09:59:57 2013
@@ -19,12 +19,14 @@ package org.apache.jackrabbit.mongomk.pr
 import java.io.InputStream;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
 
 public class MongoMK implements MicroKernel {
 
@@ -61,27 +63,80 @@ public class MongoMK implements MicroKer
      */
     private static final int trustedRevisionAge = Integer.MAX_VALUE;
 
+    protected static final long ASYNC_DELAY = 1000;
+
     /**
      * The set of known valid revision.
      * The key is the revision id, the value is 1 (because a cache can't be a set).
      */
     private final Map<String, Long> revCache = new Cache<String, Long>(1024);
+    
+    /**
+     * The last known head revision. This is the last-known revision.
+     */
+    private String headRevision;
+    
+    AtomicBoolean disposed = new AtomicBoolean();
+    
+    private Thread backgroundThread;
+
+    /**
+     * Create a new in-memory MongoMK to be used for testing.
+     */
+    public MongoMK() {
+        this(new MemoryDocumentStore(), new MemoryBlobStore(), 0);
+    }
 
     /**
      * Create a new MongoMK.
      *
      * @param store the store (might be shared)
+     * @param blobStore the blob store to use
      * @param clusterId the cluster id (must be unique)
      */
     public MongoMK(DocumentStore store, BlobStore blobStore, int clusterId) {
         this.store = store;
         this.blobStore = blobStore;
         this.clusterId = clusterId;
+        backgroundThread = new Thread(new Runnable() {
+            public void run() {
+                while (!disposed.get()) {
+                    synchronized (this) {
+                        try {
+                            wait(ASYNC_DELAY);
+                        } catch (InterruptedException e) {
+                            // ignore
+                        }
+                    }
+                    runBackgroundOperations();
+                }
+            }
+        }, "MongoMK background thread");
+        backgroundThread.setDaemon(true);
+        backgroundThread.start();
+    }
+    
+    void runBackgroundOperations() {
+        // to be implemented
     }
 
     String getNewRevision() {
         return Utils.createRevision(clusterId);
     }
+    
+    public void dispose() {
+        if (!disposed.getAndSet(true)) {
+            synchronized (backgroundThread) {
+                backgroundThread.notifyAll();
+            }
+            try {
+                backgroundThread.join();
+            } catch (InterruptedException e) {
+                // ignore
+            }
+            store.dispose();
+        }
+    }
 
     /**
      * Get the node for the given path and revision. The returned object might
@@ -102,6 +157,11 @@ public class MongoMK implements MicroKer
         }
         return node;
     }
+    
+    private static String getDocumentId(String path) {
+        int depth = Utils.pathDepth(path);
+        return depth + ":" + path;
+    }
 
     /**
      * Try to add a node.
@@ -113,17 +173,12 @@ public class MongoMK implements MicroKer
     public void addNode(String rev, String commitRoot, Node n) {
         UpdateOp node = new UpdateOp(n.path);
         int depth = Utils.pathDepth(n.path);
-        node.set("_path", n.path);
+        node.set("_id", getDocumentId(n.path));
         node.set("_pathDepth", depth);
         int commitDepth = depth - Utils.pathDepth(commitRoot);
         node.addMapEntry("_commitDepth", rev, commitDepth);
 
-        // the affected (direct) children of this revision
-        node.addMapEntry("_affectedChildren", rev, "");
-
         node.increment("_changeCount", 1L);
-//        setCommitRoot(path);
-
 
         for (String p : n.properties.keySet()) {
             node.addMapEntry(p, rev, n.properties.get(p));
@@ -150,8 +205,7 @@ public class MongoMK implements MicroKer
 
     @Override
     public String getHeadRevision() throws MicroKernelException {
-        // TODO Auto-generated method stub
-        return null;
+        return headRevision;
     }
 
     @Override

Added: 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=1446093&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
(added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
Thu Feb 14 09:59:57 2013
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mongomk.prototype;
+
+import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
+import org.junit.Test;
+
+public class SimpleTest {
+
+    @Test
+    public void test() {
+        MongoMK mk = new MongoMK(new MemoryDocumentStore(), new MemoryBlobStore(), 0);
+        mk.dispose();
+    }
+}



Mime
View raw message