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 15:23:19 UTC
(sling-org-apache-sling-resourceresolver) branch SLING-12615 updated: Resource Resolver: refactor MapEntries - extract vanity path handling - vanityResourcesOnStartup metrics
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
The following commit(s) were added to refs/heads/SLING-12615 by this push:
new 902413d Resource Resolver: refactor MapEntries - extract vanity path handling - vanityResourcesOnStartup metrics
902413d is described below
commit 902413d9fcd683946777f34d26c78598e7a4de73
Author: Julian Reschke <re...@apache.org>
AuthorDate: Tue Jan 14 16:23:11 2025 +0100
Resource Resolver: refactor MapEntries - extract vanity path handling - vanityResourcesOnStartup metrics
---
.../resourceresolver/impl/mapping/MapEntries.java | 19 ++++++++++---------
.../impl/mapping/VanityPathHandler.java | 12 +++++++++++-
2 files changed, 21 insertions(+), 10 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 42c3299..546950f 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
@@ -150,7 +150,6 @@ public class MapEntries implements
private final ReentrantLock initializing = new ReentrantLock();
- private final AtomicLong vanityResourcesOnStartup;
private final AtomicLong vanityPathLookups;
private final AtomicLong vanityPathBloomNegatives;
private final AtomicLong vanityPathBloomFalsePositives;
@@ -185,7 +184,6 @@ public class MapEntries implements
this.registration = registerResourceChangeListener(bundleContext);
- this.vanityResourcesOnStartup = new AtomicLong(0);
this.vanityPathLookups = new AtomicLong(0);
this.vanityPathBloomNegatives = new AtomicLong(0);
this.vanityPathBloomFalsePositives = new AtomicLong(0);
@@ -197,7 +195,7 @@ public class MapEntries implements
this.metrics = metrics;
if (metrics.isPresent()) {
this.metrics.get().setNumberOfVanityPathsSupplier(vanityPathHandler::getTotalCount);
- this.metrics.get().setNumberOfResourcesWithVanityPathsOnStartupSupplier(vanityResourcesOnStartup::get);
+ this.metrics.get().setNumberOfResourcesWithVanityPathsOnStartupSupplier(vanityPathHandler::getResourceCountOnStartup);
this.metrics.get().setNumberOfVanityPathLookupsSupplier(vanityPathLookups::get);
this.metrics.get().setNumberOfVanityPathBloomNegativesSupplier(vanityPathBloomNegatives::get);
this.metrics.get().setNumberOfVanityPathBloomFalsePositivesSupplier(vanityPathBloomFalsePositives::get);
@@ -297,7 +295,7 @@ public class MapEntries implements
this.initializing.lock();
try {
if (this.factory.isVanityPathEnabled()) {
- VanityPathInitializer vpi = new VanityPathInitializer(this.factory);
+ VanityPathInitializer vpi = new VanityPathInitializer(this.factory, this.vanityPathHandler);
if (this.factory.isVanityPathCacheInitInBackground()) {
this.log.debug("bg init starting");
Thread vpinit = new Thread(vpi, "VanityPathInitializer");
@@ -315,10 +313,13 @@ public class MapEntries implements
private int SIZELIMIT = 10000;
- private MapConfigurationProvider factory;
+ private final MapConfigurationProvider factory;
- public VanityPathInitializer(MapConfigurationProvider factory) {
+ private final VanityPathHandler vanityPathHandler;
+
+ public VanityPathInitializer(MapConfigurationProvider factory, VanityPathHandler vanityPathHandler) {
this.factory = factory;
+ this.vanityPathHandler = vanityPathHandler;
}
@Override
@@ -376,11 +377,11 @@ public class MapEntries implements
drainQueue(resourceChangeQueue);
long initElapsed = System.nanoTime() - initStart;
- long resourcesPerSecond = (vanityResourcesOnStartup.get() * TimeUnit.SECONDS.toNanos(1) / (initElapsed == 0 ? 1 : initElapsed));
+ long resourcesPerSecond = (this.vanityPathHandler.getResourceCountOnStartup() * TimeUnit.SECONDS.toNanos(1) / (initElapsed == 0 ? 1 : initElapsed));
log.info(
"vanity path initialization - completed, processed {} resources with sling:vanityPath properties in {}ms (~{} resource/s)",
- vanityResourcesOnStartup.get(), TimeUnit.NANOSECONDS.toMillis(initElapsed), resourcesPerSecond);
+ this.vanityPathHandler.getResourceCountOnStartup(), TimeUnit.NANOSECONDS.toMillis(initElapsed), resourcesPerSecond);
} catch (LoginException ex) {
log.error("Vanity path init failed", ex);
} finally {
@@ -1368,7 +1369,7 @@ public class MapEntries implements
}
}
- this.vanityResourcesOnStartup.set(count);
+ this.vanityPathHandler.setResourceCountOnStartup(count);
return targetPaths;
}
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
index eeca266..5324b16 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
@@ -46,6 +46,7 @@ public class VanityPathHandler {
private static final String JCR_SYSTEM_PREFIX = "/jcr:system/";
private final AtomicLong vanityCounter;
+ private final AtomicLong vanityResourcesOnStartup;
private static final String ANY_SCHEME_HOST = "[^/]+/[^/]+";
@@ -57,6 +58,7 @@ public class VanityPathHandler {
this.bloomFilter = BloomFilterUtils.createFilter(VANITY_BLOOM_FILTER_MAX_ENTRIES,
this.factory.getVanityBloomFilterMaxBytes());
this.vanityCounter = new AtomicLong(0);
+ this.vanityResourcesOnStartup = new AtomicLong(0);
}
/**
@@ -163,4 +165,12 @@ public class VanityPathHandler {
long addToTotalCountAndGet(long delta) {
return vanityCounter.addAndGet(delta);
}
- }
+
+ Long getResourceCountOnStartup() {
+ return vanityResourcesOnStartup.get();
+ }
+
+ void setResourceCountOnStartup(long value) {
+ vanityResourcesOnStartup.set(value);
+ }
+}