Author: tomekr
Date: Mon Nov  7 08:41:54 2016
New Revision: 1768448

URL: http://svn.apache.org/viewvc?rev=1768448&view=rev
Log:
OAK-5071: Persistent cache: use the asynchronous mode by default

Don't use async cache for DIFF cache.

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java?rev=1768448&r1=1768447&r2=1768448&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
 Mon Nov  7 08:41:54 2016
@@ -66,6 +66,7 @@ class NodeCache<K, V> implements Cache<K
     private final DataType valueType;
     private final CacheMetadata<K> memCacheMetadata;
     private final DocumentNodeStore nodeStore;
+    private final boolean async;
     CacheWriteQueue<K, V> writeQueue;
 
     NodeCache(
@@ -75,17 +76,19 @@ 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.nodeStore = docNodeStore;
+        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 {
@@ -200,7 +203,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);
@@ -223,7 +226,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);
@@ -234,7 +237,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);
@@ -299,7 +302,7 @@ class NodeCache<K, V> implements Cache<K
             memCacheMetadata.put(key);
         }
         stats.markRecvBroadcast();
-        if (!cache.isAsyncCache()) {
+        if (!async) {
             write(key, value);
         }
     }
@@ -309,7 +312,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()) {

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java?rev=1768448&r1=1768447&r2=1768448&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
 Mon Nov  7 08:41:54 2016
@@ -68,6 +68,7 @@ public class PersistentCache implements
     private boolean compactOnClose;
     private boolean compress = true;
     private boolean asyncCache = true;
+    private boolean asyncDiffCache = false;
     private HashMap<CacheType, GenerationCache> caches = 
             new HashMap<CacheType, GenerationCache>();
     
@@ -144,10 +145,10 @@ public class PersistentCache implements
                 manualCommit = true;
             } else if (p.startsWith("broadcast=")) {
                 broadcast = p.split("=")[1];               
-            } else if (p.equals("+async")) {
-                asyncCache = true;
             } else if (p.equals("-async")) {
                 asyncCache = false;
+            } else if (p.equals("+asyncDiff")) {
+                asyncDiffCache = true;
             }
         }
         this.directory = dir;
@@ -402,6 +403,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 +413,7 @@ public class PersistentCache implements
             break;
         case DIFF:
             wrap = cacheDiff;
+            async = asyncDiffCache;
             break;
         case LOCAL_DIFF:
             wrap = cacheLocalDiff;
@@ -431,7 +434,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 +517,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) {

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java?rev=1768448&r1=1768447&r2=1768448&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
 Mon Nov  7 08:41:54 2016
@@ -64,7 +64,7 @@ public class AsyncQueueTest {
     @Before
     public void setup() throws IOException {
         FileUtils.deleteDirectory(new File("target/cacheTest"));
-        pCache = new PersistentCache("target/cacheTest,+async");
+        pCache = new PersistentCache("target/cacheTest");
         final AtomicReference<NodeCache<PathRev, StringValue>> nodeCacheRef = 
new AtomicReference<NodeCache<PathRev, StringValue>>();
         CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev, 
StringValue>().maximumSize(1).evictionCallback(new 
CacheLIRS.EvictionCallback<PathRev, StringValue>() {
             @Override

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java?rev=1768448&r1=1768447&r2=1768448&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
 Mon Nov  7 08:41:54 2016
@@ -124,7 +124,7 @@ public class NodeCacheTest {
                 .setStatisticsProvider(statsProvider);
 
         if (asyncCache){
-            builder.setPersistentCache("target/persistentCache,time,+async");
+            builder.setPersistentCache("target/persistentCache,time");
         }else {
             builder.setPersistentCache("target/persistentCache,time,-async");
         }


Reply via email to