Author: tomekr
Date: Thu Apr 28 13:17:26 2016
New Revision: 1741422

URL: http://svn.apache.org/viewvc?rev=1741422&view=rev
Log:
OAK-4112: Replace the query exclusive lock with a cache tracker

Accept fromKey/toKey parameters in the registerTracker. Use a smaller
bloom filter if the query is scoped and a bigger one if
toKey == MAX_ID_VALUE.

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTracker.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTracker.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTracker.java?rev=1741422&r1=1741421&r2=1741422&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTracker.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTracker.java
 Thu Apr 28 13:17:26 2016
@@ -25,16 +25,20 @@ import java.util.List;
 
 public class CacheChangesTracker {
 
+    static final int ENTRIES_SCOPED = 1000;
+
+    static final int ENTRIES_OPEN = 10000;
+
     private final List<CacheChangesTracker> changeTrackers;
 
     private final Predicate<String> keyFilter;
 
     private final LazyBloomFilter lazyBloomFilter;
 
-    CacheChangesTracker(Predicate<String> keyFilter, List<CacheChangesTracker> 
changeTrackers) {
+    CacheChangesTracker(Predicate<String> keyFilter, List<CacheChangesTracker> 
changeTrackers, int bloomFilterSize) {
         this.changeTrackers = changeTrackers;
         this.keyFilter = keyFilter;
-        this.lazyBloomFilter = new LazyBloomFilter();
+        this.lazyBloomFilter = new LazyBloomFilter(bloomFilterSize);
         changeTrackers.add(this);
     }
 
@@ -62,10 +66,14 @@ public class CacheChangesTracker {
 
         private static final double FPP = 0.01d;
 
-        private static final int ENTRIES = 1000;
+        private final int entries;
 
         private volatile BloomFilter<String> filter;
 
+        public LazyBloomFilter(int entries) {
+            this.entries = entries;
+        }
+
         public synchronized void put(String entry) {
             getFilter().put(entry);
         }
@@ -89,7 +97,7 @@ public class CacheChangesTracker {
                     public void funnel(String from, PrimitiveSink into) {
                         into.putUnencodedChars(from);
                     }
-                }, ENTRIES, FPP);
+                }, entries, FPP);
             }
             return filter;
         }

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java?rev=1741422&r1=1741421&r2=1741422&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
 Thu Apr 28 13:17:26 2016
@@ -353,16 +353,23 @@ public class NodeDocumentCache implement
      * Registers a new CacheChangesTracker that records all puts and
      * invalidations related to children of the given parent.
      *
-     * @param parentId children of this parent will be tracked
+     * @param fromKey only keys larger than this key will be tracked
+     * @param toKey only keys smaller than this key will be tracked
      * @return new tracker
      */
-    public CacheChangesTracker registerTracker(final String parentId) {
+    public CacheChangesTracker registerTracker(final String fromKey, final 
String toKey) {
+        final int bloomFilterSize;
+        if (toKey.equals(NodeDocument.MAX_ID_VALUE)) {
+            bloomFilterSize = CacheChangesTracker.ENTRIES_OPEN;
+        } else {
+            bloomFilterSize = CacheChangesTracker.ENTRIES_SCOPED;
+        }
         return new CacheChangesTracker(new Predicate<String>() {
             @Override
             public boolean apply(@Nullable String input) {
-                return input != null && 
parentId.equals(Utils.getParentId(input));
+                return input != null && fromKey.compareTo(input) < 0 && 
toKey.compareTo(input) > 0;
             }
-        }, changeTrackers);
+        }, changeTrackers, bloomFilterSize);
     }
 
    /**

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1741422&r1=1741421&r2=1741422&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
 Thu Apr 28 13:17:26 2016
@@ -562,7 +562,7 @@ public class MongoDocumentStore implemen
         int resultSize = 0;
         CacheChangesTracker cacheChangesTracker = null;
         if (parentId != null && collection == Collection.NODES) {
-            cacheChangesTracker = nodesCache.registerTracker(parentId);
+            cacheChangesTracker = nodesCache.registerTracker(fromKey, toKey);
         }
         try {
             DBCursor cursor = dbCollection.find(query).sort(BY_ID_ASC);

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java?rev=1741422&r1=1741421&r2=1741422&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
 Thu Apr 28 13:17:26 2016
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.oak.plugins
 import 
org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks;
 import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -38,6 +39,8 @@ import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 
+import static 
org.apache.jackrabbit.oak.plugins.document.util.Utils.getKeyLowerLimit;
+import static 
org.apache.jackrabbit.oak.plugins.document.util.Utils.getKeyUpperLimit;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -58,7 +61,7 @@ public class CacheChangesTrackerTest {
             public boolean apply(@Nullable String input) {
                 return !"ignored".equals(input);
             }
-        }, list);
+        }, list, 100);
 
         assertFalse(tracker.mightBeenAffected("xyz"));
         assertFalse(tracker.mightBeenAffected("abc"));
@@ -80,7 +83,7 @@ public class CacheChangesTrackerTest {
     @Test
     public void testRegisterChildrenTracker() {
         NodeDocumentCache cache = createCache();
-        CacheChangesTracker tracker = cache.registerTracker("1:/parent");
+        CacheChangesTracker tracker = 
cache.registerTracker(getKeyLowerLimit("/parent"), getKeyUpperLimit("/parent"));
 
         assertFalse(tracker.mightBeenAffected("2:/parent/xyz"));
         assertFalse(tracker.mightBeenAffected("2:/parent/abc"));
@@ -103,7 +106,7 @@ public class CacheChangesTrackerTest {
     @Test
     public void testGetLoaderAffectsTracker() throws ExecutionException {
         NodeDocumentCache cache = createCache();
-        CacheChangesTracker tracker = cache.registerTracker("1:/parent");
+        CacheChangesTracker tracker = 
cache.registerTracker(getKeyLowerLimit("/parent"), getKeyUpperLimit("/parent"));
 
         assertFalse(tracker.mightBeenAffected("2:/parent/xyz"));
 


Reply via email to