Alanxtl commented on code in PR #3773:
URL: https://github.com/apache/dubbo-go/pull/3773#discussion_r4291166695
##########
cluster/router/condition/dynamic_router.go:
##########
@@ -385,7 +386,14 @@ func NewApplicationRouter(url *common.URL)
*ApplicationRouter {
dynamicConfiguration := conf.GetEnvInstance().GetDynamicConfiguration()
if dynamicConfiguration != nil && applicationName != "" {
-
dynamicConfiguration.AddListener(strings.Join([]string{applicationName,
constant.ConditionRouterRuleSuffix}, ""), a)
+ key := strings.Join([]string{applicationName,
constant.ConditionRouterRuleSuffix}, "")
+ dynamicConfiguration.AddListener(key, a)
+ value, err := dynamicConfiguration.GetRule(key)
+ if err != nil {
+ logger.Errorf("[Router][Condition] failed to query
condition rule: key=%s, err=%v", key, err)
+ } else if value != "" {
+ a.Process(&config_center.ConfigChangeEvent{Key: key,
Value: value, ConfigType: remoting.EventTypeAdd})
+ }
Review Comment:
初始动态规则会被静态配置覆盖
`NewApplicationRouter` 在构造时加载动态规则,但 `NewRouterChain` 随后调用
`injectStaticRouters`。同时配置 application 静态规则时,刚读取的 consumer
动态规则会被覆盖,直到下一次配置事件才恢复。复现中,动态规则要求选择 B,实际选择了静态规则指定的 A。建议调整加载顺序,并补充完整初始化流程的测试。
初始读取可能覆盖更新的订阅事件
若 `GetRule` 返回前,listener 已处理更新或删除事件,随后无条件调用 `Process`
会重新应用旧快照,导致规则回退,甚至恢复已删除的规则。互斥锁只能保证串行写入,无法保证事件新旧顺序。建议记录订阅后的更新代次,避免旧快照覆盖新事件。
--
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]