From 80fd7b7cc00a720a1e749e14c566d0c5dee7aba7 Mon Sep 17 00:00:00 2001 From: "vito.he" <hxmhlt@163.com> Date: Tue, 21 Apr 2020 18:02:38 +0800 Subject: [PATCH] Mod:resolve conflict --- config/config_loader_test.go | 2 +- config/service_config.go | 16 +++++++---- .../service/exporter/configurable/exporter.go | 28 +++++++++++-------- metadata/service/service.go | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 63951d700..0192b4c8a 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 9bc86d600..9cf60c8fb 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 1e05013c0..3d12e0ecd 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 8ff63b505..bc526c541 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 -- GitLab