Author: tomekr
Date: Wed Nov 9 09:47:08 2016
New Revision: 1768897
URL: http://svn.apache.org/viewvc?rev=1768897&view=rev
Log:
OAK-5071: Persistent cache: don't use the async mode for DIFF cache
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java?rev=1768897&r1=1768896&r2=1768897&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
(original)
+++
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
Wed Nov 9 09:47:08 2016
@@ -64,6 +64,7 @@ class NodeCache<K, V> implements Cache<K
private final DataType keyType;
private final DataType valueType;
private final CacheMetadata<K> memCacheMetadata;
+ private final boolean async;
CacheWriteQueue<K, V> writeQueue;
NodeCache(
@@ -73,16 +74,18 @@ class NodeCache<K, V> implements Cache<K
DocumentStore docStore,
CacheType type,
CacheActionDispatcher dispatcher,
- StatisticsProvider statisticsProvider) {
+ StatisticsProvider statisticsProvider,
+ boolean async) {
this.cache = cache;
this.memCache = memCache;
this.type = type;
+ this.async = async;
PersistentCache.LOG.info("wrapping map " + this.type);
map = new MultiGenerationMap<K, V>();
keyType = new KeyDataType(type);
valueType = new ValueDataType(docNodeStore, docStore, type);
this.memCacheMetadata = new CacheMetadata<K>();
- if (cache.isAsyncCache()) {
+ if (async) {
this.writeQueue = new CacheWriteQueue<K, V>(dispatcher, cache,
map);
LOG.info("The persistent cache {} writes will be asynchronous",
type);
} else {
@@ -194,7 +197,7 @@ class NodeCache<K, V> implements Cache<K
value = memCache.get(key, valueLoader);
memCacheMetadata.increment(key);
ctx.stop();
- if (!cache.isAsyncCache()) {
+ if (!async) {
write((K) key, value);
}
broadcast(key, value);
@@ -217,7 +220,7 @@ class NodeCache<K, V> implements Cache<K
public void put(K key, V value) {
memCache.put(key, value);
memCacheMetadata.put(key);
- if (!cache.isAsyncCache()) {
+ if (!async) {
write((K) key, value);
}
broadcast(key, value);
@@ -228,7 +231,7 @@ class NodeCache<K, V> implements Cache<K
public void invalidate(Object key) {
memCache.invalidate(key);
memCacheMetadata.remove(key);
- if (cache.isAsyncCache()) {
+ if (async) {
writeQueue.addInvalidate(singleton((K) key));
} else {
write((K) key, null);
@@ -293,7 +296,7 @@ class NodeCache<K, V> implements Cache<K
memCacheMetadata.put(key);
}
stats.markRecvBroadcast();
- if (!cache.isAsyncCache()) {
+ if (!async) {
write(key, value);
}
}
@@ -303,7 +306,7 @@ class NodeCache<K, V> implements Cache<K
*/
@Override
public void evicted(K key, V value, RemovalCause cause) {
- if (cache.isAsyncCache() && EVICTION_CAUSES.contains(cause) && value
!= null) {
+ if (async && EVICTION_CAUSES.contains(cause) && value != null) {
CacheMetadata.MetadataEntry metadata =
memCacheMetadata.remove(key);
boolean qualifiesToPersist = true;
if (metadata != null && metadata.isReadFromPersistentCache()) {
@@ -332,4 +335,4 @@ class NodeCache<K, V> implements Cache<K
public PersistentCacheStats getPersistentCacheStats() {
return stats;
}
-}
\ No newline at end of file
+}
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java?rev=1768897&r1=1768896&r2=1768897&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
(original)
+++
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
Wed Nov 9 09:47:08 2016
@@ -74,6 +74,7 @@ public class PersistentCache implements
private boolean compactOnClose;
private boolean compress = true;
private boolean asyncCache = ASYNC_CACHE;
+ private boolean asyncDiffCache = false;
private HashMap<CacheType, GenerationCache> caches =
new HashMap<CacheType, GenerationCache>();
@@ -151,6 +152,8 @@ public class PersistentCache implements
asyncCache = true;
} else if (p.equals("-async")) {
asyncCache = false;
+ } else if (p.equals("+asyncDiff")) {
+ asyncDiffCache = true;
}
}
this.directory = dir;
@@ -402,6 +405,7 @@ public class PersistentCache implements
Cache<K, V> base, CacheType type,
StatisticsProvider statisticsProvider) {
boolean wrap;
+ boolean async = asyncCache;
switch (type) {
case NODE:
wrap = cacheNodes;
@@ -411,6 +415,7 @@ public class PersistentCache implements
break;
case DIFF:
wrap = cacheDiff;
+ async = asyncDiffCache;
break;
case LOCAL_DIFF:
wrap = cacheLocalDiff;
@@ -431,7 +436,7 @@ public class PersistentCache implements
if (wrap) {
NodeCache<K, V> c = new NodeCache<K, V>(this,
base, docNodeStore, docStore,
- type, writeDispatcher, statisticsProvider);
+ type, writeDispatcher, statisticsProvider, async);
initGenerationCache(c);
return c;
}
@@ -514,10 +519,6 @@ public class PersistentCache implements
return exceptionCount;
}
- public boolean isAsyncCache() {
- return asyncCache;
- }
-
void broadcast(CacheType type, Function<WriteBuffer, Void> writer) {
Broadcaster b = broadcaster;
if (b == null) {