jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1466782 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/impl/ main/java/org/apache/jackrabbit/mongomk/osgi/ main/java/org/apache/jackrabbit/mongomk/prototype/ main/java/org/apache/jackrabbit/mongomk/util...
Date Thu, 11 Apr 2013 07:47:49 GMT
Author: thomasm
Date: Thu Apr 11 07:47:49 2013
New Revision: 1466782

URL: http://svn.apache.org/r1466782
Log:
OAK-731 The cluster id should be automatically generated (the document cache should only cache
nodes, not clusterNode info)

Added:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoConnection.java
      - copied, changed from r1466488, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
Removed:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/osgi/MongoMicroKernelService.java
    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/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKConcurrentAddTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/multitenancy/MultiTenancyTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/ClusterTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/osgi/MongoMicroKernelService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/osgi/MongoMicroKernelService.java?rev=1466782&r1=1466781&r2=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/osgi/MongoMicroKernelService.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/osgi/MongoMicroKernelService.java
Thu Apr 11 07:47:49 2013
@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mongomk.impl.MongoConnection;
 import org.apache.jackrabbit.mongomk.prototype.MongoMK;
+import org.apache.jackrabbit.mongomk.util.MongoConnection;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -47,7 +47,7 @@ import com.mongodb.DB;
 public class MongoMicroKernelService {
 
     private static final String DEFAULT_HOST = "localhost";
-    private static final int DEFAULT_PORT= 27017;
+    private static final int DEFAULT_PORT = 27017;
     private static final String DEFAULT_DB = "oak";
 
     @Property(value = DEFAULT_HOST)
@@ -88,7 +88,7 @@ public class MongoMicroKernelService {
 
     @Deactivate
     private void deactivate() {
-        if (reg != null){
+        if (reg != null) {
             reg.unregister();
         }
 

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=1466782&r1=1466781&r2=1466782&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 Apr 11 07:47:49 2013
@@ -146,4 +146,13 @@ public interface DocumentStore {
      */
     void dispose();
 
+    /**
+     * Check whether the given document is in the cache.
+     * 
+     * @param collection the collection
+     * @param key the key
+     * @return true if yes
+     */
+    boolean isCached(Collection collection, String key);
+
 }

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=1466782&r1=1466781&r2=1466782&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 Apr 11 07:47:49 2013
@@ -238,4 +238,9 @@ public class MemoryDocumentStore impleme
         // ignore
     }
 
+    @Override
+    public boolean isCached(Collection collection, String key) {
+        return false;
+    }
+
 }
\ 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=1466782&r1=1466781&r2=1466782&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 Apr 11 07:47:49 2013
@@ -60,7 +60,7 @@ public class MongoDocumentStore implemen
      */
     private long timeSum;
     
-    private final Cache<String, CachedDocument> cache;
+    private final Cache<String, CachedDocument> nodesCache;
 
     public MongoDocumentStore(DB db) {
         nodes = db.getCollection(
@@ -77,7 +77,7 @@ public class MongoDocumentStore implemen
         // nodesCollection.ensureIndex(index, options);
 
         // TODO expire entries if the parent was changed
-        cache = CacheBuilder.newBuilder()
+        nodesCache = CacheBuilder.newBuilder()
                 .maximumSize(MongoMK.CACHE_DOCUMENTS)
                 .build();
         
@@ -102,7 +102,7 @@ public class MongoDocumentStore implemen
     
     @Override
     public void invalidateCache() {
-        cache.invalidateAll();
+        nodesCache.invalidateAll();
     }
 
     public Map<String, Object> find(Collection collection, String key) {
@@ -111,10 +111,13 @@ public class MongoDocumentStore implemen
     
     @Override
     public Map<String, Object> find(final Collection collection, final String key,
int maxCacheAge) {
+        if (collection != Collection.NODES) {
+            return findUncached(collection, key);
+        }
         try {
             CachedDocument doc;
             while (true) {
-                doc = cache.get(key, new Callable<CachedDocument>() {
+                doc = nodesCache.get(key, new Callable<CachedDocument>() {
                     @Override
                     public CachedDocument call() throws Exception {
                         Map<String, Object> map = findUncached(collection, key);
@@ -128,7 +131,7 @@ public class MongoDocumentStore implemen
                     break;
                 }
                 // too old: invalidate, try again
-                cache.invalidate(key);
+                nodesCache.invalidate(key);
             }
             return doc.value;
         } catch (ExecutionException e) {
@@ -167,8 +170,10 @@ public class MongoDocumentStore implemen
             for (int i = 0; i < limit && cursor.hasNext(); i++) {
                 DBObject o = cursor.next();
                 Map<String, Object> map = convertFromDBObject(o);
-                String key = (String) map.get(UpdateOp.ID);
-                cache.put(key, new CachedDocument(map));
+                if (collection == Collection.NODES) {
+                    String key = (String) map.get(UpdateOp.ID);
+                    nodesCache.put(key, new CachedDocument(map));
+                }
                 list.add(map);
             }
             return list;
@@ -183,7 +188,9 @@ public class MongoDocumentStore implemen
         DBCollection dbCollection = getDBCollection(collection);
         long start = start();
         try {
-            cache.invalidate(key);
+            if (collection == Collection.NODES) {
+                nodesCache.invalidate(key);
+            }
             WriteResult writeResult = dbCollection.remove(getByKeyQuery(key), WriteConcern.SAFE);
             if (writeResult.getError() != null) {
                 throw new MicroKernelException("Remove failed: " + writeResult.getError());
@@ -261,11 +268,13 @@ public class MongoDocumentStore implemen
             Map<String, Object> map = convertFromDBObject(oldNode);
             
             // cache the new document
-            Map<String, Object> newMap = Utils.newMap();
-            Utils.deepCopyMap(map, newMap);
-            String key = updateOp.getKey();
-            MemoryDocumentStore.applyChanges(newMap, updateOp);
-            cache.put(key, new CachedDocument(newMap));
+            if (collection == Collection.NODES) {
+                Map<String, Object> newMap = Utils.newMap();
+                Utils.deepCopyMap(map, newMap);
+                String key = updateOp.getKey();
+                MemoryDocumentStore.applyChanges(newMap, updateOp);
+                nodesCache.put(key, new CachedDocument(newMap));
+            }
             
             log("createOrUpdate returns ", map);
             return map;
@@ -322,9 +331,11 @@ public class MongoDocumentStore implemen
                 if (writeResult.getError() != null) {
                     return false;
                 }
-                for (Map<String, Object> map : maps) {
-                    String id = (String) map.get(UpdateOp.ID);
-                    cache.put(id, new CachedDocument(map));
+                if (collection == Collection.NODES) {
+                    for (Map<String, Object> map : maps) {
+                        String id = (String) map.get(UpdateOp.ID);
+                        nodesCache.put(id, new CachedDocument(map));
+                    }
                 }
                 return true;
             } catch (MongoException e) {
@@ -396,4 +407,12 @@ public class MongoDocumentStore implemen
         }
     }
 
+    @Override
+    public boolean isCached(Collection collection, String key) {
+        if (collection != Collection.NODES) {
+            return false;
+        }
+        return nodesCache.getIfPresent(key) != null;
+    }
+
 }
\ 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=1466782&r1=1466781&r2=1466782&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 Apr 11 07:47:49 2013
@@ -45,6 +45,7 @@ import org.apache.jackrabbit.mk.json.Jso
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.json.JsopWriter;
 import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
+import org.apache.jackrabbit.mongomk.prototype.DocumentStore.Collection;
 import org.apache.jackrabbit.mongomk.prototype.Node.Children;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.slf4j.Logger;
@@ -1371,4 +1372,12 @@ public class MongoMK implements MicroKer
         return clusterNodeInfo;
     }
 
+    public int getPendingWriteCount() {
+        return unsavedLastRevisions.size();
+    }
+
+    public boolean isCached(String path) {
+        return store.isCached(Collection.NODES, Utils.getIdFromPath(path));
+    }
+
 }

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoConnection.java
(from r1466488, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoConnection.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoConnection.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java&r1=1466488&r2=1466782&rev=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoConnection.java
Thu Apr 11 07:47:49 2013
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl;
+package org.apache.jackrabbit.mongomk.util;
 
 import com.mongodb.DB;
 import com.mongodb.Mongo;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java?rev=1466782&r1=1466781&r2=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
Thu Apr 11 07:47:49 2013
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk;
 
-import org.apache.jackrabbit.mongomk.impl.MongoConnection;
+import org.apache.jackrabbit.mongomk.util.MongoConnection;
 import org.junit.After;
 import org.junit.Assume;
 import org.junit.Before;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKConcurrentAddTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKConcurrentAddTest.java?rev=1466782&r1=1466781&r2=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKConcurrentAddTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKConcurrentAddTest.java
Thu Apr 11 07:47:49 2013
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
 import org.apache.jackrabbit.mongomk.prototype.MongoMK;
+import org.apache.jackrabbit.mongomk.util.MongoConnection;
 import org.junit.After;
 import org.junit.Test;
 

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/multitenancy/MultiTenancyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/multitenancy/MultiTenancyTest.java?rev=1466782&r1=1466781&r2=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/multitenancy/MultiTenancyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/multitenancy/MultiTenancyTest.java
Thu Apr 11 07:47:49 2013
@@ -22,8 +22,8 @@ import static org.junit.Assert.assertTru
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
-import org.apache.jackrabbit.mongomk.impl.MongoConnection;
 import org.apache.jackrabbit.mongomk.prototype.MongoMK;
+import org.apache.jackrabbit.mongomk.util.MongoConnection;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/ClusterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/ClusterTest.java?rev=1466782&r1=1466781&r2=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/ClusterTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/ClusterTest.java
Thu Apr 11 07:47:49 2013
@@ -21,7 +21,8 @@ import static org.junit.Assert.fail;
 
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
-import org.junit.Ignore;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.mongodb.DB;
@@ -119,7 +120,6 @@ public class ClusterTest {
     }
     
     @Test
-    @Ignore
     public void revisionVisibility() throws InterruptedException {
         MongoMK mk1 = createMK(1);
         MongoMK mk2 = createMK(2);
@@ -133,11 +133,22 @@ public class ClusterTest {
         assertEquals("{\"test\":{},\":childNodeCount\":1}", m1h);
         
         m2h = mk2.getNodes("/", mk2.getHeadRevision(), 0, 0, 2, null);
+        
         // not available yet...
         assertEquals("{\":childNodeCount\":0}", m2h);
+        m2h = mk2.getNodes("/test", mk2.getHeadRevision(), 0, 0, 2, null);
         
-        // the delay is 10 ms
-        Thread.sleep(100);
+        // the delay is 10 ms - wait at most 1000 millis
+        for (int i = 0; i < 100; i++) {
+            Thread.sleep(10);
+            if (mk1.getPendingWriteCount() > 0) {
+                continue;
+            }
+            if (mk2.isCached("/")) {
+                continue;
+            }
+            break;
+        }
         
         // so now it should be available
         m2h = mk2.getNodes("/", mk2.getHeadRevision(), 0, 0, 5, null);
@@ -168,12 +179,19 @@ public class ClusterTest {
         mk2.dispose();
     }
 
+    @Before
+    @After
+    public void clear() {
+        if (MONGO_DB) {
+            DB db = MongoUtils.getConnection().getDB();
+            MongoUtils.dropCollections(db);
+        }                    
+    }
 
     private MongoMK createMK(int clusterId) {
         MongoMK.Builder builder = new MongoMK.Builder();
         if (MONGO_DB) {
             DB db = MongoUtils.getConnection().getDB();
-            MongoUtils.dropCollections(db);
             builder.setMongoDB(db);
         } else {
             if (ds == null) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java?rev=1466782&r1=1466781&r2=1466782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
Thu Apr 11 07:47:49 2013
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk.prototype;
 
-import org.apache.jackrabbit.mongomk.impl.MongoConnection;
+import org.apache.jackrabbit.mongomk.util.MongoConnection;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.DB;



Mime
View raw message