From 551ff4a374cdcf90fb80c2ef517f62485c3ed9d3 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Wed, 15 Feb 2023 07:17:13 +0800 Subject: [PATCH] Enhance service discovery update interval (#11223) * Enhance service discovery update interval * Update DefaultApplicationDeployer.java --- .../common/deploy/ApplicationDeployer.java | 11 ++++ .../deploy/DefaultApplicationDeployer.java | 30 +++++++++++ .../dubbo/metadata/MetadataConstants.java | 2 +- .../integration/RegistryProtocol.java | 50 +++++++++++++++---- 4 files changed, 83 insertions(+), 10 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/deploy/ApplicationDeployer.java b/dubbo-common/src/main/java/org/apache/dubbo/common/deploy/ApplicationDeployer.java index 611f47c715..7cdd356872 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/deploy/ApplicationDeployer.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/deploy/ApplicationDeployer.java @@ -88,4 +88,15 @@ public interface ApplicationDeployer extends Deployer { * module state changed callbacks */ void notifyModuleChanged(ModuleModel moduleModel, DeployState state); + + /** + * Increase the count of service update threads. + * NOTE: should call ${@link ApplicationDeployer#decreaseServiceRefreshCount()} after update finished + */ + void increaseServiceRefreshCount(); + + /** + * Decrease the count of service update threads + */ + void decreaseServiceRefreshCount(); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java index 5d82ac7da2..f4f64b1167 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java @@ -75,6 +75,7 @@ import java.util.concurrent.Future; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -816,6 +817,13 @@ public class DefaultApplicationDeployer extends AbstractDeployer> overrideListeners = new ConcurrentHashMap<>(); + private final ModuleModel moduleModel; + public ProviderConfigurationListener(ModuleModel moduleModel) { super(moduleModel); + this.moduleModel = moduleModel; if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { this.initWith(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX); } @@ -845,11 +871,17 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { @Override protected void notifyOverrides() { - overrideListeners.values().forEach(listeners -> { - for (NotifyListener listener : listeners) { - ((OverrideListener) listener).doOverrideIfNecessary(); - } - }); + ApplicationDeployer deployer = this.moduleModel.getApplicationModel().getDeployer(); + try { + deployer.increaseServiceRefreshCount(); + overrideListeners.values().forEach(listeners -> { + for (NotifyListener listener : listeners) { + ((OverrideListener) listener).doOverrideIfNecessary(); + } + }); + } finally { + deployer.decreaseServiceRefreshCount(); + } } public Map> getOverrideListeners() {