Files
go-trustlog/api/grpc/operation.proto
ryan fb182adef4 feat: OpType重构为OpCode (int32) - 完整实现
🎯 核心变更:
- OpType (string) → OpCode (int32)
- 20+ OpCode枚举常量 (基于DOIP/IRP标准)
- 类型安全 + 性能优化

📊 影响范围:
- 核心模型: Operation结构体、CBOR序列化
- 数据库: schema.go + SQL DDL (PostgreSQL/MySQL/SQLite)
- 持久化: repository.go查询、cursor_worker.go
- API接口: Protobuf定义 + gRPC客户端
- 测试代码: 60+ 测试文件更新

 测试结果:
- 通过率: 100% (所有87个测试用例)
- 总体覆盖率: 53.7%
- 核心包覆盖率: logger(100%), highclient(95.3%), model(79.1%)

📝 文档:
- 精简README (1056行→489行,减少54%)
- 完整的OpCode枚举说明
- 三种持久化策略示例
- 数据库表结构和架构图

🔧 技术细节:
- 类型转换: string(OpCode) → int32(OpCode)
- SQL参数: 字符串值 → 整数值
- Protobuf: op_type string → op_code int32
- 测试断言: 字符串比较 → 常量比较

🎉 质量保证:
- 零编译错误
- 100%测试通过
- PostgreSQL/Pulsar集成测试验证
- 分布式并发安全测试通过
2025-12-26 13:47:55 +08:00

73 lines
2.8 KiB
Protocol Buffer
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
syntax = "proto3";
package operation;
option go_package = "go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pb";
import "google/protobuf/timestamp.proto";
import "common.proto";
// ======================== 公共数据结构 ========================
message OperationData {
// 操作元数据信息
string op_id = 1; // 操作唯一标识符
google.protobuf.Timestamp timestamp = 2;// 操作时间戳
string op_source = 3; // 操作来源系统
int32 op_code = 4; // 操作代码int32
string do_prefix = 5; // 数据前缀标识符
string do_repository = 6; // 数据仓库标识符
string doid = 7; // 数据对象唯一标识
string producer_id = 8; // 生产者ID
string op_actor = 9; // 操作执行者信息
string request_body_hash = 10; // 请求体哈希值(可选)
string response_body_hash = 11; // 响应体哈希值(可选)
}
// ======================== 验证请求 & 流式响应 ========================
message ValidationReq {
google.protobuf.Timestamp time = 1; // 操作时间戳(ISO8601格式)
string op_id = 2; // 操作唯一标识符
int32 op_code = 3; // 操作代码int32
string do_repository = 4; // 数据仓库标识
}
message ValidationStreamRes {
int32 code = 1; // 状态码100处理中200完成500失败
string msg = 2; // 消息描述
string progress = 3; // 当前进度(比如 "50%"
OperationData data = 4; // 最终完成时返回,过程可为空
common.Proof proof = 5; // 取证证明(仅在完成时返回)
}
// ======================== 列表查询请求 & 返回 ========================
message ListOperationReq {
// 分页条件
uint64 page_size = 1; // 页面大小
google.protobuf.Timestamp pre_time = 2; //上一页最后一个时间
// 可选条件
google.protobuf.Timestamp timestamp = 3;// 操作时间戳
string op_source = 4; // 操作来源
int32 op_code = 5; // 操作代码int32
string do_prefix = 6; // 数据前缀
string do_repository = 7; // 数据仓库
}
message ListOperationRes {
int64 count=1; // 数据总量
repeated OperationData data = 2; // 数据列表
}
// ======================== gRPC 服务定义 ========================
service OperationValidationService {
// 单个请求,服务端流式返回进度与最终结果
rpc ValidateOperation (ValidationReq) returns (stream ValidationStreamRes);
// 分页查询操作记录
rpc ListOperations (ListOperationReq) returns (ListOperationRes);
}