You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Ray7788 (via GitHub)" <gi...@apache.org> on 2026/02/01 12:59:40 UTC

[I] [讨论] dubbo-go metadata 报告 [dubbo-go]

Ray7788 opened a new issue, #3188:
URL: https://github.com/apache/dubbo-go/issues/3188

   ### 讨论详情
   
   1. https://github.com/apache/dubbo-go/tree/release-3.0/metadata 学习3.0 metadata模块代码
   2. 当前main分支 metadata代码学习
   3. 把dubbo-java metadata最新代码学习下
   
   产出目标:
   1. 当前dubbo go 3.3和3.0的metadata差异在哪
   2. 当前3.3 dubbo java 的metadata的差异
   
   ### 📚 相关背景
   
   _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: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [讨论] dubbo-go metadata 报告 [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on issue #3188:
URL: https://github.com/apache/dubbo-go/issues/3188#issuecomment-4582464870

   复盘下来,删减的直接原因很明确:**#2534 是按 #2432 的方案做的一次主动瘦身,不是误删**。
   
   时间线大概是这样:
   
   1. 2023-09 的 [#2432](https://github.com/apache/dubbo-go/issues/2432) 先把当时 metadata 模块梳理了一遍,指出 metadata 逻辑散在 `common/extension`、`config/instance`、`metadata/definition`、`metadata/identifier`、`metadata/service`、`registry/event` 等很多地方。
   2. #2432 的评论里给了“优化 draft”:目标是简化 metadata center 处理逻辑,把 metadata 逻辑集中到 `metadata` 模块。
   3. 2024-03 的 [#2534](https://github.com/apache/dubbo-go/pull/2534) 落地了这个方案,commit 是 `d6464e40 Refactor metadata`,一次性 `1703 insertions / 5227 deletions`。
   4. 后面 [#2760](https://github.com/apache/dubbo-go/pull/2760) 合 `dev-3.3` 时,又把这套删减后的形态带进开发线,所以现在看起来就是 metadata 被“大幅删了”。
   
   它当时的设计假设是:**dubbo-go 3.x 主要服务发现路径已经转向应用级服务发现,所以 metadata center 不再重点存 provider/consumer/service-definition 级元数据,只保留应用级 MetadataInfo、service-app mapping、MetadataService。**
   
   所以被删的核心东西是:
   
   - `metadata/definition`:provider service definition / method definition 这套被判断为“不再需要”
   - `metadata/identifier`:老的 service/provider/consumer identifier 被判断为“不再需要”
   - `metadata/service/local|remote|exporter`:拆开的 MetadataService 本地/远程/exporter 抽象被压扁到 [metadata_service.go](/dubbo-go/metadata/metadata_service.go:51)
   - `metadata/report/delegate`:带失败重试、周期上报、provider/consumer metadata 上报的 delegate 层被删
   - `common/extension/metadata_*`、`config/instance/metadata_report*`:扩展点和全局实例缓存被认为太分散,迁到/收缩到 metadata 包内部
   
   保留下来的新模型就是现在这套:`MetadataInfo` 作为应用级服务发现元数据容器,见 [metadata_info.go](/dubbo-go/metadata/info/metadata_info.go:58);`MetadataReport` 只负责 app metadata 和 mapping,见 [report.go](/dubbo-go/metadata/report/report.go:29);服务发现过程通过 revision 拿远端 app metadata。
   
   我觉得当时这个删减有它的工程动机:老 metadata 模块确实重、散、和 config/registry/server lifecycle 纠缠很深,而且很多能力对 dubbo-go 当时的应用级服务发现主路径不是必需的。但问题也很明显:**他们把“当前主路径不需要”处理成了“能力可以删除”**。这就导致现在如果目标变成“和 Dubbo Java metadata 完全对齐”,这些被删掉的 identifier、ServiceDefinition、完整 MetadataReport、retry/exporter 生命周期就又变成缺口了。


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [讨论] dubbo-go metadata 报告 [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl closed issue #3188: [讨论] dubbo-go metadata 报告
URL: https://github.com/apache/dubbo-go/issues/3188


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [讨论] dubbo-go metadata 报告 [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on issue #3188:
URL: https://github.com/apache/dubbo-go/issues/3188#issuecomment-4655699161

   [apache/dubbo-go#3360](https://github.com/apache/dubbo-go/pull/3360)
   [apache/dubbo-go#3362](https://github.com/apache/dubbo-go/pull/3362)
   [apache/dubbo-go#3367](https://github.com/apache/dubbo-go/pull/3367)
   [apache/dubbo-go#3369](https://github.com/apache/dubbo-go/pull/3369)
   [apache/dubbo-go#3370](https://github.com/apache/dubbo-go/pull/3370)
   [apache/dubbo-go#3371](https://github.com/apache/dubbo-go/pull/3371)
   [apache/dubbo-go#3373](https://github.com/apache/dubbo-go/pull/3373)


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [讨论] dubbo-go metadata 报告 [dubbo-go]

Posted by "zbchi (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [讨论] dubbo-go metadata 报告 [dubbo-go]

Posted by "Ray7788 (via GitHub)" <gi...@apache.org>.
Ray7788 commented on issue #3188:
URL: https://github.com/apache/dubbo-go/issues/3188#issuecomment-3831019780

   @ zhu zecheng
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org