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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to