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

adoroszlai 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 f22f32e05d HDDS-12764. NodeDecommissionManager#monitorInterval should 
get with ms unit from config (#8250)
f22f32e05d is described below

commit f22f32e05d0b98c74349c3aa9040d636c7693e49
Author: Peter Lee <[email protected]>
AuthorDate: Thu Apr 10 02:01:24 2025 +0800

    HDDS-12764. NodeDecommissionManager#monitorInterval should get with ms unit 
from config (#8250)
---
 .../hadoop/hdds/conf/OzoneConfiguration.java       | 32 ++++++++++++++++++++++
 .../hdds/scm/node/NodeDecommissionManager.java     | 21 ++++----------
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
index 0e11be5477..8ed13b588b 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
@@ -37,6 +37,7 @@
 import java.util.Properties;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 import java.util.stream.Collectors;
 import javax.xml.bind.JAXBContext;
@@ -53,6 +54,7 @@
 import org.apache.hadoop.hdds.utils.LegacyHadoopConfigurationSource;
 import org.apache.hadoop.ozone.OzoneConfigKeys;
 import org.apache.ratis.server.RaftServerConfigKeys;
+import org.slf4j.Logger;
 
 /**
  * Configuration for ozone.
@@ -476,6 +478,36 @@ private Properties getCryptoProperties() {
     }
   }
 
+  /**
+   * Get a duration value from the configuration, and default to the given 
value if it's invalid.
+   * @param logger the logger to use
+   * @param key the key to get the value from
+   * @param defaultValue the default value to use if the key is not set
+   * @param unit the unit of the duration
+   * @return the duration value
+   */
+  public long getOrFixDuration(Logger logger, String key, String defaultValue, 
TimeUnit unit) {
+    maybeFixInvalidDuration(logger, key, defaultValue, unit);
+    return getTimeDuration(key, defaultValue, unit);
+  }
+
+  private boolean maybeFixInvalidDuration(Logger logger, String key, String 
defaultValue, TimeUnit unit) {
+    boolean fixed = maybeFixInvalidDuration(key, defaultValue, unit);
+    if (fixed) {
+      logger.warn("{} must be greater than zero, defaulting to {}", key, 
defaultValue);
+    }
+    return fixed;
+  }
+
+  private boolean maybeFixInvalidDuration(String key, String defaultValue, 
TimeUnit unit) {
+    long duration = getTimeDuration(key, defaultValue, unit);
+    if (duration <= 0) {
+      set(key, defaultValue);
+      return true;
+    }
+    return false;
+  }
+
   @Override
   public Iterator<Map.Entry<String, String>> iterator() {
     DelegatingProperties properties = (DelegatingProperties) getProps();
diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
index a4deae441f..045666eee5 100644
--- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
@@ -276,21 +276,12 @@ public NodeDecommissionManager(OzoneConfiguration config, 
NodeManager nm, Contai
         HddsConfigKeys.HDDS_DATANODE_USE_DN_HOSTNAME,
         HddsConfigKeys.HDDS_DATANODE_USE_DN_HOSTNAME_DEFAULT);
 
-    long monitorInterval = config.getTimeDuration(
+    long monitorIntervalMs = config.getOrFixDuration(
+        LOG,
         ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL,
         ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL_DEFAULT,
-        TimeUnit.SECONDS);
-    if (monitorInterval <= 0) {
-      LOG.warn("{} must be greater than zero, defaulting to {}",
-          ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL,
-          ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL_DEFAULT);
-      config.set(ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL,
-          ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL_DEFAULT);
-      monitorInterval = config.getTimeDuration(
-          ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL,
-          ScmConfigKeys.OZONE_SCM_DATANODE_ADMIN_MONITOR_INTERVAL_DEFAULT,
-          TimeUnit.SECONDS);
-    }
+        TimeUnit.MILLISECONDS);
+
     
setMaintenanceConfigs(config.getInt("hdds.scm.replication.maintenance.replica.minimum",
 2),
         config.getInt("hdds.scm.replication.maintenance.remaining.redundancy", 
1));
 
@@ -298,8 +289,8 @@ public NodeDecommissionManager(OzoneConfiguration config, 
NodeManager nm, Contai
         rm);
     this.metrics = NodeDecommissionMetrics.create();
     monitor.setMetrics(this.metrics);
-    executor.scheduleAtFixedRate(monitor, monitorInterval, monitorInterval,
-        TimeUnit.SECONDS);
+    executor.scheduleAtFixedRate(monitor, monitorIntervalMs, monitorIntervalMs,
+        TimeUnit.MILLISECONDS);
   }
 
   public Map<String, List<ContainerID>> 
getContainersPendingReplication(DatanodeDetails dn)


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

Reply via email to