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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 5d7a02af780b812f1bb528126e5216455e6edb36
Author: zclllhhjj <zhaochan...@selectdb.com>
AuthorDate: Thu Aug 22 16:21:14 2024 +0800

    [Enhancement](FE) Make scheduler aware of interval changes immediately 
(#39695)
    
    ## Proposed changes
    
    Issue Number: close #xxx
    
    Before, if `dynamic_partition_check_interval_seconds` is 86400 now and
    we want to set it to 1, the set operation will not go into effect in
    86400 seconds in worst situation.
    Now all set operation will norify scheduler thread and set the interval
    immediately.
    
    Now only applied for `DynamicPartitionScheduler`. should check other
    daemons in future.
---
 .../java/org/apache/doris/common/ConfigBase.java   |  4 ++++
 .../main/java/org/apache/doris/catalog/Env.java    | 24 +++++++++++++++++++++-
 .../apache/doris/httpv2/rest/SetConfigAction.java  |  3 ++-
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/ConfigBase.java 
b/fe/fe-common/src/main/java/org/apache/doris/common/ConfigBase.java
index 21bd84ebd72..18ae1dc1c01 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/ConfigBase.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/ConfigBase.java
@@ -123,6 +123,10 @@ public class ConfigBase {
         }
     }
 
+    public static Field getField(String name) {
+        return confFields.get(name);
+    }
+
     public void initCustom(String customConfFile) throws Exception {
         this.customConfFile = customConfFile;
         File file = new File(customConfFile);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 3003e832d96..e67752ce236 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -334,6 +334,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 
@@ -567,6 +568,10 @@ public class Env {
 
     private final List<String> forceSkipJournalIds = 
Arrays.asList(Config.force_skip_journal_ids);
 
+    // if a config is relative to a daemon thread. record the relation here. 
we will proactively change interval of it.
+    private final Map<String, Supplier<MasterDaemon>> configtoThreads = 
ImmutableMap
+            .of("dynamic_partition_check_interval_seconds", 
this::getDynamicPartitionScheduler);
+
     public List<TFrontendInfo> getFrontendInfos() {
         List<TFrontendInfo> res = new ArrayList<>();
 
@@ -5717,13 +5722,30 @@ public class Env {
         globalFunctionMgr.replayDropFunction(functionSearchDesc);
     }
 
+    /**
+     * we can't set callback which is in fe-core to config items which are in 
fe-common. so wrap them here. it's not so
+     * good but is best for us now.
+     */
+    public void setMutableConfigwithCallback(String key, String value) throws 
ConfigException {
+        ConfigBase.setMutableConfig(key, value);
+        if (configtoThreads.get(key) != null) {
+            try {
+                
configtoThreads.get(key).get().setInterval(Config.getField(key).getLong(null) * 
1000L);
+                configtoThreads.get(key).get().interrupt();
+                LOG.info("set config " + key + " to " + value);
+            } catch (IllegalAccessException e) {
+                LOG.warn("set config " + key + " failed: " + e.getMessage());
+            }
+        }
+    }
+
     public void setConfig(AdminSetConfigStmt stmt) throws Exception {
         Map<String, String> configs = stmt.getConfigs();
         Preconditions.checkState(configs.size() == 1);
 
         for (Map.Entry<String, String> entry : configs.entrySet()) {
             try {
-                ConfigBase.setMutableConfig(entry.getKey(), entry.getValue());
+                setMutableConfigwithCallback(entry.getKey(), entry.getValue());
             } catch (ConfigException e) {
                 throw new DdlException(e.getMessage());
             }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/SetConfigAction.java 
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/SetConfigAction.java
index d6b539269a9..d9351ec5978 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/SetConfigAction.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/SetConfigAction.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.httpv2.rest;
 
+import org.apache.doris.catalog.Env;
 import org.apache.doris.common.ConfigBase;
 import org.apache.doris.common.ConfigException;
 import org.apache.doris.common.DdlException;
@@ -93,7 +94,7 @@ public class SetConfigAction extends RestBaseController {
             try {
                 if (confValue != null && confValue.length == 1) {
                     try {
-                        ConfigBase.setMutableConfig(confKey, confValue[0]);
+                        
Env.getCurrentEnv().setMutableConfigwithCallback(confKey, confValue[0]);
                     } catch (ConfigException e) {
                         throw new DdlException(e.getMessage());
                     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to