DMwangnima commented on code in PR #2534:
URL: https://github.com/apache/dubbo-go/pull/2534#discussion_r1442775587


##########
global/registry_config.go:
##########
@@ -36,7 +36,7 @@ type RegistryConfig struct {
        Zone              string            `yaml:"zone" json:"zone,omitempty" 
property:"zone"`                // The region where the registry belongs, 
usually used to isolate traffics
        Weight            int64             `yaml:"weight" 
json:"weight,omitempty" property:"weight"`          // Affects traffic 
distribution among registriesConfig, useful when subscribe to multiple 
registriesConfig Take effect only when no preferred registry is specified.
        Params            map[string]string `yaml:"params" 
json:"params,omitempty" property:"params"`
-       RegistryType      string            `yaml:"registry-type"`
+       RegistryType      string            `default:"all" yaml:"registry-type"`

Review Comment:
   Why the default configuration is "all"? Is that the same as dubbo?



##########
metadata/mapping/metadata/service_name_mapping.go:
##########
@@ -24,98 +24,81 @@ import (
 import (
        gxset "github.com/dubbogo/gost/container/set"
        "github.com/dubbogo/gost/log/logger"
-
-       perrors "github.com/pkg/errors"
 )
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
        "dubbo.apache.org/dubbo-go/v3/common/constant"
        "dubbo.apache.org/dubbo-go/v3/common/extension"
-       "dubbo.apache.org/dubbo-go/v3/config"
-       "dubbo.apache.org/dubbo-go/v3/config/instance"
        "dubbo.apache.org/dubbo-go/v3/metadata/mapping"
-       "dubbo.apache.org/dubbo-go/v3/metadata/report"
-       "dubbo.apache.org/dubbo-go/v3/registry"
+       "dubbo.apache.org/dubbo-go/v3/metadata/report/instance"
 )
 
 const (
        DefaultGroup = "mapping"
        slash        = "/"
+       retryTimes   = 10
 )
 
 func init() {
        extension.SetGlobalServiceNameMapping(GetNameMappingInstance)
 }
 
-// MetadataServiceNameMapping is the implementation based on metadata report
+var (
+       serviceNameMappingInstance *ServiceNameMapping
+       serviceNameMappingOnce     sync.Once
+)
+
+// GetNameMappingInstance return an instance, if not found, it creates one
+func GetNameMappingInstance() mapping.ServiceNameMapping {
+       serviceNameMappingOnce.Do(func() {
+               serviceNameMappingInstance = &ServiceNameMapping{}
+       })
+       return serviceNameMappingInstance
+}
+
+// ServiceNameMapping is the implementation based on metadata report
 // it's a singleton
-type MetadataServiceNameMapping struct {
+type ServiceNameMapping struct {
 }
 
 // Map will map the service to this application-level service
-func (d *MetadataServiceNameMapping) Map(url *common.URL) error {
+func (d *ServiceNameMapping) Map(url *common.URL) error {
        serviceInterface := url.GetParam(constant.InterfaceKey, "")
-       // metadata service is admin service, should not be mapped
-       if constant.MetadataServiceName == serviceInterface {
-               logger.Debug("try to map the metadata service, will be ignored")
-               return nil
-       }
-
-       appName := config.GetApplicationConfig().Name
-
-       metadataReport := getMetaDataReport(url.GetParam(constant.RegistryKey, 
""))
+       appName := url.GetParam(constant.ApplicationKey, "")
+       metadataReport := 
instance.GetMetadataReportByRegistry(url.GetParam(constant.RegistryIdKey, ""))
        if metadataReport == nil {
-               logger.Info("get metadata report instance is nil, metadata 
service will be enabled!")
+               logger.Warn("get metadata report instance is nil")

Review Comment:
   If metadataReport == nil, we just log and do not need to return err? It is 
kinda weird.



##########
metadata/mapping/metadata/service_name_mapping.go:
##########
@@ -24,98 +24,81 @@ import (
 import (
        gxset "github.com/dubbogo/gost/container/set"
        "github.com/dubbogo/gost/log/logger"
-
-       perrors "github.com/pkg/errors"
 )
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
        "dubbo.apache.org/dubbo-go/v3/common/constant"
        "dubbo.apache.org/dubbo-go/v3/common/extension"
-       "dubbo.apache.org/dubbo-go/v3/config"
-       "dubbo.apache.org/dubbo-go/v3/config/instance"
        "dubbo.apache.org/dubbo-go/v3/metadata/mapping"
-       "dubbo.apache.org/dubbo-go/v3/metadata/report"
-       "dubbo.apache.org/dubbo-go/v3/registry"
+       "dubbo.apache.org/dubbo-go/v3/metadata/report/instance"
 )
 
 const (
        DefaultGroup = "mapping"
        slash        = "/"
+       retryTimes   = 10
 )
 
 func init() {
        extension.SetGlobalServiceNameMapping(GetNameMappingInstance)
 }
 
-// MetadataServiceNameMapping is the implementation based on metadata report
+var (
+       serviceNameMappingInstance *ServiceNameMapping
+       serviceNameMappingOnce     sync.Once
+)
+
+// GetNameMappingInstance return an instance, if not found, it creates one
+func GetNameMappingInstance() mapping.ServiceNameMapping {
+       serviceNameMappingOnce.Do(func() {
+               serviceNameMappingInstance = &ServiceNameMapping{}
+       })
+       return serviceNameMappingInstance
+}
+
+// ServiceNameMapping is the implementation based on metadata report
 // it's a singleton
-type MetadataServiceNameMapping struct {
+type ServiceNameMapping struct {
 }
 
 // Map will map the service to this application-level service
-func (d *MetadataServiceNameMapping) Map(url *common.URL) error {
+func (d *ServiceNameMapping) Map(url *common.URL) error {
        serviceInterface := url.GetParam(constant.InterfaceKey, "")
-       // metadata service is admin service, should not be mapped
-       if constant.MetadataServiceName == serviceInterface {
-               logger.Debug("try to map the metadata service, will be ignored")
-               return nil
-       }
-
-       appName := config.GetApplicationConfig().Name
-
-       metadataReport := getMetaDataReport(url.GetParam(constant.RegistryKey, 
""))
+       appName := url.GetParam(constant.ApplicationKey, "")
+       metadataReport := 
instance.GetMetadataReportByRegistry(url.GetParam(constant.RegistryIdKey, ""))
        if metadataReport == nil {
-               logger.Info("get metadata report instance is nil, metadata 
service will be enabled!")
+               logger.Warn("get metadata report instance is nil")
        } else {
-               err := 
metadataReport.RegisterServiceAppMapping(serviceInterface, DefaultGroup, 
appName)
+               var err error
+               for i := 0; i < retryTimes; i++ {
+                       err = 
metadataReport.RegisterServiceAppMapping(serviceInterface, DefaultGroup, 
appName)
+                       if err == nil {
+                               break
+                       }
+               }
                if err != nil {
-                       return perrors.WithStack(err)
+                       logger.Errorf("Failed registering mapping to remote, 
&v", err)

Review Comment:
   ditto.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to