Author: mreutegg
Date: Wed Jul 27 14:22:18 2016
New Revision: 1754276

URL: http://svn.apache.org/viewvc?rev=1754276&view=rev
Log:
OAK-4605: Separate persistent cache for diff and local_diff

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1754276&r1=1754275&r2=1754276&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
 Wed Jul 27 14:22:18 2016
@@ -572,6 +572,8 @@ public class DocumentMK {
         private Executor executor;
         private String persistentCacheURI = DEFAULT_PERSISTENT_CACHE_URI;
         private PersistentCache persistentCache;
+        private String journalCacheURI;
+        private PersistentCache journalCache;
         private LeaseFailureHandler leaseFailureHandler;
         private StatisticsProvider statisticsProvider = 
StatisticsProvider.NOOP;
         private BlobStoreStats blobStoreStats;
@@ -712,6 +714,16 @@ public class DocumentMK {
         }
 
         /**
+         * Sets the journal cache option.
+         *
+         * @return this
+         */
+        public Builder setJournalCache(String journalCache) {
+            this.journalCacheURI = journalCache;
+            return this;
+        }
+
+        /**
          * Use the timing document store wrapper.
          *
          * @param timing whether to use the timing wrapper.
@@ -1100,11 +1112,16 @@ public class DocumentMK {
                 ) {
             Set<EvictionListener<K, V>> listeners = new 
CopyOnWriteArraySet<EvictionListener<K,V>>();
             Cache<K, V> cache = buildCache(cacheType.name(), maxWeight, 
listeners);
-            PersistentCache p = getPersistentCache();
+            PersistentCache p = null;
+            if (cacheType == CacheType.DIFF || cacheType == 
CacheType.LOCAL_DIFF) {
+                // use separate journal cache if configured
+                p = getJournalCache();
+            }
+            if (p == null) {
+                // otherwise fall back to single persistent cache
+                p = getPersistentCache();
+            }
             if (p != null) {
-                if (docNodeStore != null) {
-                    docNodeStore.setPersistentCache(p);
-                }
                 cache = p.wrap(docNodeStore, docStore, cache, cacheType, 
statisticsProvider);
                 if (cache instanceof EvictionListener) {
                     listeners.add((EvictionListener<K, V>) cache);
@@ -1132,6 +1149,21 @@ public class DocumentMK {
             return persistentCache;
         }
 
+        PersistentCache getJournalCache() {
+            if (journalCacheURI == null) {
+                return null;
+            }
+            if (journalCache == null) {
+                try {
+                    journalCache = new PersistentCache(journalCacheURI);
+                } catch (Throwable e) {
+                    LOG.warn("Journal cache not available; please disable the 
configuration", e);
+                    throw new IllegalArgumentException(e);
+                }
+            }
+            return journalCache;
+        }
+
         private <K extends CacheValue, V extends CacheValue> Cache<K, V> 
buildCache(
                 String module,
                 long maxWeight,

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1754276&r1=1754275&r2=1754276&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 Wed Jul 27 14:22:18 2016
@@ -403,6 +403,8 @@ public final class DocumentNodeStore
 
     private PersistentCache persistentCache;
 
+    private PersistentCache journalCache;
+
     private final DocumentNodeStoreMBean mbean;
 
     private final boolean readOnlyMode;
@@ -554,11 +556,12 @@ public final class DocumentNodeStore
             leaseUpdateThread.start();
         }
         
-        PersistentCache pc = builder.getPersistentCache();
-        if (!readOnlyMode && pc != null) {
+        persistentCache = builder.getPersistentCache();
+        if (!readOnlyMode && persistentCache != null) {
             DynamicBroadcastConfig broadcastConfig = new 
DocumentBroadcastConfig(this);
-            pc.setBroadcastConfig(broadcastConfig);
+            persistentCache.setBroadcastConfig(broadcastConfig);
         }
+        journalCache = builder.getJournalCache();
 
         this.mbean = createMBean();
         LOG.info("Initialized DocumentNodeStore with clusterNodeId: {} ({})", 
clusterId,
@@ -2696,10 +2699,6 @@ public final class DocumentNodeStore
         return lastRevRecoveryAgent;
     }
 
-    public void setPersistentCache(PersistentCache persistentCache) {
-        this.persistentCache = persistentCache;
-    }
-
     @Override
     public String getInstanceId() {
         return String.valueOf(getClusterId());

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1754276&r1=1754275&r2=1754276&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
 Wed Jul 27 14:22:18 2016
@@ -116,6 +116,7 @@ public class DocumentNodeStoreService {
     private static final int DEFAULT_BLOB_CACHE_SIZE = 16;
     private static final String DEFAULT_DB = "oak";
     private static final String DEFAULT_PERSISTENT_CACHE = "";
+    private static final String DEFAULT_JOURNAL_CACHE = "";
     private static final int DEFAULT_CACHE_SEGMENT_COUNT = 16;
     private static final int DEFAULT_CACHE_STACK_MOVE_DISTANCE = 16;
     private static final String PREFIX = "oak.documentstore.";
@@ -208,6 +209,13 @@ public class DocumentNodeStoreService {
     )
     private static final String PROP_PERSISTENT_CACHE = "persistentCache";
 
+    @Property(value = DEFAULT_JOURNAL_CACHE,
+            label = "Journal Cache Config",
+            description = "Configuration for enabling journal cache. By 
default it is not enabled. Refer to " +
+                    
"http://jackrabbit.apache.org/oak/docs/nodestore/persistent-cache.html for 
various options"
+    )
+    private static final String PROP_JOURNAL_CACHE = "journalCache";
+
     @Property(boolValue = false,
             label = "Custom BlobStore",
             description = "Boolean value indicating that a custom BlobStore is 
to be used. " +
@@ -407,6 +415,7 @@ public class DocumentNodeStoreService {
         int diffCachePercentage = toInteger(prop(PROP_DIFF_CACHE_PERCENTAGE), 
DEFAULT_DIFF_CACHE_PERCENTAGE);
         int blobCacheSize = toInteger(prop(PROP_BLOB_CACHE_SIZE), 
DEFAULT_BLOB_CACHE_SIZE);
         String persistentCache = 
PropertiesUtil.toString(prop(PROP_PERSISTENT_CACHE), DEFAULT_PERSISTENT_CACHE);
+        String journalCache = 
PropertiesUtil.toString(prop(PROP_JOURNAL_CACHE), DEFAULT_JOURNAL_CACHE);
         int cacheSegmentCount = toInteger(prop(PROP_CACHE_SEGMENT_COUNT), 
DEFAULT_CACHE_SEGMENT_COUNT);
         int cacheStackMoveDistance = 
toInteger(prop(PROP_CACHE_STACK_MOVE_DISTANCE), 
DEFAULT_CACHE_STACK_MOVE_DISTANCE);
         DocumentMK.Builder mkBuilder =
@@ -446,6 +455,9 @@ public class DocumentNodeStoreService {
         if (persistentCache != null && persistentCache.length() > 0) {
             mkBuilder.setPersistentCache(persistentCache);
         }
+        if (journalCache != null && journalCache.length() > 0) {
+            mkBuilder.setJournalCache(journalCache);
+        }
 
         boolean wrappingCustomBlobStore = customBlobStore && blobStore 
instanceof BlobStoreWrapper;
 
@@ -476,8 +488,9 @@ public class DocumentNodeStoreService {
                 // Take care around not logging the uri directly as it
                 // might contain passwords
                 log.info("Starting DocumentNodeStore with host={}, db={}, 
cache size (MB)={}, persistentCache={}, " +
-                                "blobCacheSize (MB)={}, 
maxReplicationLagInSecs={}",
-                        mongoURI.getHosts(), db, cacheSize, persistentCache, 
blobCacheSize, maxReplicationLagInSecs);
+                                "journalCache={}, blobCacheSize (MB)={}, 
maxReplicationLagInSecs={}",
+                        mongoURI.getHosts(), db, cacheSize, persistentCache,
+                        journalCache, blobCacheSize, maxReplicationLagInSecs);
                 log.info("Mongo Connection details {}", 
MongoConnection.toString(mongoURI.getOptions()));
             }
 


Reply via email to