jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1416420 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl: MongoNodeStore.java action/FetchCommitAction.java
Date Mon, 03 Dec 2012 10:30:49 GMT
Author: meteatamel
Date: Mon Dec  3 10:30:48 2012
New Revision: 1416420

URL: http://svn.apache.org/viewvc?rev=1416420&view=rev
Log:
OAK-455 - Caching in MongoMK

Adding basic commit caching. Improves the performance quite a bit as there are many FetchCommitAction
calls in the current MongoMK implementation.

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitAction.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java?rev=1416420&r1=1416419&r2=1416420&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoNodeStore.java
Mon Dec  3 10:30:48 2012
@@ -17,7 +17,10 @@
 package org.apache.jackrabbit.mongomk.impl;
 
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
 
+import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 import org.apache.jackrabbit.mongomk.api.NodeStore;
 import org.apache.jackrabbit.mongomk.api.command.Command;
 import org.apache.jackrabbit.mongomk.api.command.CommandExecutor;
@@ -38,6 +41,8 @@ import org.apache.jackrabbit.mongomk.imp
 import org.apache.jackrabbit.mongomk.impl.model.MongoNode;
 import org.apache.jackrabbit.mongomk.impl.model.MongoSync;
 import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.DB;
@@ -57,9 +62,13 @@ public class MongoNodeStore implements N
     public static final String COLLECTION_NODES = "nodes";
     public static final String COLLECTION_SYNC = "sync";
 
+    private static final Logger LOG = LoggerFactory.getLogger(MongoNodeStore.class);
+
     private final CommandExecutor commandExecutor;
     private final DB db;
 
+    private Map<Long, MongoCommit> commitCache = Collections.synchronizedMap(SimpleLRUCache.<Long,
MongoCommit> newInstance(1000));
+
     /**
      * Constructs a new {@code NodeStoreMongo}.
      *
@@ -173,6 +182,30 @@ public class MongoNodeStore implements N
         return nodeCollection;
     }
 
+    /**
+     * Caches the commit.
+     *
+     * @param commit Commit to cache.
+     */
+    public void cache(Commit commit) {
+        LOG.debug("Adding commit {} to cache", commit.getRevisionId());
+        commitCache.put(commit.getRevisionId(), (MongoCommit)commit);
+    }
+
+    /**
+     * Returns the commit from the cache or null if the commit is not in the cache.
+     *
+     * @param revisionId Commit revision id.
+     * @return Commit from cache or null if commit is not in the cache.
+     */
+    public MongoCommit getFromCache(long revisionId) {
+        MongoCommit commit = commitCache.get(revisionId);
+        if (commit != null) {
+            LOG.debug("Returning commit {} from cache", revisionId);
+        }
+        return commit;
+    }
+
     private void init() {
         initCommitCollection();
         initNodeCollection();

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitAction.java?rev=1416420&r1=1416419&r2=1416420&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitAction.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchCommitAction.java
Mon Dec  3 10:30:48 2012
@@ -48,6 +48,11 @@ public class FetchCommitAction extends B
 
     @Override
     public MongoCommit execute() throws Exception {
+        MongoCommit commit = nodeStore.getFromCache(revisionId);
+        if (commit != null) {
+            return commit;
+        }
+
         DBCollection commitCollection = nodeStore.getCommitCollection();
         DBObject query = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE)
                 .and(MongoCommit.KEY_REVISION_ID).is(revisionId)
@@ -59,6 +64,9 @@ public class FetchCommitAction extends B
         if (dbObject == null) {
             throw new Exception(String.format("Commit with revision %d could not be found",
revisionId));
         }
-        return (MongoCommit)dbObject;
+
+        commit = (MongoCommit)dbObject;
+        nodeStore.cache(commit);
+        return commit;
     }
 }
\ No newline at end of file



Mime
View raw message