diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 63951d7009ecf16ec8672cab614010734646650e..0192b4c8a06263266cb80b344a0792ea2f6af8c8 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -18,13 +18,13 @@ package config import ( - "go.uber.org/atomic" "path/filepath" "testing" ) import ( "github.com/stretchr/testify/assert" + "go.uber.org/atomic" ) import ( diff --git a/config/service_config.go b/config/service_config.go index 9bc86d600128f7beffb3972c3222e2bd459899f5..9cf60c8fb30f74e78f44e736604394fda779eb88 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -205,12 +205,16 @@ func (c *ServiceConfig) Unexport() { if c.unexported.Load() { return } - c.exportersLock.Lock() - defer c.exportersLock.Unlock() - for _, exporter := range c.exporters { - exporter.Unexport() - } - c.exporters = nil + + func() { + c.exportersLock.Lock() + defer c.exportersLock.Unlock() + for _, exporter := range c.exporters { + exporter.Unexport() + } + c.exporters = nil + }() + c.exported.Store(false) c.unexported.Store(true) } diff --git a/metadata/service/exporter/configurable/exporter.go b/metadata/service/exporter/configurable/exporter.go index 1e05013c010ef896c26caa07137b87bcdcb544ab..3d12e0ecd4def4b9d99f346a4f556fc3d781d1b2 100644 --- a/metadata/service/exporter/configurable/exporter.go +++ b/metadata/service/exporter/configurable/exporter.go @@ -48,22 +48,28 @@ func NewMetadataServiceExporter(metadataService service.MetadataService) exporte // Export will export the metadataService func (exporter *MetadataServiceExporter) Export() error { if !exporter.IsExported() { - exporter.lock.Lock() - defer exporter.lock.Unlock() - exporter.serviceConfig = config.NewServiceConfig("MetadataService", context.Background()) - exporter.serviceConfig.Protocol = constant.DEFAULT_PROTOCOL - exporter.serviceConfig.Protocols = map[string]*config.ProtocolConfig{ + + serviceConfig := config.NewServiceConfig("MetadataService", context.Background()) + serviceConfig.Protocol = constant.DEFAULT_PROTOCOL + serviceConfig.Protocols = map[string]*config.ProtocolConfig{ constant.DEFAULT_PROTOCOL: generateMetadataProtocol(), } - exporter.serviceConfig.InterfaceName = constant.METADATA_SERVICE_NAME - exporter.serviceConfig.Group = config.GetApplicationConfig().Name - exporter.serviceConfig.Version = exporter.metadataService.Version() - exporter.serviceConfig.Implement(exporter.metadataService) - err := exporter.serviceConfig.Export() + serviceConfig.InterfaceName = constant.METADATA_SERVICE_NAME + serviceConfig.Group = config.GetApplicationConfig().Name + serviceConfig.Version = exporter.metadataService.Version() + + var err error + func() { + exporter.lock.Lock() + defer exporter.lock.Unlock() + exporter.serviceConfig = serviceConfig + exporter.serviceConfig.Implement(exporter.metadataService) + err = exporter.serviceConfig.Export() + }() + logger.Infof("The MetadataService exports urls : %v ", exporter.serviceConfig.GetExportedUrls()) return err } - logger.Warnf("The MetadataService has been exported : %v ", exporter.serviceConfig.GetExportedUrls()) return nil } diff --git a/metadata/service/service.go b/metadata/service/service.go index 8ff63b50598f5bad16e3d1cc76fe6dca16e2fc04..bc526c5411383f0d5cee971cef4f84d6f4f48f59 100644 --- a/metadata/service/service.go +++ b/metadata/service/service.go @@ -28,6 +28,7 @@ import ( // Metadataservice is used to define meta data related behaviors type MetadataService interface { + common.RPCService // ServiceName will get the service's name in meta service , which is application name ServiceName() (string, error) // ExportURL will store the exported url in metadata @@ -50,7 +51,6 @@ type MetadataService interface { GetServiceDefinitionByServiceKey(serviceKey string) (string, error) // Version will return the metadata service version Version() string - common.RPCService } // BaseMetadataService is used for the common logic for struct who will implement interface MetadataService