jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1539312 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
Date Wed, 06 Nov 2013 11:23:15 GMT
Author: mreutegg
Date: Wed Nov  6 11:23:14 2013
New Revision: 1539312

URL: http://svn.apache.org/r1539312
Log:
OAK-1080: MongoMK: improved concurrency
- minor improvement in MongoDocumentStore.find()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java?rev=1539312&r1=1539311&r2=1539312&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
Wed Nov  6 11:23:14 2013
@@ -157,6 +157,7 @@ public class MongoDocumentStore implemen
         return find(collection, key, Integer.MAX_VALUE);
     }
     
+    @SuppressWarnings("unchecked")
     @Override
     public <T extends Document> T find(final Collection<T> collection,
                                        final String key,
@@ -164,8 +165,18 @@ public class MongoDocumentStore implemen
         if (collection != Collection.NODES) {
             return findUncached(collection, key);
         }
+        NodeDocument doc;
+        if (maxCacheAge > 0) {
+            // first try without lock
+            doc = nodesCache.getIfPresent(key);
+            if (doc != null) {
+                if (maxCacheAge == Integer.MAX_VALUE ||
+                        System.currentTimeMillis() - doc.getCreated() < maxCacheAge) {
+                    return (T) doc;
+                }
+            }
+        }
         try {
-            NodeDocument doc;
             Lock lock = getAndLock(key);
             try {
                 if (maxCacheAge == 0) {
@@ -197,9 +208,7 @@ public class MongoDocumentStore implemen
             if (doc == NodeDocument.NULL) {
                 return null;
             } else {
-                @SuppressWarnings("unchecked")
-                T result = (T) doc;
-                return result;
+                return (T) doc;
             }
         } catch (ExecutionException e) {
             throw new IllegalStateException("Failed to load document with " + key, e);



Mime
View raw message