0x-infinity opened a new issue, #1022:
URL: https://github.com/apache/incubator-seata-go/issues/1022
### 讨论详情
## 问题背景
`pkg/remoting/config/config.go` 中的 `SeataConfig`
结构体设计不够合理,把不同层次的配置混在一起,导致模块职责不清晰。
**当前代码** (`pkg/remoting/config/config.go`)
```go
// todo refactor config
type SeataConfig struct {
ApplicationID string
TxServiceGroup string
ServiceVgroupMapping flagext.StringMap
ServiceGrouplist flagext.StringMap
LoadBalanceType string
}
```
## 核心问题
### 1. 配置归属混乱
这个结构体把三种不同的配置混在了一起:
- `ApplicationID`, `TxServiceGroup` → 本该属于 remoting 层
- `ServiceVgroupMapping`, `Grouplist` → 本该属于 discovery 包
- `LoadBalanceType` → 本该属于 getty 包
### 2. 存在冗余字段
`ServiceVgroupMapping` 和 `ServiceGrouplist` 在 `SeataConfig`
里其实**根本没被用到**,真正用它们的地方是 `pkg/discovery/file.go`,从 `discovery.ServiceConfig` 读取。
在 `pkg/client/client.go` 做了无意义的数据搬运:
```go
seataConfig := remoteConfig.SeataConfig{
ApplicationID: cfg.ApplicationID,
TxServiceGroup: cfg.TxServiceGroup,
ServiceVgroupMapping: cfg.ServiceConfig.VgroupMapping, // 从 discovery
拷贝过来
ServiceGrouplist: cfg.ServiceConfig.Grouplist, // 从 discovery
拷贝过来
LoadBalanceType: cfg.GettyConfig.LoadBalanceType, // 从 getty 拷贝过来
}
```
### 3. 使用了全局变量
配置通过全局变量共享,测试不友好,依赖关系也不明确:
```go
var seataConfig *SeataConfig
func GetSeataConfig() *SeataConfig {
return seataConfig
}
```
被多处调用:
- `pkg/remoting/getty/listener.go`
- `pkg/remoting/getty/session_manager.go`
### 4. 错误的数据流向
当前流程:
```
Config (client/config.go)
└─> remoting.SeataConfig (临时聚合)
└─> 全局变量(到处访问)
├─> getty 使用 LoadBalanceType
└─> discovery 需要 VgroupMapping/Grouplist (但从其他地方获取)
```
期望流程:
```
Config (client/config.go)
├─> discovery.ServiceConfig (VgroupMapping, Grouplist)
│ └─> discovery.Registry (直接使用)
└─> getty.Config (LoadBalanceType)
└─> getty.SessionManager (直接使用)
```
### 📚 相关背景
_No response_
--
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]