Alanxtl commented on PR #3320:
URL: https://github.com/apache/dubbo-go/pull/3320#issuecomment-4417568213

   要废弃 `config`,核心原则应该是:
   
   **`global / InstanceOptions` 是唯一 source of truth;`config` 只能作为旧 API/旧 YAML 
的输入适配器,不能再参与新初始化主链路。**
   
   现在 PR 的问题是:它只是删掉最后一次 config -> global 覆盖,但初始化仍然主要发生在 `rcCompat 
*config.RootConfig` 上。这会导致两头都不稳:global-only 字段可能还会在 config-center 路径丢失,config 
初始化出来的默认值又同步不回 global。
   
   
   
   
   
   
   
   
   
   
   
   我建议这样改。
   
   **推荐方案**
   1. **把 `InstanceOptions.init` 改成 global-native 初始化**
      
      不要再这样:
   
      ```text
      global -> compatRootConfig -> config.Init -> compatInstanceOptions -> 
global
      ```
   
      改成:
   
      ```text
      global.InstanceOptions
        -> global/default/validate/normalize/init
        -> set config.RootConfig mirror only for legacy GetRootConfig
      ```
   
      也就是说,`compatRootConfig(rc)` 最多只在最后做镜像:
   
      ```go
      setCompatRootConfig(compatRootConfig(rc))
      ```
   
      不能再反过来覆盖 `rc`。
   
   2. **把 `config.*.Init()` 里的逻辑搬到 global 初始化层**
   
      这些逻辑现在仍然有价值,但不应该挂在 `config` 类型上:
   
      - defaults.Set
      - validate
      - registry address 翻译:`zookeeper://127.0.0.1:2181` -> 
`Protocol=zookeeper, Address=127.0.0.1:2181`
      - provider/consumer registry ids 展开
      - service/reference 继承 application group/version
      - protocol 默认值
      - metrics/otel/logger/shutdown 初始化
   
      可以先放在 `dubbo` 包或 `internal/configinit` 包里,操作 `global.*Config`。不一定要放到 
`global` 包本身,避免让 `global` 从纯数据包变成重依赖包。
   
   3. **`config` 入口只做一次转换**
   
      未来语义应该是:
   
      ```text
      config.Load / config.WithRootConfig
        -> parse old config.RootConfig
        -> convert to global.InstanceOptions
        -> run global init
      ```
   
      注意:这里是“旧入口转成新模型”,不是运行时一直维护两个主模型。
   
      包依赖上要小心:`config` 包现在不能直接 import 根包 `dubbo`,否则容易循环依赖。比较干净的做法是把 canonical 
runtime config 放到一个较低层包,比如 `internal/runtimeconfig` 或把 `InstanceOptions` 下沉到可被 
`dubbo` 和 `config` 都引用的位置。
   
   4. **config-center 也要改成写 global**
   
      当前 [options.go](/home/lxt/repo/dubbo-go/options.go:98) 走的是:
   
      ```go
      rcCompat.ConfigCenter.Init(rcCompat)
      ```
   
      这会把远端配置 unmarshal 到 `config.RootConfig`。废弃 config 后,应该有一条 global 版本:
   
      ```go
      initGlobalConfigCenter(rc *InstanceOptions)
      ```
   
      远端配置直接 merge/unmarshal 到 `InstanceOptions`。旧格式的 config-center 
配置可以作为兼容路径:先 parse 成 `config.RootConfig`,再 adapter 到 global,但最终仍然写 global。
   
   5. **保留 `config.GetRootConfig()` 只是镜像**
   
      很多老代码可能还会调用 `config.GetRootConfig()`。过渡期可以保留,但它应该是初始化完成后的只读兼容快照:
   
      ```go
      setCompatRootConfig(compatRootConfig(globalFinal))
      ```
   
      运行时行为不要再依赖它作为主配置。
   
   **PR #3320 当前应该怎么改**
   短期不要只删最后的 `compatInstanceOptions`。更合理的是:
   
   - 删除或替换 config-center 成功分支里的早期 `compatInstanceOptions(rcCompat, rc)`
   - 让初始化逻辑直接作用在 `rc *InstanceOptions`
   - 最后用 finalized global 生成 `config.RootConfig` 镜像
   - 补测试:
     - `ClosingInvokerExpireTime` 在 config-center 成功路径不丢
     - `TripleConfig.Cors/OpenAPI` 不丢
     - `TLSConfig` 在 `config.GetRootConfig()` 镜像里可见
     - protocol 默认值 `name=tri, port=50051` 初始化后能被 `NewServer()` 拿到
     - registry 地址 `zookeeper://...` 初始化后 metadata report/client/server 
使用的是翻译后的值
   
   一句话:**不要修 round-trip,要消灭 round-trip。** `config` 
以后只负责“旧输入转新模型”,不能再成为初始化过程里的中间主模型。


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