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:17 UTC

[dubbo] branch 3.0-metadata-refactor updated (dfc4d74 -> 2b89e08)

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

liujun pushed a change to branch 3.0-metadata-refactor
in repository https://gitbox.apache.org/repos/asf/dubbo.git.


    from dfc4d74  fix uts
     new cda07b6  fix metadata report and cache
     new 2b89e08  fix deployer sequence

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/dubbo/common/cache/FileCacheStore.java  |  9 +++---
 .../dubbo/common/config/ConfigurationUtils.java    |  2 +-
 .../dubbo/common/deploy/ApplicationDeployer.java   |  5 ++++
 .../org/apache/dubbo/config/ServiceConfig.java     |  3 +-
 .../config/deploy/DefaultApplicationDeployer.java  |  5 +---
 .../dubbo/config/deploy/DefaultModuleDeployer.java |  6 ++--
 .../config/metadata/ExporterDeployListener.java    |  8 ++++-
 .../src/main/resources/spring/dubbo-consumer.xml   |  2 +-
 .../src/main/resources/spring/dubbo-provider.xml   |  8 ++---
 .../org/apache/dubbo/metadata/MetadataService.java |  4 +++
 .../registry/client/AbstractServiceDiscovery.java  | 18 ++++++++----
 .../registry/client/metadata/MetadataUtils.java    |  2 +-
 .../client/metadata/store/MetaCacheManager.java    |  9 ++++--
 .../ZookeeperServiceDiscoveryFactoryTest.java      | 34 ----------------------
 14 files changed, 53 insertions(+), 62 deletions(-)
 delete mode 100644 dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryFactoryTest.java

[dubbo] 02/02: fix deployer sequence

Posted by li...@apache.org.
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);
-    }
-}

[dubbo] 01/02: fix metadata report and cache

Posted by li...@apache.org.
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 cda07b6656b5a360dbd2e25d7553d02c99dba719
Author: ken.lj <ke...@gmail.com>
AuthorDate: Fri Nov 26 15:10:34 2021 +0800

    fix metadata report and cache
---
 .../java/org/apache/dubbo/common/cache/FileCacheStore.java  |  9 +++++----
 .../org/apache/dubbo/common/config/ConfigurationUtils.java  |  2 +-
 .../main/java/org/apache/dubbo/config/ServiceConfig.java    |  3 ++-
 .../src/main/resources/spring/dubbo-consumer.xml            |  2 +-
 .../java/org/apache/dubbo/metadata/MetadataService.java     |  4 ++++
 .../dubbo/registry/client/AbstractServiceDiscovery.java     | 13 +++++++------
 .../dubbo/registry/client/metadata/MetadataUtils.java       |  2 +-
 .../registry/client/metadata/store/MetaCacheManager.java    |  9 +++++++--
 8 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
index efe764d..cbe42f0 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
@@ -57,7 +57,7 @@ public class FileCacheStore {
     private FileLock directoryLock;
     private File lockFile;
 
-    public FileCacheStore(String basePath, String fileName) throws IOException {
+    public FileCacheStore(String basePath, String fileName) throws IOException, PathNotExclusiveException {
         if (basePath == null) {
             basePath = System.getProperty("user.home") + "/.dubbo/";
         }
@@ -65,7 +65,7 @@ public class FileCacheStore {
         this.fileName = fileName;
 
         this.cacheFile = getFile(fileName, SUFFIX);
-        if (!cacheFile.exists()) {
+        if (cacheFile != null && !cacheFile.exists()) {
             cacheFile.createNewFile();
         }
     }
@@ -95,7 +95,7 @@ public class FileCacheStore {
         return properties;
     }
 
-    public File getFile(String cacheName, String suffix) {
+    public File getFile(String cacheName, String suffix) throws PathNotExclusiveException {
         cacheName = safeName(cacheName);
         if (!cacheName.endsWith(suffix)) {
             cacheName = cacheName + suffix;
@@ -109,7 +109,7 @@ public class FileCacheStore {
      * @param name the file name
      * @return a file object
      */
-    public File getFile(String name) {
+    public File getFile(String name) throws PathNotExclusiveException {
         synchronized (this) {
             File candidate = basePath;
             // ensure cache store path exists
@@ -123,6 +123,7 @@ public class FileCacheStore {
                 logger.warn("Path '" + basePath
                     + "' is already used by an existing Dubbo process.\n"
                     + "Please specify another one explicitly.");
+                throw e;
             }
         }
 
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
index 2f79aa2..90feeab 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
@@ -162,7 +162,7 @@ public class ConfigurationUtils {
     public static Map<String, String> parseProperties(String content) throws IOException {
         Map<String, String> map = new HashMap<>();
         if (StringUtils.isEmpty(content)) {
-            logger.warn("You specified the config center, but there's not even one single config item in it.");
+            logger.warn("Config center was specified, but no config item found.");
         } else {
             Properties properties = new Properties();
             properties.load(new StringReader(content));
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
index d794397..f3fcacb 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
@@ -80,6 +80,7 @@ import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY;
 import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND;
 import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY;
 import static org.apache.dubbo.config.Constants.SCOPE_NONE;
+import static org.apache.dubbo.metadata.MetadataService.isMetadataService;
 import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY;
 import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
 import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
@@ -559,7 +560,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
             // export to remote if the config is not local (export to local only when config is local)
             if (!SCOPE_LOCAL.equalsIgnoreCase(scope)) {
                 url = exportRemote(url, registryURLs);
-                if (!isGeneric(generic)) {
+                if (!isGeneric(generic) && !isMetadataService(interfaceName)) {
                     ServiceDescriptor descriptor = getScopeModel().getServiceRepository().getService(interfaceName);
                     if (descriptor != null) {
                         MetadataUtils.publishServiceDefinition(getScopeModel().getServiceRepository().getService(interfaceName), getApplicationModel());
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml
index 88f9253..e8c9521 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml
@@ -26,7 +26,7 @@
 
     <dubbo:metadata-report address="zookeeper://127.0.0.1:2181"/>
 
-    <dubbo:registry address="zookeeper://127.0.0.1:2181?registry-type=service"/>
+    <dubbo:registry id="demo1" address="zookeeper://127.0.0.1:2181?registry-type=service"/>
 
     <dubbo:reference id="demoService" check="false"
                      interface="org.apache.dubbo.demo.DemoService"/>
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java
index b5c5d2f..6e48658 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java
@@ -186,4 +186,8 @@ public interface MetadataService {
         return unmodifiableSortedSet(stream.map(URL::toFullString).collect(TreeSet::new, Set::add, Set::addAll));
     }
 
+    static boolean isMetadataService(String interfaceName) {
+        return interfaceName != null && interfaceName.equals(MetadataService.class.getName());
+    }
+
 }
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 aa13626..4364e23 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
@@ -31,7 +31,6 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
 
 import java.util.List;
 
-import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
 import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
 import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
 import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
@@ -59,11 +58,13 @@ public abstract class AbstractServiceDiscovery implements ServiceDiscovery {
         this.applicationModel = applicationModel;
         MetadataReportInstance metadataReportInstance = applicationModel.getBeanFactory().getBean(MetadataReportInstance.class);
         metadataType = metadataReportInstance.getMetadataType();
-        if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataReportInstance.getMetadataType())) {
-            this.metadataReport = metadataReportInstance.getMetadataReport(registryURL.getParameter(REGISTRY_CLUSTER_KEY));
-        } else {
-            this.metadataReport = metadataReportInstance.getNopMetadataReport();
-        }
+//        if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataReportInstance.getMetadataType())) {
+//            this.metadataReport = metadataReportInstance.getMetadataReport(registryURL.getParameter(REGISTRY_CLUSTER_KEY));
+//        } else {
+//            this.metadataReport = metadataReportInstance.getNopMetadataReport();
+//        }
+        this.metadataReport = metadataReportInstance.getMetadataReport(registryURL.getParameter(REGISTRY_CLUSTER_KEY));
+
     }
 
     public AbstractServiceDiscovery(String serviceName, URL registryURL) {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
index 4bfa752..6b3979a 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
@@ -146,7 +146,7 @@ public class MetadataUtils {
                 logger.debug("Instance " + instance.getAddress() + " is using metadata type " + metadataType);
             }
             if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
-                MetadataUtils.getMetadata(instance, metadataReport);
+                metadataInfo = MetadataUtils.getMetadata(instance, metadataReport);
             } else {
                 // change the instance used to communicate to avoid all requests route to the same instance
                 MetadataService metadataServiceProxy = MetadataUtils.getMetadataServiceProxy(instance);
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java
index ddc9213..e6ae867 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java
@@ -85,7 +85,7 @@ public class MetaCacheManager implements ScopeModelAware, Disposable {
                 MetadataInfo metadataInfo = JsonUtils.getGson().fromJson(value, MetadataInfo.class);
                 cache.put(key, metadataInfo);
             }
-
+            // executorService can be empty if FileCacheStore fails
             executorService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Dubbo-cache-refresh", true));
             executorService.scheduleWithFixedDelay(new CacheRefreshTask(cacheStore, cache), 10, INTERVAL, TimeUnit.MINUTES);
         } catch (Exception e) {
@@ -125,7 +125,12 @@ public class MetaCacheManager implements ScopeModelAware, Disposable {
     }
 
     public void destroy() {
-        executorService.shutdownNow();
+        if (executorService != null) {
+            executorService.shutdownNow();
+        }
+        if (cacheStore != null) {
+            cacheStore.destroy();
+        }
     }
 
     protected static class CacheRefreshTask implements Runnable {