diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/DomainsManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/DomainsManager.java index eef90aad6..f3cc72e38 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/DomainsManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/DomainsManager.java @@ -670,6 +670,10 @@ public class DomainsManager { lock.unlock(); } + // clean up lock resources since they are no longer in need: + dom2LockMap.remove(dom.getName()); + dom2ContionMap.remove(dom.getName()); + } catch (Throwable e) { Loggers.SRV_LOG.error("VIPSRV-DOM", "error while processing dom update", e); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java index 40a51f920..aefb99f9b 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java @@ -29,9 +29,7 @@ import org.apache.commons.lang3.StringUtils; import java.io.File; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.ThreadFactory; +import java.util.concurrent.*; /** * @author nacos @@ -117,6 +115,8 @@ public class UtilsAndCommons { public static final ScheduledExecutorService INIT_CONFIG_EXECUTOR; + public static final Executor RAFT_PUBLISH_EXECUTOR; + static { // custom serializer and deserializer for fast-json SerializeConfig.getGlobalInstance() @@ -181,6 +181,17 @@ public class UtilsAndCommons { } }); + RAFT_PUBLISH_EXECUTOR + = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setName("nacos.naming.raft.publisher"); + t.setDaemon(true); + return t; + } + }); + } public static String getAllExceptionMsg(Throwable e) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java b/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java index 05bed9657..9544ad73f 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java @@ -553,11 +553,20 @@ public class ApiCommands { if (virtualClusterDomain == null) { - regDom(request); - Lock lock = domainsManager.addLock(dom); Condition condition = domainsManager.addCondtion(dom); + UtilsAndCommons.RAFT_PUBLISH_EXECUTOR.execute(new Runnable() { + @Override + public void run() { + try { + regDom(request); + } catch (Exception e) { + Loggers.SRV_LOG.error("REG-SERIVCE", "register service failed, service:" + dom, e); + } + } + }); + try { lock.lock(); condition.await(5000, TimeUnit.MILLISECONDS);