Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java (revision 1754133) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java (working copy) @@ -572,6 +572,8 @@ 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 @@ } /** + * 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 @@ ) { Set> listeners = new CopyOnWriteArraySet>(); Cache 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) cache); @@ -1132,6 +1149,21 @@ 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 Cache buildCache( String module, long maxWeight, Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (revision 1754133) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (working copy) @@ -403,6 +403,8 @@ private PersistentCache persistentCache; + private PersistentCache journalCache; + private final DocumentNodeStoreMBean mbean; private final boolean readOnlyMode; @@ -554,11 +556,12 @@ 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 @@ return lastRevRecoveryAgent; } - public void setPersistentCache(PersistentCache persistentCache) { - this.persistentCache = persistentCache; - } - @Override public String getInstanceId() { return String.valueOf(getClusterId()); Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (revision 1754133) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (working copy) @@ -116,6 +116,7 @@ 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 @@ ) 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 @@ 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 @@ 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 @@ // 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())); }