godocdb/design/tasks/017-storage_compact_mode.md

31 lines
907 B
Markdown
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.

# 017-存储层紧凑模式设计
## 目标
实现存储层紧凑模式通过共享LevelDB实例优化资源使用
## 子任务
1. 创建StorageManager结构体storage/storage.go
- 实现NewStorageManager工厂函数
- 添加GetDB()方法供测试使用
2. 修改DocumentStore使用共享db实例
- 移除直接创建LevelDB的代码
- 使用StorageManager获取数据库实例
3. 修改IndexStore使用共享db实例
- 同步调整索引存储实现
- 确保索引操作兼容性
4. 添加资源管理接口
- Close()方法优雅关闭数据库
- 错误处理机制完善
## 技术要点
- 确保StorageManager的单例模式实现
- 处理数据库连接的生命周期管理
- 验证不同store操作是否互不影响
## 测试验证
- 验证多个store实例是否共享同一个db实例
- 测试db连接泄漏问题
- 性能对比测试(内存/CPU使用率