You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/04/22 00:32:02 UTC
[dubbo-go] branch 1.5 updated: chery-pick
a14c18f35f7510b714d8a2a4ef32a285d17c43c7
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/1.5 by this push:
new 20b6349 chery-pick a14c18f35f7510b714d8a2a4ef32a285d17c43c7
new 9f88c54 Merge branch '1.5' of https://github.com/apache/dubbo-go into 1.5
20b6349 is described below
commit 20b63493ce910945ad1d1189e36ab13e3c17c8c5
Author: WilliamLeaves <wi...@gmail.com>
AuthorDate: Thu Apr 22 07:43:48 2021 +0800
chery-pick a14c18f35f7510b714d8a2a4ef32a285d17c43c7
---
metadata/service/inmemory/service.go | 15 +++++++++++++++
registry/nacos/service_discovery.go | 16 +++++-----------
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/metadata/service/inmemory/service.go b/metadata/service/inmemory/service.go
index 8da78c3..5bac94d 100644
--- a/metadata/service/inmemory/service.go
+++ b/metadata/service/inmemory/service.go
@@ -153,11 +153,26 @@ func (mts *MetadataService) getSpecifiedService(services *sync.Map, serviceKey s
// ExportURL can store the in memory
func (mts *MetadataService) ExportURL(url *common.URL) (bool, error) {
+ if constant.METADATA_SERVICE_NAME == url.GetParam(constant.INTERFACE_KEY, "") {
+ mts.metadataServiceURL = url
+ return true, nil
+ }
+ mts.mOnce.Do(func() {
+ mts.metadataInfo = common.NewMetadataInfWithApp(config.GetApplicationConfig().Name)
+ })
+ mts.metadataInfo.AddService(common.NewServiceInfoWithURL(url))
return mts.addURL(mts.exportedServiceURLs, url), nil
}
// UnexportURL can remove the url store in memory
func (mts *MetadataService) UnexportURL(url *common.URL) error {
+ if constant.METADATA_SERVICE_NAME == url.GetParam(constant.INTERFACE_KEY, "") {
+ mts.metadataServiceURL = nil
+ return nil
+ }
+ if mts.metadataInfo != nil {
+ mts.metadataInfo.RemoveService(common.NewServiceInfoWithURL(url))
+ }
mts.removeURL(mts.exportedServiceURLs, url)
return nil
}
diff --git a/registry/nacos/service_discovery.go b/registry/nacos/service_discovery.go
index 4533e7b..5bdf025 100644
--- a/registry/nacos/service_discovery.go
+++ b/registry/nacos/service_discovery.go
@@ -306,19 +306,11 @@ var (
)
// newNacosServiceDiscovery will create new service discovery instance
-// use double-check pattern to reduce race condition
func newNacosServiceDiscovery(name string) (registry.ServiceDiscovery, error) {
-
- instance, ok := instanceMap[name]
- if ok {
- return instance, nil
- }
-
initLock.Lock()
defer initLock.Unlock()
- // double check
- instance, ok = instanceMap[name]
+ instance, ok := instanceMap[name]
if ok {
return instance, nil
}
@@ -344,10 +336,12 @@ func newNacosServiceDiscovery(name string) (registry.ServiceDiscovery, error) {
descriptor := fmt.Sprintf("nacos-service-discovery[%s]", remoteConfig.Address)
- return &nacosServiceDiscovery{
+ newInstance := &nacosServiceDiscovery{
group: group,
namingClient: client,
descriptor: descriptor,
registryInstances: []registry.ServiceInstance{},
- }, nil
+ }
+ instanceMap[name] = newInstance
+ return newInstance, nil
}