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:09 UTC

(sling-org-apache-sling-resourceresolver) branch SLING-12615 created (now e54441c)

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

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


      at e54441c  Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter

This branch includes the following new commits:

     new 594e2c4  Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter
     new e54441c  Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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

Posted by re...@apache.org.
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);
                 }
             }
         }


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

Posted by re...@apache.org.
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 e54441c718816f469bfa52f353beb592f6571a61
Author: Julian Reschke <re...@apache.org>
AuthorDate: Tue Jan 14 10:30:18 2025 +0100

    Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter
---
 .../impl/mapping/VanityPathHandler.java            | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
new file mode 100644
index 0000000..4b6150a
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resourceresolver.impl.mapping;
+
+/**
+ * Handles loading and caching of vanity paths.
+ */
+public class VanityPathHandler {
+
+    private static final int VANITY_BLOOM_FILTER_MAX_ENTRIES = 10000000;
+
+    private volatile MapConfigurationProvider factory;
+
+    private final byte[] bloomFilter;
+
+    /**
+     * @param factory {@link MapConfigurationProvider}
+     */
+    public VanityPathHandler(MapConfigurationProvider factory) {
+        this.factory = factory;
+        this.bloomFilter = BloomFilterUtils.createFilter(VANITY_BLOOM_FILTER_MAX_ENTRIES,
+                this.factory.getVanityBloomFilterMaxBytes());
+    }
+
+    public boolean cacheProbablyContains(String path) {
+        return BloomFilterUtils.probablyContains(this.bloomFilter, path);
+    }
+
+    public void cacheWillProbablyContain(String path) {
+        BloomFilterUtils.add(this.bloomFilter, path);
+    }
+ }