Skip to content

Commit

Permalink
delete redundant dynamic configuration center cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjianhui03 committed Nov 5, 2021
1 parent 5fd6115 commit 021d9f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 3 additions & 2 deletions cluster/router/v3router/router_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/cluster/router"
"dubbo.apache.org/dubbo-go/v3/common"
conf "dubbo.apache.org/dubbo-go/v3/common/config"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
Expand All @@ -48,11 +49,11 @@ func NewUniformRouterChain() (router.PriorityRouter, error) {
// 1. add mesh route listener
r := &RouterChain{}
rootConfig := config.GetRootConfig()
if rootConfig.ConfigCenter.DynamicConfiguration == nil {
dynamicConfiguration := conf.GetEnvInstance().GetDynamicConfiguration()
if dynamicConfiguration == nil {
logger.Infof("Config center does not start, please check if the configuration center has been properly configured in dubbogo.yml")
return nil, nil
}
dynamicConfiguration := rootConfig.ConfigCenter.DynamicConfiguration
dynamicConfiguration.AddListener(rootConfig.Application.Name, r)

// 2. try to get mesh route configuration, default key is "dubbo.io.MESHAPPRULE" with group "dubbo"
Expand Down
11 changes: 4 additions & 7 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ type CenterConfig struct {
AppID string `default:"dubbo" yaml:"app-id" json:"app-id,omitempty"`
Timeout string `default:"10s" yaml:"timeout" json:"timeout,omitempty"`
Params map[string]string `yaml:"params" json:"parameters,omitempty"`

DynamicConfiguration config_center.DynamicConfiguration
}

// Prefix dubbo.config-center
Expand Down Expand Up @@ -137,8 +135,6 @@ func startConfigCenter(rc *RootConfig) error {
logger.Errorf("Start dynamic configuration center error, error message is %v", err)
return err
}
envInstance := conf.GetEnvInstance()
envInstance.SetDynamicConfiguration(dynamicConfig)

strConf, err := dynamicConfig.GetProperties(cc.DataId, config_center.WithGroup(cc.Group))
if err != nil {
Expand Down Expand Up @@ -170,14 +166,15 @@ func (c *CenterConfig) CreateDynamicConfiguration() (config_center.DynamicConfig
}

func (c *CenterConfig) GetDynamicConfiguration() (config_center.DynamicConfiguration, error) {
if c.DynamicConfiguration != nil {
return c.DynamicConfiguration, nil
envInstance := conf.GetEnvInstance()
if envInstance.GetDynamicConfiguration() != nil {
return envInstance.GetDynamicConfiguration(), nil
}
dynamicConfig, err := c.CreateDynamicConfiguration()
if err != nil {
return nil, errors.WithStack(err)
}
c.DynamicConfiguration = dynamicConfig
envInstance.SetDynamicConfiguration(dynamicConfig)
return dynamicConfig, nil
}

Expand Down

0 comments on commit 021d9f0

Please sign in to comment.