You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "rishabhdaim (via GitHub)" <gi...@apache.org> on 2026/04/16 09:16:59 UTC

[PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

rishabhdaim opened a new pull request, #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim merged PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4259992159

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [78.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4259953323

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [75.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4259973120

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [75.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4260461526

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [78.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "jsedding (via GitHub)" <gi...@apache.org>.
jsedding commented on code in PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#discussion_r3092410356


##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/AbstractCacheStats.java:
##########
@@ -38,8 +38,8 @@ public abstract class AbstractCacheStats extends AnnotatedStandardMBean implemen
     @NotNull
     private final String name;
 
-    private CacheStats lastSnapshot =
-            new CacheStats(0, 0, 0, 0, 0, 0);
+    private CacheStatsSnapshot lastSnapshot =
+            new CacheStatsSnapshot(0, 0, 0, 0, 0, 0);

Review Comment:
   `lastSnapshot` should be `volatile`. It isn't properly `synchronized` anyway, and synchronization is not nessesary.



##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/AbstractCacheStats.java:
##########


Review Comment:
   This probably should move to the `org.apache.jackrabbit.oak.cache.api`, I think. The class is used by other bundles, right? So it needs to be exported, and probably annotated `@ProviderType`.



##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/AbstractCacheStats.java:
##########
@@ -51,19 +51,17 @@ protected AbstractCacheStats(@NotNull String name) {
     }
 
     /**
-     * Call back invoked to retrieve the most recent {@code CacheStats} instance of the
+     * Call back invoked to retrieve the most recent {@link CacheStatsSnapshot} of the
      * underlying cache.
      */
-    protected abstract CacheStats getCurrentStats();
+    protected abstract CacheStatsSnapshot getCurrentStats();
 
-    private CacheStats stats() {
+    private CacheStatsSnapshot stats() {
         return getCurrentStats().minus(lastSnapshot);
     }

Review Comment:
   Together with the proposal to make `lastSnapshot` volatile, we should make sure to first get the value of `lastSnapshot` before calling `getCurrentStats(). Otherwise it is possible that a `resetStats()` call happens after `getCurrentStats()` and reading `lastSnapshot`, leading to negative values.
   
   ```suggestion
       private CacheStatsSnapshot stats() {
           // get baseline before calling getCurrentStats() to guard against race with resetStats()
           CacheStatsSnapshot baseline = lastSnapshot;
           return getCurrentStats().minus(baseline);
       }
   ```



##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/AbstractCacheStats.java:
##########
@@ -51,19 +51,17 @@ protected AbstractCacheStats(@NotNull String name) {
     }
 
     /**
-     * Call back invoked to retrieve the most recent {@code CacheStats} instance of the
+     * Call back invoked to retrieve the most recent {@link CacheStatsSnapshot} of the
      * underlying cache.
      */
-    protected abstract CacheStats getCurrentStats();
+    protected abstract CacheStatsSnapshot getCurrentStats();
 
-    private CacheStats stats() {
+    private CacheStatsSnapshot stats() {
         return getCurrentStats().minus(lastSnapshot);
     }
 
     @Override
     public synchronized void resetStats() {

Review Comment:
   If we switch `lastSnapshot` to volatile, this no longer needs to be synchronized.
   
   ```suggestion
       public void resetStats() {
   ```



##########
oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java:
##########
@@ -351,17 +351,20 @@ public CacheStatsMBean getTemplateCacheStats() {
         }
 
         @NotNull
-        private static <T> Supplier<CacheStats> accumulateRecordCacheStats(
+        private static <T> Supplier<CacheStatsSnapshot> accumulateRecordCacheStats(
                 final Iterable<RecordCache<T>> caches) {
-            return new Supplier<CacheStats>() {
-                @Override
-                public CacheStats get() {
-                    CacheStats stats = new CacheStats(0, 0, 0, 0, 0, 0);
-                    for (RecordCache<?> cache : caches) {
-                        stats = stats.plus(cache.getStats());
-                    }
-                    return stats;
+            return () -> {
+                long hits = 0, misses = 0, loads = 0, failures = 0, loadTime = 0, evictions = 0;
+                for (RecordCache<?> cache : caches) {
+                    CacheStatsSnapshot s = cache.getStats();
+                    hits += s.hitCount();
+                    misses += s.missCount();
+                    loads += s.loadSuccessCount();
+                    failures += s.loadFailureCount();
+                    loadTime += s.totalLoadTime();
+                    evictions += s.evictionCount();

Review Comment:
   We could consider implementing `CacheStatsSnapshot#plus(CacheStatsSnapshot)`. It already implements `#minus(CacheStatsSnapshot)`.



##########
oak-core-spi/src/test/java/org/apache/jackrabbit/oak/cache/api/CacheStatsTest.java:
##########
@@ -20,7 +20,7 @@
 import org.junit.Test;
 
 /** Tests for {@link CacheStatsSnapshot}. */
-public class CacheStatsSnapshotTest {
+public class CacheStatsTest {

Review Comment:
   The name should be `CacheStatsSnapshotTest`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4259910401

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [61.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4260697412

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [78.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#discussion_r3092814442


##########
oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java:
##########
@@ -351,17 +351,20 @@ public CacheStatsMBean getTemplateCacheStats() {
         }
 
         @NotNull
-        private static <T> Supplier<CacheStats> accumulateRecordCacheStats(
+        private static <T> Supplier<CacheStatsSnapshot> accumulateRecordCacheStats(
                 final Iterable<RecordCache<T>> caches) {
-            return new Supplier<CacheStats>() {
-                @Override
-                public CacheStats get() {
-                    CacheStats stats = new CacheStats(0, 0, 0, 0, 0, 0);
-                    for (RecordCache<?> cache : caches) {
-                        stats = stats.plus(cache.getStats());
-                    }
-                    return stats;
+            return () -> {
+                long hits = 0, misses = 0, loads = 0, failures = 0, loadTime = 0, evictions = 0;
+                for (RecordCache<?> cache : caches) {
+                    CacheStatsSnapshot s = cache.getStats();
+                    hits += s.hitCount();
+                    misses += s.missCount();
+                    loads += s.loadSuccessCount();
+                    failures += s.loadFailureCount();
+                    loadTime += s.totalLoadTime();
+                    evictions += s.evictionCount();

Review Comment:
   added in https://github.com/apache/jackrabbit-oak/pull/2864/commits/809e98790f5821f7245237d050505a510a366796



##########
oak-core-spi/src/test/java/org/apache/jackrabbit/oak/cache/api/CacheStatsTest.java:
##########
@@ -20,7 +20,7 @@
 import org.junit.Test;
 
 /** Tests for {@link CacheStatsSnapshot}. */
-public class CacheStatsSnapshotTest {
+public class CacheStatsTest {

Review Comment:
   added in https://github.com/apache/jackrabbit-oak/pull/2864/commits/809e98790f5821f7245237d050505a510a366796



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "jsedding (via GitHub)" <gi...@apache.org>.
jsedding commented on code in PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#discussion_r3092975273


##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheStatsSnapshot.java:
##########
@@ -89,4 +130,23 @@ public CacheStatsSnapshot minus(@NotNull CacheStatsSnapshot other) {
                 Math.max(0, evictionCount - other.evictionCount)
         );
     }
-}
+
+    /**
+     * Returns the sum of this snapshot and an earlier {@code other}
+     * snapshot, useful for computing total deltas.
+     *
+     * @param other the earlier snapshot to add (must not be null)
+     * @return a new snapshot representing the total
+     */
+    @NotNull
+    public CacheStatsSnapshot plus(@NotNull CacheStatsSnapshot other) {
+        return new CacheStatsSnapshot(
+                Long.sum(hitCount, other.hitCount),
+                Long.sum(missCount, other.missCount),
+                Long.sum(loadSuccessCount, other.loadSuccessCount),
+                Long.sum(loadFailureCount, other.loadFailureCount),
+                Long.sum(totalLoadTime, other.totalLoadTime),
+                Long.sum(evictionCount, other.evictionCount)

Review Comment:
   Very unlikely to happen in practice. But `Math.addExact()` throws if a long overflow happens. `Long.sum)()` quietly overflows.
   
   ```suggestion
                   Math.addExact(hitCount, other.hitCount),
                   Math.addExact(missCount, other.missCount),
                   Math.addExact(loadSuccessCount, other.loadSuccessCount),
                   Math.addExact(loadFailureCount, other.loadFailureCount),
                   Math.addExact(totalLoadTime, other.totalLoadTime),
                   Math.addExact(evictionCount, other.evictionCount)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4279620196

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [78.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#discussion_r3092820187


##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/AbstractCacheStats.java:
##########


Review Comment:
   As discussed offline, we have moved `CacheStats` and `CacheStatsSnapshot` into same package as that of `AbstractCacheStats` in https://github.com/apache/jackrabbit-oak/pull/2864/commits/809e98790f5821f7245237d050505a510a366796



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OAK-12161 : removed guava's cachestats and did the final cleanup [jackrabbit-oak]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2864:
URL: https://github.com/apache/jackrabbit-oak/pull/2864#issuecomment-4259891707

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [75.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864&metric=new_coverage&view=list) (required ≥ 80%)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.apache.jackrabbit%3Ajackrabbit-oak&pullRequest=2864)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org