zbchi commented on issue #3188:
URL: https://github.com/apache/dubbo-go/issues/3188#issuecomment-3918277902
## 目录结构
### dubbo-Java
```
dubbo-metadata/
├── dubbo-metadata-api/ # 核心接口
│ └── org/apache/dubbo/metadata/report/
│ ├── identifier/ # Identifier 系统
│ │ ├── BaseMetadataIdentifier.java
│ │ ├── MetadataIdentifier.java
│ │ ├── ServiceMetadataIdentifier.java
│ │ └── SubscriberMetadataIdentifier.java
│ ├── MetadataReport.java # 完整接口
│ ├── MetadataReportFactory.java
│ ├── MetadataScopeModelInitializer.java
│ └── support/ # 抽象基类
│ └── AbstractMetadataReport.java
│
├── dubbo-metadata-definition-protobuf/ # ServiceDefinition
├── dubbo-metadata-processor/ # 注解处理器
└── dubbo-metadata-report-*/ # 实现
├── nacos/
└── zookeeper/
```
---
### dubbo-go-3.0
```
metadata/
├── definition/ # ServiceDefinition 支持
│ ├── definition.go
│ └── mock.go
│
├── identifier/ # Identifier 系统
│ ├── base_metadata_identifier.go
│ ├── metadata_identifier.go
│ ├── service_metadata_identifier.go
│ └── subscribe_metadata_identifier.go
│
├── mapping/ # 服务名映射
│ ├── memory/ # 内存实现
│ └── metadata/ # 元数据中心实现
│ ├── service_name_mapping.go
│ └── ...
│
├── report/ # MetadataReport 实现
│ ├── delegate/ # 委托模式
│ │ └── delegate_report.go
│ ├── etcd/
│ ├── nacos/
│ ├── zookeeper/
│ └── factory/
│ └── report_factory.go
│
└── service/ # 元数据服务
├── exporter/ # 服务导出器
│ └── configurable/
├── local/ # 本地元数据
└── remote/ # 远程元数据
└── service.go
```
---
### dubbo-go-current
```
metadata/
├── info/ # MetadataInfo 定义
├── mapping/ # 服务名映射
│ ├── service_name_mapping.go # 接口定义
│ └── metadata/
│ └── service_name_mapping.go # 实现但包名是 metadata
├── report/ # MetadataReport 实现
│ ├── etcd/
│ ├── nacos/
│ └── zookeeper/
├── triple_api/ # Triple 协议支持
│ └── proto/
│
├── metadata.go # 全局可变状态
├── metadata_service.go
├── client.go
├── options.go # 配置
├── report_instance.go # 委托模式
└── metadata_service_test.go
```
---
## 核心功能
### Identifier系统
| 功能 | dubbo-metadata (Java) | dubbo-go-3.0
| dubbo-go (current) |
| -------------- | ---------------------------- |
---------------------------- | ------------------ |
| **标识符接口** | BaseMetadataIdentifier | IMetadataIdentifier |
x缺失 |
| **应用级标识** | MetadataIdentifier | MetadataIdentifier |
x缺失 |
| **服务级标识** | ServiceMetadataIdentifier | ServiceMetadataIdentifier |
x缺失 |
| **订阅者标识** | SubscriberMetadataIdentifier | SubscriberMetadataIdentifier |
x缺失 |
| **Key 生成** | getIdentifierKey() | GetIdentifierKey()
| x各自手拼 |
| **Path 生成** | getFilePathKey() | GetFilePathKey()
| x缺失 |
| **参数组合** | 可变参数支持 | 可变参数支持 | x缺失
|
```java
// java: 标准化 key 生成
MetadataIdentifier id = new MetadataIdentifier(...);
String key = id.getIdentifierKey(); //
"my-app.com.example.UserService:1.0.0:provider"
```
```go
// dubbo-go-3.0: 标准化 key 生成
identifier := identifier.NewMetadataIdentifier(...)
key := identifier.GetIdentifierKey()
```
```go
// dubbo-go (current): 手动拼接
// nacos/report.go
DataID: application
// zookeeper/report.go
Path: "/dubbo/" + application + "/metadata/"
// 格式不统一,容易出错
```
---
### MetadataReport 接口
| 方法 | java、 3.0 | current
| |
| --------------------------------- | ------------------------------- |
------- | ---- |
| **应用级元数据** | | |
|
| - publishAppMetadata | PublishAppMetadata | 存在
| |
| - getAppMetadata | GetAppMetadata | 存在
| |
| - unPublishAppMetadata | UnPublishAppMetadata | x
| |
| **服务级元数据** | | |
|
| - storeProviderMetadata | StoreProviderMetadata | x
| |
| - getServiceDefinition | GetServiceDefinition | x
| |
| - storeConsumerMetadata | StoreConsumerMetadata | x
| |
| **URL 管理** | |
| |
| - saveServiceMetadata | SaveServiceMetadata | x
| |
| - removeServiceMetadata | RemoveServiceMetadata | x
| |
| - getExportedURLs | GetExportedURLs | x
| |
| - saveSubscribedData | SaveSubscribedData | x
| |
| - getSubscribedURLs | GetSubscribedURLs | x
| |
| **服务映射** | |
| |
| - registerServiceAppMapping | RegisterServiceAppMapping | 存在
| |
| - getServiceAppMapping | GetServiceAppMapping | 存在
| |
| - removeServiceAppMappingListener | RemoveServiceAppMappingListener | 存在
| |
| **生命周期** | |
| |
| - destroy | 存在 | x
| |
---
### 3. ServiceDefinition 支持
| 功能 | java、3.0 | current | 影响
|
| -------------------------- | ----------------- | ------- |
-------------------- |
| **ServiceDefinition 接口** | ServiceDefiner | x | 无法存储详细服务定义 |
| **完整定义模型** | ServiceDefinition | x | 只有MetadataInfo |
| **方法级别信息** | MethodDefinition | x | 缺失方法签名 |
| **参数类型信息** | TypeDefinition | x | 缺失参数详情 |
| **JSON 序列化** | ToBytes() | x | 性能优化缺失 |
| **Protobuf 支持** | 支持 | x | 与java不兼容 |
**对比**:
```java
// Java & 3.0: 完整的服务定义
ServiceDefinition {
CanonicalName: "com.example.UserService",
Methods: [...],
Types: [...]
}
```
```go
// current: 只有基本信息
MetadataInfo {
App: "my-app",
Services: [...], // 缺少方法详情
}
```
---
### 架构
metadata_service.go 混合了五种职责,应当拆分为
```
service/
├── interface.go
├── service.go # 默认实现
├── exporter.go # 服务导出器
├── adapters.go # V2 协议适配器
└── service_info.go # 协议服务信息定义
```
```
├── mapping/ # 映射模块
│ ├── service_name_mapping.go # 接口
│ └── metadata/ # 子目录(包名冲突)
```
/metadata/mapping/ -定义接口 package mapping
/metadata/mapping/metadata/ 实现接口但声明为 package metadata
/metadata/*.go 主包也是 package metadata
应重构为
```
├── mapping/ # 服务名映射
│ ├── interface.go # ServiceNameMapping 接口
│ ├── impl.go # 实现 (合并 metadata 子目录)
│ └── (删除 metadata 子目录)
```
另外,服务导出器缺少关键方法,
```go
// 3.0接口实现
type MetadataServiceExporter interface {
Export(url *common.URL) error
Unexport() // 取消导出
GetExportedURLs() []*common.URL // 有获取 URL
IsExported() bool // 状态查询
}
//current 直接实现
type serviceExporter struct {
opts *Options
service MetadataService
protocolExporter base.Exporter
v2Exporter base.Exporter
}
func (e *serviceExporter) Export() error { ... }// 只有Export()方法
```
---
### 重试与容错
| 功能 | Java | 3.0 | current
|
| ----------------------- | ----------------- | ------------------- |
------------------- |
| **MetadataReportRetry** | 统一调度器 | metadataReportRetry | 分散的for循环
|
| **可配置次数** | 可用 | 可用 |
硬编码retryTimes=10 |
| **可配置间隔** | 可用 | 可用 | 无
|
| **失败追踪** | failedReports Map | retryCounter | 缺失
|
| **指数退避** | 可用 | 可用 | 无
|
代码对比:
```java
// java: 统一重试调度器
metadataReportRetry.startRetryTask(); // 自动重试失败项
```
```go
// 3.0: 统一重试机制
retry := newMetadataReportRetry(period, limit)
retry.startRetryTask()
```
```go
// current: 分散的重试逻辑
const retryTimes = 10
for i := 0; i < retryTimes; i++ {
if err = metadataReport.RegisterServiceAppMapping(...); err == nil {
break
}
// 无间隔,无退避
}
```
---
### 本地文件缓存
| 功能 | Java、3.0 | current | 影响 |
| ---------------- | ------------------ | ----------------- | ---- |
| **本地缓存文件** | Properties | 缺失 | |
| **文件锁** | FileLock | 多进程冲突 | |
| **同步/异步** | syncReport 参数 | 无选择 | |
| **定时保存** | 调度器 | 数据丢失 | |
| **优雅降级** | 缓存失败不影响启动 | 缓存失败=启动失败 | |
需远程拉取全部元数据,元数据中心故障=无法启动,重复请求网络压力大
---
### 服务导出器
| 功能 | Java | 3.0 | current
|
| --------------------------- | -------- | ----------------------- |
-------------- |
| **MetadataServiceExporter** | 完整接口 | MetadataServiceExporter | 混乱
|
| **Export/Unexport** | 存在 | 存在 | 混在其他代码中 |
| **GetExportedURLs** | 存在 | 存在 | 缺失
|
| **IsExported** | 存在 | 存在 | 缺失
|
---
### 配置管理
| 功能 | Java | 3.0 | current |
| ---------------------- | --------------- | ---- | ------- |
| **MetadataScopeModel** | 统一配置模型 | 存在 | 部分 |
| **动态配置获取** | getConfigItem() | 部分 | 缺失 |
##
---
## 关键问题
| 功能 | Java | 3.0 | current |
| -------------------- | ----- | ---- | ------- |
| Identifier系统 | 存在 | 存在 | x |
| ServiceDefinition | 存在 | 存在 | x |
| MetadataReport完整度 | 10/10 | 8/10 | 3/10 |
| 本地文件缓存 | 存在 | 存在 | x |
| 统一重试机制 | 存在 | 存在 | x |
| 服务导出器抽象 | 存在 | 存在 | x |
| 配置动态获取 | 存在 | 存在 | 可选 |
| 架构差异 | | | |
--
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]