Repository navigation
Conversation
- 将Core结构体中的innerMemCache替换为tableRegistry以统一管理表结构元数据 - HasTable函数优化为通过tableRegistry完成表存在性判断,提高查询效率 - SetTableFields改为通过registry缓存表字段信息,移除直接操作缓存的逻辑 - GetTablesWithCache改用registry缓存表名列表以避免重复数据库查询 - ClearTableFields及ClearTableFieldsAll改为操作registry,实现缓存清理 - TableFields获取及软时间字段缓存逻辑改为访问registry,去除冗余缓存层 - 删除与innerMemCache相关的缓存键生成及无用缓存代码 - 新增tableRegistry类型,实现线程安全的三维(group-schema-table)元数据缓存管理 - 修改相关调用逻辑以适配registry缓存体系,提升缓存一致性及并发性能
- 修改 GetLoadedSchemaTables 方法以跟踪完整表名列表是否已从数据库加载 - 添加 schemaKey 类型用于标识 (group, schema) 对以跟踪表列表加载状态 - 新增 loadedSchemas 映射跟踪哪些 (group, schema) 对的完整表名列表已加载 - 更新 Sets 方法记录完整表名列表已从数据库加载的信息 - 修改 ClearTableFields 方法保留表存在标记以避免数据库往返查询 - 更新 ClearAll 方法清除已加载模式标记确保下次访问重新查询数据库 - 在 gdb_func.go 中为 HasTable 调用添加模式参数支持
There was a problem hiding this comment.
Pull request overview
This PR refactors the database schema metadata caching mechanism in the database/gdb module by introducing a type-safe tableRegistry to replace the generic innerMemCache. The refactoring addresses correctness issues with multi-schema support, cache consistency, concurrent safety, and performance.
Changes:
- Introduced
tableRegistrywith three-dimensional addressing (group, schema, table) to replaceinnerMemCachefor schema metadata storage - Enhanced
HasTableandGetTablesWithCachewith optional schema parameters while maintaining backward compatibility - Refactored soft delete field caching to derive directly from the table fields registry, eliminating a separate cache layer
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| gdb_schema_table_registry.go | New file implementing type-safe registry for schema metadata with concurrent-safe operations |
| gdb.go | Updated Core struct to use registry instead of innerMemCache, removed obsolete cache prefix constant |
| gdb_core.go | Refactored HasTable to use O(1) registry lookup, GetTablesWithCache to support schema parameter, removed GetInnerMemCache method |
| gdb_core_utility.go | Updated ClearTableFields and ClearTableFieldsAll to work with registry, simplified ClearCacheAll |
| gdb_driver_wrapper_db.go | Refactored TableFields to use registry's GetOrSet with double-checked locking, removed cache imports |
| gdb_func.go | Updated HasTable calls to pass schema parameter, removed obsolete cache key generation functions |
| gdb_model_utility.go | Updated HasTable call to include schema parameter for correct table existence checking |
| gdb_model_soft_time.go | Refactored to derive soft time fields directly from registry, removed separate cache layer and related structures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@LanceAdd 该PR也很有意思,但影响面较大,也保持审核状态,预计在v3版本考虑合并。 |
|
我还不能可靠完成这次审查,建议请维护者协助确认一下。 原因是:目标分支当前提交上读不到这次审查需要的 建议关注:gdb schema 缓存重构;标题用了 如果方便的话,建议请以下成员协助:@wln32 @xgd16 @jianchenma 提及原因:这些成员处理过相关文件。 我暂时没有添加 |
|
表结构按 group/schema/table 收进
标题类型写成了 |
|
按 group/schema/table 把表结构收进
标题类型写成了 这几处还没改完,我没有打 |
变更概述
本次PR对
database/gdb模块的schema元数据缓存机制进行了全面重构,用类型安全的tableRegistry替代原有的innerMemCache,解决了多个正确性、一致性、并发安全和性能问题。主要改进
🎯 核心重构
tableRegistry作为schema元数据的唯一存储源(group, schema, table)三维寻址,彻底消除跨schema缓存混淆sync.RWMutex + map的组合,提供类型安全的并发访问🔧 问题修复
正确性问题:
HasTable和GetTablesWithCache添加schema参数支持一致性问题:
ClearTableFields现在会清除表的所有相关缓存ClearTableFieldsAll现在真正清除所有schema元数据并发安全问题:
性能优化:
HasTable从O(n)线性扫描优化为O(1)哈希查找🏗️ 架构优化
接口变更
向后兼容的增强
内部实现优化
SetTableFields签名保持不变,生成代码无需调整GetInnerMemCache()方法迁移说明
本次变更对现有用户代码完全向后兼容,无需任何代码修改即可享受性能提升和问题修复。