feat: 边缘查询 scan + 谓词下推——只回传命中切片(方向 B,热窗口)#139
Conversation
为边缘查询提供存储层基础: - SkipList.firstGTE 定位起点,level-0 有序遍历 - ScanRange 全程持读锁,2 路归并 active(最新)+dirty,新值优先、墓碑遮蔽 - start/end 空表示该侧不限;fn 返回 false 提前停止 - Engine.Scan 转发;当前仅覆盖未刷盘热数据,SSTable 历史待 Phase 2 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
支持 > >= < <= == !=,数值/字符串自动判别;无谓词全匹配。 覆盖具身采集常见查询(如 az>9.9 / status==ok),不引入完整表达式语言。 纯函数、零业务依赖,供边缘查询服务端筛选、只回传命中切片。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- pkg/proto: SCAN msgID 与请求/响应 wire 编解码(server/client 共用) - KVServer.Scan: 扫 MemTable 热数据,谓词下推筛选,命中拷贝返回,10000 条封顶并告警 - router.handleScan + 两个 Server 注册 SCAN 路由 - metrics 增 Scans 计数并入快照 谓词由钩子放行(仅 PUT 过滤),SCAN 原样直达。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- client.SendScan 编解码 SCAN 请求/响应 - 交互式 scan <start|-> <end|-> [field op operand],- 表示该侧不限 - service 集成测试:写 IMU 帧→范围+谓词扫描→只回命中、越界设备排除 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 30 minutes and 17 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (21)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🐯 BanGD 数据库内核评审整体风险:🟡 中 变更总结:本 PR 在 BanDB 存储引擎的热路径——MemTable 层新增了范围扫描(ScanRange)功能,并配合前端的谓词下推(predicate)、wire 编解码、交互式客户端与网络包上限调整,端到端实现了「边缘本地范围查询 + 服务端筛选后只回传命中切片」的能力。 核心改动集中在四层:
注释已标注 Phase 2 边界:历史 SSTable 数据暂未接入,当前仅扫 MemTable 热窗口。
架构问题(共 4 项)
普通问题(共 3 项)🛑 [阻塞 · 逻辑错误]
💡 [建议 · 逻辑错误]
💡 [建议 · 错误处理]
本次评审消耗 token:共 323462 tokens(输入 303072,输出 5926,缓存命中 14464,缓存写入 0)|维度 [concurrency, memory, lock, storage, performance]|对抗式复核 3 票/条,过滤疑似误报 0 条 |
1024B 上限会让客户端 UnPack 拒收多条 SCAN 响应,也使 >1KB 的相机帧无法 PUT (UnPack 对收发双方都生效)。提到 16MiB 容纳多模态大值与范围查询结果。 新增 banNet 网络缝回归测试:200 条命中的响应需完整通过 Pack→UnPack→解码。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
背景(采集员痛点 #3:查不动数据)
此前只有 PUT/GET/DELETE,想「把刚才 10s 内 az>9.9 的帧捞出来只传这一段」做不到。本 PR 把边缘本地查询 + 只回传命中切片端到端跑通。
范围(已与用户确认:热窗口)
v1 扫 MemTable 未刷盘热数据——正好是采集员最常查的「最近窗口」。已刷盘到 SSTable 的历史数据为 Phase 2(需把 mergeIterator 泛化+跨层新值优先+并发快照,已在代码注释标注边界)。
改动(4 个原子 commit)
MemTable.ScanRange:闭区间升序、firstGTE定位、2 路归并 active(最新) 覆盖 dirty、跳墓碑、fn可提前停;全程持读锁(热窗口扫描有界)field op value(> >= < <= == !=,数值/字符串自动判别),纯函数SCANmsgID + wire 编解码(server/client 共用)+KVServer.Scan(谓词下推、命中拷贝、10000 封顶并告警)+ 路由注册 +metrics.ScansSendScan+ 交互式scan <start|-> <end|-> [field op operand]差异化
谓词在服务端下推,只把命中切片回传——这是「GB→MB」的核心,也是 MCAP/Zenoh/COS 都不在采集入口做的那件事。
测试
scan [imu:dev0:100,imu:dev0:299] az>9.9→ 只回 2 条命中、越界设备 dev1 被范围排除go build ./...通过,既有测试无回归用法:
🤖 Generated with Claude Code