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

sarvekshayr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 971098cce45 HDDS-15405. BackgroundService pool size unchanged by 
reconfiguration (#10379)
971098cce45 is described below

commit 971098cce451f71216550e75ec7afac4b4d7f136
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Fri May 29 06:36:24 2026 +0200

    HDDS-15405. BackgroundService pool size unchanged by reconfiguration 
(#10379)
---
 .../diskbalancer/DiskBalancerService.java          |  9 +------
 .../hadoop/hdds/utils/BackgroundService.java       |  8 +++---
 .../ozone/om/service/DirectoryDeletingService.java |  2 +-
 .../om/service/TestDirectoryDeletingService.java   | 29 ++++++++++++++++++++++
 4 files changed, 35 insertions(+), 13 deletions(-)

diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerService.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerService.java
index a33a2d665fb..3e80b3cb79c 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerService.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerService.java
@@ -41,7 +41,6 @@
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentSkipListMap;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.stream.Collectors;
@@ -267,13 +266,7 @@ private void applyDiskBalancerInfo(DiskBalancerInfo 
diskBalancerInfo)
     setStopAfterDiskEven(validated.isStopAfterDiskEven());
     setVersion(diskBalancerInfo.getVersion());
     setContainerStates(validated.getMovableContainerStates());
-
-    // Default executorService is ScheduledThreadPoolExecutor, so we can
-    // update the poll size by setting corePoolSize.
-    if ((getExecutorService() instanceof ScheduledThreadPoolExecutor)) {
-      ((ScheduledThreadPoolExecutor) getExecutorService())
-          .setCorePoolSize(parallelThread);
-    }
+    setPoolSize(parallelThread);
   }
 
   /**
diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
index 144d1725fdb..1bc023b3337 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
@@ -20,7 +20,6 @@
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadFactory;
@@ -47,7 +46,7 @@ public abstract class BackgroundService {
   private long interval;
   private volatile long serviceTimeoutInNanos;
   private TimeUnit unit;
-  private final int threadPoolSize;
+  private int threadPoolSize;
   private final String threadNamePrefix;
   private final PeriodicalTask service;
   private CompletableFuture<Void> future;
@@ -77,7 +76,7 @@ protected CompletableFuture<Void> getFuture() {
   }
 
   @VisibleForTesting
-  public synchronized ExecutorService getExecutorService() {
+  public synchronized ScheduledThreadPoolExecutor getExecutorService() {
     return this.exec;
   }
 
@@ -90,6 +89,7 @@ public synchronized void setPoolSize(int size) {
     // the corePoolSize will always less maximumPoolSize.
     // So we can directly set the corePoolSize
     exec.setCorePoolSize(size);
+    threadPoolSize = size;
   }
 
   public synchronized void setServiceTimeoutInNanos(long newTimeout) {
@@ -126,7 +126,7 @@ protected synchronized void setInterval(long newInterval, 
TimeUnit newUnit) {
     this.unit = newUnit;
   }
 
-  protected synchronized long getIntervalMillis() {
+  public synchronized long getIntervalMillis() {
     return this.unit.toMillis(interval);
   }
 
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/DirectoryDeletingService.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/DirectoryDeletingService.java
index cd0b3c90e87..a4d06197c60 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/DirectoryDeletingService.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/DirectoryDeletingService.java
@@ -204,7 +204,7 @@ public void 
registerReconfigCallbacks(ReconfigurationHandler handler) {
     });
   }
 
-  private synchronized void updateAndRestart(OzoneConfiguration conf) {
+  synchronized void updateAndRestart(OzoneConfiguration conf) {
     long newInterval = 
conf.getTimeDuration(OZONE_DIR_DELETING_SERVICE_INTERVAL,
         OZONE_DIR_DELETING_SERVICE_INTERVAL_DEFAULT, TimeUnit.SECONDS);
     int newCorePoolSize = conf.getInt(OZONE_THREAD_NUMBER_DIR_DELETION,
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingService.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingService.java
index 776ef52c880..fdb723dc319 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingService.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingService.java
@@ -27,6 +27,7 @@
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -230,6 +231,34 @@ public void testMultithreadedDirectoryDeletion() throws 
Exception {
     }
   }
 
+  @Test
+  void testUpdateAndRestart() throws Exception {
+    int threadCount = 2;
+    OzoneConfiguration conf = createConfAndInitValues(threadCount);
+    OmTestManagers omTestManagers = new OmTestManagers(conf);
+    om = omTestManagers.getOzoneManager();
+    DirectoryDeletingService subject = 
om.getKeyManager().getDirDeletingService();
+
+    OzoneConfiguration updatedConf = new OzoneConfiguration(conf);
+    int newThreadCount = threadCount + 1;
+    Duration newInterval = Duration.ofSeconds(5);
+    updatedConf.setInt(OZONE_THREAD_NUMBER_DIR_DELETION, newThreadCount);
+    updatedConf.setTimeDuration(OZONE_DIR_DELETING_SERVICE_INTERVAL, 
newInterval.toMillis(), TimeUnit.MILLISECONDS);
+
+    assertThat(subject.getExecutorService().getCorePoolSize())
+        .as("initial thread pool size")
+        .isEqualTo(threadCount);
+
+    subject.updateAndRestart(updatedConf);
+
+    assertThat(subject.getExecutorService().getCorePoolSize())
+        .as("thread pool size after restart")
+        .isEqualTo(newThreadCount);
+    assertThat(subject.getIntervalMillis())
+        .as("interval after restart")
+        .isEqualTo(newInterval.toMillis());
+  }
+
   @Test
   @DisplayName("DirectoryDeletingService batches PurgeDirectories by Ratis 
byte limit (via submitRequest spy)")
   void testPurgeDirectoriesBatching() throws Exception {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to