You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/01/14 09:31:10 UTC

(sling-org-apache-sling-resourceresolver) 01/02: Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter

This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch SLING-12615
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 594e2c4254d71fb7eb26a92690077d9871f14047
Author: Julian Reschke <re...@apache.org>
AuthorDate: Tue Jan 14 10:29:43 2025 +0100

    Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter
---
 .../resourceresolver/impl/mapping/MapEntries.java   | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
index e08cd6b..a20c9c1 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
@@ -98,8 +98,6 @@ public class MapEntries implements
 
     public static final String PROP_VANITY_ORDER = "sling:vanityOrder";
 
-    private static final int VANITY_BLOOM_FILTER_MAX_ENTRIES = 10000000;
-
     /** Key for the global list. */
     private static final String GLOBAL_LIST_KEY = "*";
 
@@ -137,6 +135,8 @@ public class MapEntries implements
 
     private Collection<MapEntry> mapMaps;
 
+    private final VanityPathHandler vanityPathHandler;
+
     private Map <String,List <String>> vanityTargets;
 
     /**
@@ -159,8 +159,6 @@ public class MapEntries implements
     private final AtomicLong vanityPathBloomNegatives;
     private final AtomicLong vanityPathBloomFalsePositives;
 
-    private byte[] vanityBloomFilter;
-
     private AtomicBoolean vanityPathsProcessed = new AtomicBoolean(false);
 
     private final StringInterpolationProvider stringInterpolationProvider;
@@ -197,6 +195,8 @@ public class MapEntries implements
         this.vanityPathBloomNegatives = new AtomicLong(0);
         this.vanityPathBloomFalsePositives = new AtomicLong(0);
 
+        this.vanityPathHandler = new VanityPathHandler(factory);
+
         initializeVanityPaths();
 
         this.metrics = metrics;
@@ -302,7 +302,6 @@ public class MapEntries implements
         this.initializing.lock();
         try {
             if (this.factory.isVanityPathEnabled()) {
-                this.vanityBloomFilter = createVanityBloomFilter();
                 VanityPathInitializer vpi = new VanityPathInitializer(this.factory);
                 if (this.factory.isVanityPathCacheInitInBackground()) {
                     this.log.debug("bg init starting");
@@ -767,7 +766,7 @@ public class MapEntries implements
             }
 
             // init is done - check the bloom filter
-            probablyPresent = BloomFilterUtils.probablyContains(vanityBloomFilter, vanityPath);
+            probablyPresent = this.vanityPathHandler.cacheProbablyContains(vanityPath);
             log.trace("bloom filter lookup for {} -> {}", vanityPath, probablyPresent);
 
             if (!probablyPresent) {
@@ -950,10 +949,6 @@ public class MapEntries implements
 
     // ---------- internal
 
-    private byte[] createVanityBloomFilter() throws IOException {
-        return BloomFilterUtils.createFilter(VANITY_BLOOM_FILTER_MAX_ENTRIES, this.factory.getVanityBloomFilterMaxBytes());
-    }
-
     private boolean isAllVanityPathEntriesCached() {
         return this.factory.getMaxCachedVanityPathEntries() == -1;
     }
@@ -1491,12 +1486,10 @@ public class MapEntries implements
                             vanityCounter.addAndGet(2);
                         }
 
-                        // update bloom filter
-                        BloomFilterUtils.add(vanityBloomFilter, checkPath);
+                        this.vanityPathHandler.cacheWillProbablyContain(checkPath);
                     }
                 } else {
-                    // update bloom filter
-                    BloomFilterUtils.add(vanityBloomFilter, checkPath);
+                    this.vanityPathHandler.cacheWillProbablyContain(checkPath);
                 }
             }
         }