sanxun0325 commented on a change in pull request #1675:
URL: https://github.com/apache/dubbo-go/pull/1675#discussion_r786060473



##########
File path: common/extension/filter.go
##########
@@ -33,11 +33,11 @@ func SetFilter(name string, v func() filter.Filter) {
 }
 
 // GetFilter finds the filter extension with @name
-func GetFilter(name string) filter.Filter {
+func GetFilter(name string) (filter.Filter, bool) {

Review comment:
       原来返回一个参数感觉更舒服,panic去掉就可以了

##########
File path: registry/protocol/protocol.go
##########
@@ -72,26 +72,31 @@ func init() {
        extension.SetProtocol("registry", GetProtocol)
 }
 
-func getCacheKey(invoker protocol.Invoker) string {
-       url := getProviderUrl(invoker)
-       delKeys := gxset.NewSet("dynamic", "enabled")
-       return url.CloneExceptParams(delKeys).String()
-}
-
 func newRegistryProtocol() *registryProtocol {
        return &registryProtocol{
                registries: &sync.Map{},
                bounds:     &sync.Map{},
        }
 }
 
-func getRegistry(regUrl *common.URL) registry.Registry {
-       reg, err := extension.GetRegistry(regUrl.Protocol, regUrl)
-       if err != nil {
-               logger.Errorf("Registry can not connect success, program is 
going to panic.Error message is %s", err.Error())
-               panic(err.Error())
+func (proto *registryProtocol) getRegistry(registryUrl *common.URL) 
registry.Registry {
+       var err error
+       reg, loaded := proto.registries.Load(registryUrl.Location)
+       if !loaded {
+               reg, err = extension.GetRegistry(registryUrl.Protocol, 
registryUrl)
+               if err != nil {
+                       logger.Errorf("Registry can not connect success, 
program is going to panic.Error message is %s", err.Error())
+                       panic(err.Error())

Review comment:
       panic 直接panic(err) 就可以吧

##########
File path: config/root_config.go
##########
@@ -124,6 +124,16 @@ func GetApplicationConfig() *ApplicationConfig {
        return rootConfig.Application
 }
 
+func GetShutDown() *ShutdownConfig {

Review comment:
       这样写也许更整洁点
   if err := check(); err == nil && rootConfig.Shutdown != nil {
                return rootConfig.Shutdown
   }
   return NewShutDownConfigBuilder().Build()

##########
File path: config/graceful_shutdown.go
##########
@@ -142,13 +164,28 @@ func waitAndAcceptNewRequests() {
                return
        }
 
-       timeout := rootConfig.Shutdown.GetStepTimeout()
+       time.Sleep(rootConfig.Shutdown.GetConsumerUpdateWaitTime())
 
+       timeout := rootConfig.Shutdown.GetStepTimeout()
        // ignore this step
        if timeout < 0 {
                return
        }
-       time.Sleep(timeout)
+       waitingProviderProcessedTimeout(rootConfig.Shutdown)
+}
+
+func waitingProviderProcessedTimeout(shutdownConfig *ShutdownConfig) {
+       timeout := shutdownConfig.GetStepTimeout()
+       if timeout <= 0 {
+               return
+       }
+       deadline := time.Now().Add(timeout)
+
+       for time.Now().Before(deadline) && shutdownConfig.ProviderActiveCount > 
0 {

Review comment:
       atomic.Load?

##########
File path: config/graceful_shutdown.go
##########
@@ -159,19 +196,20 @@ func waitForSendingAndReceivingRequests() {
                return
        }
        rootConfig.Shutdown.RejectRequest = true
-       waitingProcessedTimeout(rootConfig.Shutdown)
+       waitingConsumerProcessedTimeout(rootConfig.Shutdown)
 }
 
-func waitingProcessedTimeout(shutdownConfig *ShutdownConfig) {
+func waitingConsumerProcessedTimeout(shutdownConfig *ShutdownConfig) {
        timeout := shutdownConfig.GetStepTimeout()
        if timeout <= 0 {
                return
        }
        deadline := time.Now().Add(timeout)
 
-       for time.Now().Before(deadline) && !shutdownConfig.RequestsFinished {
+       for time.Now().Before(deadline) && shutdownConfig.ConsumerActiveCount > 
0 {

Review comment:
       shutdownConfig.ConsumerActiveCount 需要用atomic.Load吧




-- 
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