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

daim pushed a commit to branch OAK-11771
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 4f2b7e361847b4985cc9fc1194bf6a74386dff57
Author: Rishabh Kumar <[email protected]>
AuthorDate: Mon Jul 7 14:54:27 2025 +0530

    OAK-11771 : removed usage of AtomicDouble
---
 .../plugins/document/mongo/MongoDocumentStore.java |  4 ++--
 ...MongoDocumentStoreThrottlingMetricsUpdater.java | 12 +++++------
 .../document/mongo/MongoThrottlerFactory.java      | 11 +++++-----
 .../document/mongo/MongoThrottlerFactoryTest.java  | 25 +++++++++++-----------
 4 files changed, 27 insertions(+), 25 deletions(-)

diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
index 8d713e2547..8ef0640e7e 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
@@ -36,6 +36,7 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -43,7 +44,6 @@ import java.util.stream.StreamSupport;
 
 import org.apache.commons.io.IOUtils;
 import com.mongodb.client.model.IndexOptions;
-import org.apache.jackrabbit.guava.common.util.concurrent.AtomicDouble;
 import com.mongodb.Block;
 import com.mongodb.DBObject;
 import com.mongodb.MongoBulkWriteException;
@@ -368,7 +368,7 @@ public class MongoDocumentStore implements DocumentStore {
 
             if (ol.isPresent()) {
                 // oplog window based on current oplog filling rate
-                final AtomicDouble oplogWindow = new AtomicDouble(MAX_VALUE);
+                final AtomicReference<Double> oplogWindow = new 
AtomicReference<>((double) MAX_VALUE);
                 throttler = exponentialThrottler(DEFAULT_THROTTLING_THRESHOLD, 
oplogWindow, DEFAULT_THROTTLING_TIME_MS);
                 throttlingMetricsUpdater = new 
MongoDocumentStoreThrottlingMetricsUpdater(localDb, oplogWindow);
                 throttlingMetricsUpdater.scheduleUpdateMetrics();
diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreThrottlingMetricsUpdater.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreThrottlingMetricsUpdater.java
index 8729cb69f4..5c48a57ae6 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreThrottlingMetricsUpdater.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreThrottlingMetricsUpdater.java
@@ -19,7 +19,6 @@
 package org.apache.jackrabbit.oak.plugins.document.mongo;
 
 import org.apache.commons.math3.util.Precision;
-import org.apache.jackrabbit.guava.common.util.concurrent.AtomicDouble;
 import com.mongodb.client.MongoCollection;
 import com.mongodb.client.MongoDatabase;
 import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
@@ -33,6 +32,7 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.util.Objects;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
 
 import static java.lang.Integer.MAX_VALUE;
 import static java.lang.Math.abs;
@@ -55,10 +55,10 @@ public class MongoDocumentStoreThrottlingMetricsUpdater 
implements Closeable {
     private static final String OPLOG_RS = "oplog.rs";
     public static final String SIZE = "size";
     private final ScheduledExecutorService throttlingMetricsExecutor;
-    private final AtomicDouble oplogWindow;
+    private final AtomicReference<Double> oplogWindow;
     private final MongoDatabase localDb;
 
-    public MongoDocumentStoreThrottlingMetricsUpdater(final @NotNull 
MongoDatabase localDb, final @NotNull AtomicDouble oplogWindow) {
+    public MongoDocumentStoreThrottlingMetricsUpdater(final @NotNull 
MongoDatabase localDb, final @NotNull AtomicReference<Double> oplogWindow) {
         this.throttlingMetricsExecutor = newSingleThreadScheduledExecutor();
         this.oplogWindow = oplogWindow;
         this.localDb = localDb;
@@ -69,7 +69,7 @@ public class MongoDocumentStoreThrottlingMetricsUpdater 
implements Closeable {
             Document document = localDb.runCommand(new Document("collStats", 
OPLOG_RS));
             if (!document.containsKey(MAX_SIZE) || 
!document.containsKey(SIZE)) {
                 LOG.warn("Could not get stats for local.{}  collection. 
collstats returned: {}.", OPLOG_RS, document);
-                oplogWindow.set(MAX_VALUE);
+                oplogWindow.set((double) MAX_VALUE);
             } else {
                 int maxSize = document.getInteger(MAX_SIZE);
                 double maxSizeGb = (double) maxSize / (1024 * 1024 * 1024);
@@ -81,11 +81,11 @@ public class MongoDocumentStoreThrottlingMetricsUpdater 
implements Closeable {
 
                 if (isNull(first) || isNull(last)) {
                     LOG.warn("Objects not found in local.oplog.rs -- is this a 
new and empty db instance?");
-                    oplogWindow.set(MAX_VALUE);
+                    oplogWindow.set((double) MAX_VALUE);
                 } else {
                     if (!first.containsKey(TS_TIME) || 
!last.containsKey(TS_TIME)) {
                         LOG.warn("ts element not found in oplog objects");
-                        oplogWindow.set(MAX_VALUE);
+                        oplogWindow.set((double) MAX_VALUE);
                     } else {
                         oplogWindow.set(updateOplogWindow(maxSizeGb, 
usedSizeGb, first, last));
                     }
diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactory.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactory.java
index 30fbf23998..091fed9b3f 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactory.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactory.java
@@ -19,10 +19,11 @@
 package org.apache.jackrabbit.oak.plugins.document.mongo;
 
 import org.apache.commons.math3.util.Precision;
-import org.apache.jackrabbit.guava.common.util.concurrent.AtomicDouble;
 import org.apache.jackrabbit.oak.plugins.document.Throttler;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.concurrent.atomic.AtomicReference;
+
 import static java.util.Objects.requireNonNull;
 import static 
org.apache.jackrabbit.oak.plugins.document.Throttler.NO_THROTTLING;
 
@@ -41,7 +42,7 @@ public final class MongoThrottlerFactory {
      * @param throttlingTime time duration for throttling
      * @return an exponential throttler to throttle system if required
      */
-    public static Throttler exponentialThrottler(final int threshold, final 
AtomicDouble oplogWindow, final long throttlingTime) {
+    public static Throttler exponentialThrottler(final int threshold, final 
AtomicReference<Double> oplogWindow, final long throttlingTime) {
         requireNonNull(oplogWindow);
         return new ExponentialThrottler(threshold, oplogWindow, 
throttlingTime);
     }
@@ -58,10 +59,10 @@ public final class MongoThrottlerFactory {
 
         private final int threshold;
         @NotNull
-        private final AtomicDouble oplogWindow;
+        private final AtomicReference<Double> oplogWindow;
         private final long throttlingTime;
 
-        public ExponentialThrottler(final int threshold, final @NotNull 
AtomicDouble oplogWindow, final long throttlingTime) {
+        public ExponentialThrottler(final int threshold, final @NotNull 
AtomicReference<Double> oplogWindow, final long throttlingTime) {
             this.threshold = threshold;
             this.oplogWindow = oplogWindow;
             this.throttlingTime = throttlingTime;
@@ -75,7 +76,7 @@ public final class MongoThrottlerFactory {
         @Override
         public long throttlingTime() {
             final double threshold = this.threshold;
-            final double oplogWindow = this.oplogWindow.doubleValue();
+            final double oplogWindow = this.oplogWindow.get();
             long throttleTime = throttlingTime;
 
             if (Precision.compareTo(oplogWindow,threshold/8,  0.001) <= 0) {
diff --git 
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactoryTest.java
 
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactoryTest.java
index e8d4ddf9a3..6d7180d6ac 100644
--- 
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactoryTest.java
+++ 
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoThrottlerFactoryTest.java
@@ -18,10 +18,11 @@
  */
 package org.apache.jackrabbit.oak.plugins.document.mongo;
 
-import org.apache.jackrabbit.guava.common.util.concurrent.AtomicDouble;
 import org.apache.jackrabbit.oak.plugins.document.Throttler;
 import org.junit.Test;
 
+import java.util.concurrent.atomic.AtomicReference;
+
 import static 
org.apache.jackrabbit.oak.plugins.document.mongo.MongoThrottlerFactory.exponentialThrottler;
 import static 
org.apache.jackrabbit.oak.plugins.document.mongo.MongoThrottlerFactory.noThrottler;
 import static org.junit.Assert.assertEquals;
@@ -46,67 +47,67 @@ public class MongoThrottlerFactoryTest {
 
     @Test
     public void testExpThrottler() {
-        Throttler throttler = exponentialThrottler(10, new AtomicDouble(11), 
10);
+        Throttler throttler = exponentialThrottler(10, new 
AtomicReference<>(11.0), 10);
         assertEquals(0L, throttler.throttlingTime());
     }
 
     @Test
     public void testExpThrottler_2() {
-        Throttler throttler = exponentialThrottler(10, new 
AtomicDouble(10.002), 10);
+        Throttler throttler = exponentialThrottler(10, new 
AtomicReference<>(10.002), 10);
         assertEquals(0L, throttler.throttlingTime());
     }
 
     @Test
     public void testExpThrottlerNormalPace() {
-        Throttler throttler = exponentialThrottler(10, new 
AtomicDouble(10.001), 10);
+        Throttler throttler = exponentialThrottler(10, new 
AtomicReference<>(10.001), 10);
         assertEquals(10L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingNormalPace_2() {
-        Throttler throttler = exponentialThrottler(10, new 
AtomicDouble(5.001), 10);
+        Throttler throttler = exponentialThrottler(10, new 
AtomicReference<>(5.001), 10);
         assertEquals(10L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingDoublePace() {
-        Throttler throttler = exponentialThrottler(10, new AtomicDouble(5.0), 
10);
+        Throttler throttler = exponentialThrottler(10, new 
AtomicReference<>(5.0), 10);
         assertEquals(20L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingDoublePace_2() {
-        Throttler throttler = exponentialThrottler(10, new 
AtomicDouble(5.0001), 10);
+        Throttler throttler = exponentialThrottler(10, new 
AtomicReference<>(5.0001), 10);
         assertEquals(20L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingDoublePace_3() {
-        Throttler throttler = exponentialThrottler(20, new 
AtomicDouble(5.001), 10);
+        Throttler throttler = exponentialThrottler(20, new 
AtomicReference<>(5.001), 10);
         assertEquals(20L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingQuadruplePace() {
-        Throttler throttler = exponentialThrottler(20, new 
AtomicDouble(5.0001), 10);
+        Throttler throttler = exponentialThrottler(20, new 
AtomicReference<>(5.0001), 10);
         assertEquals(40L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingQuadruplePace_2() {
-        Throttler throttler = exponentialThrottler(40, new 
AtomicDouble(5.001), 10);
+        Throttler throttler = exponentialThrottler(40, new 
AtomicReference<>(5.001), 10);
         assertEquals(40L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingOctagonalPace() {
-        Throttler throttler = exponentialThrottler(80, new 
AtomicDouble(5.0001), 10);
+        Throttler throttler = exponentialThrottler(80, new 
AtomicReference<>(5.0001), 10);
         assertEquals(80L, throttler.throttlingTime());
     }
 
     @Test
     public void testThrottlingOctagonalPace_2() {
-        Throttler throttler = exponentialThrottler(160, new 
AtomicDouble(5.0001), 10);
+        Throttler throttler = exponentialThrottler(160, new 
AtomicReference<>(5.0001), 10);
         assertEquals(80L, throttler.throttlingTime());
     }
 

Reply via email to