You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/12/03 01:27:19 UTC
[dubbo] 02/02: fix deployer sequence
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.0-metadata-refactor
in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 2b89e08804def855215294c87ce553ebf456c2f4
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Dec 1 15:08:47 2021 +0800
fix deployer sequence
---
.../dubbo/common/deploy/ApplicationDeployer.java | 5 ++++
.../config/deploy/DefaultApplicationDeployer.java | 5 +---
.../dubbo/config/deploy/DefaultModuleDeployer.java | 6 ++--
.../config/metadata/ExporterDeployListener.java | 8 ++++-
.../src/main/resources/spring/dubbo-provider.xml | 8 ++---
.../registry/client/AbstractServiceDiscovery.java | 5 ++++
.../ZookeeperServiceDiscoveryFactoryTest.java | 34 ----------------------
7 files changed, 25 insertions(+), 46 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 a0ed30b..0b74696 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
@@ -51,6 +51,11 @@ public interface ApplicationDeployer extends Deployer<ApplicationModel> {
void prepareApplicationInstance();
/**
+ * Register application instance and start internal services
+ */
+ void prepareInternalModule();
+
+ /**
* Pre-processing before destroy model
*/
void preDestroy();
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 aa80620..a45fb7d 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
@@ -578,9 +578,6 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
@Override
public void prepareApplicationInstance() {
- // ensure init and start internal module first
- prepareInternalModule();
-
if (hasPreparedApplicationInstance.get()) {
return;
}
@@ -596,7 +593,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
}
}
- private void prepareInternalModule() {
+ public void prepareInternalModule() {
synchronized (internalModuleLock) {
if (!hasPreparedInternalModule.compareAndSet(false, true)) {
return;
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java
index 6a6f5bc..de27724 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java
@@ -142,9 +142,9 @@ public class DefaultModuleDeployer extends AbstractDeployer<ModuleModel> impleme
// prepare application instance
// exclude internal module to avoid wait itself
-// if (moduleModel != moduleModel.getApplicationModel().getInternalModule()) {
-// applicationDeployer.prepareApplicationInstance();
-// }
+ if (moduleModel != moduleModel.getApplicationModel().getInternalModule()) {
+ applicationDeployer.prepareInternalModule();
+ }
// refer services
referServices();
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java
index 929ed73..1a0bafc 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ExporterDeployListener.java
@@ -17,13 +17,14 @@
package org.apache.dubbo.config.metadata;
import org.apache.dubbo.common.deploy.ApplicationDeployListener;
+import org.apache.dubbo.common.lang.Prioritized;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.model.ApplicationModel;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
-public class ExporterDeployListener implements ApplicationDeployListener {
+public class ExporterDeployListener implements ApplicationDeployListener, Prioritized {
protected volatile ConfigurableMetadataServiceExporter metadataServiceExporter;
@Override
@@ -87,4 +88,9 @@ public class ExporterDeployListener implements ApplicationDeployListener {
public void onFailure(ApplicationModel scopeModel, Throwable cause) {
}
+
+ @Override
+ public int getPriority() {
+ return MAX_PRIORITY;
+ }
}
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
index 60f1d93..42d7ccd 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
@@ -37,12 +37,12 @@
<bean id="restDemoService" class="org.apache.dubbo.demo.provider.RestDemoServiceImpl"/>
<bean id="tripleService" class="org.apache.dubbo.demo.provider.TripleServiceImpl"/>
- <dubbo:service delay="5000" interface="org.apache.dubbo.demo.DemoService" timeout="3000" ref="demoService" registry="registry1" protocol="dubbo"/>
- <dubbo:service delay="5000" version="1.0.0" group="greeting" timeout="5000" interface="org.apache.dubbo.demo.GreetingService"
+ <dubbo:service delay="500000" interface="org.apache.dubbo.demo.DemoService" timeout="3000" ref="demoService" registry="registry1" protocol="dubbo"/>
+ <dubbo:service delay="500000" version="1.0.0" group="greeting" timeout="5000" interface="org.apache.dubbo.demo.GreetingService"
ref="greetingService" protocol="dubbo"/>
- <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.RestDemoService"
+ <dubbo:service delay="500000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.RestDemoService"
ref="restDemoService" protocol="rest"/>
- <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService"
+ <dubbo:service delay="500000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService"
ref="tripleService" protocol="tri"/>
</beans>
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
index 4364e23..102f14c 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
@@ -84,6 +84,11 @@ public abstract class AbstractServiceDiscovery implements ServiceDiscovery {
}
}
+ /**
+ * Update assumes that DefaultServiceInstance and its attributes will never get updated once created.
+ * Checking hasExportedServices() before registration guarantees that at least one service is ready for creating the
+ * instance.
+ */
@Override
public synchronized final void update() throws RuntimeException {
if (this.serviceInstance == null) {
diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryFactoryTest.java b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryFactoryTest.java
deleted file mode 100644
index bae8ac7..0000000
--- a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryFactoryTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.zookeeper;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.client.ServiceDiscovery;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class ZookeeperServiceDiscoveryFactoryTest {
-
- @Test
- public void testCreateZookeeperServiceDiscovery() {
- final URL url = URL.valueOf("test://test:80");
- final ZookeeperServiceDiscoveryFactory factory = new ZookeeperServiceDiscoveryFactory();
- ServiceDiscovery discovery = factory.createDiscovery(url);
-
- Assertions.assertTrue(discovery instanceof ZookeeperServiceDiscovery);
- }
-}