Repository navigation
[4.2-dev] fix(disttae): preserve RowEntry snapshot isolation during replay - #32616
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
This pull request is merged. |
LeftHandCold
left a comment
There was a problem hiding this comment.
复审结论:当前 revision 未发现需要阻断的代码问题,支持这个最小范围的 4.2 回补。当前账号也是 PR 作者,因此这里只提交 COMMENT,不作为独立 reviewer 的 APPROVE,也不替代 CI/仓库合并门禁。
核对范围:4.2-dev 51c0af67a207 → 598b782e3d2c,完整阅读两个变更文件,并追踪 Partition 发布、普通行扫描、主键迭代、数据源/CDC batch 消费以及行/索引 GC。
设计与正确性
- 修复放在已有的两个行回放写入口:命中已有物理版本后先复制 RowEntry,再通过原来的 B-tree Set/Partition 发布路径替换。没有新增状态机、读者锁或另一套回放逻辑;对应 main #30617 的两处 COW 修复,不携带其 CLUSTER BY 功能。
- 浅复制在这里足够:后续写入替换 Batch 指针、Offset、Deleted 和主键字节切片,并不原地修改旧 batch payload/旧 key 字节。已检查的扫描和 CDC 消费路径将数据写入自己的输出 batch。无需深复制整个 payload。
- 保留 RowEntry.ID、物理键和时间戳,不改变主键索引的版本匹配及 GC 查找;仍保留原有 delete-wins 语义,重复插入不会复活同版本删除。新版本首次插入路径不变。
- 发布前修改不再泄漏给旧快照;即使新状态最终没有发布,旧行条目也不受影响。
Unhappy path 与性能
- Q1:新条目和旧条目均由保留它们的树/读者引用及 Go GC 管理;没有引入手动 Free、引用计数或双重清理责任。
- Q2:没有新增生产锁、channel、后台任务或等待链。测试中的有限读者在断言和资源清理前已收回。
- Q3:是原键替换,不是追加新版本历史;旧对象随快照释放后可回收,没有新增常驻 registry。
- 代价不是零:已有 benchmark 的对照结果为每次命中已有版本增加 1 次分配、112 B;不复制 batch payload,不增加编码和树查找。旧快照会继续保留其原 batch,因此保留内存不能简单理解为只有 112 B,这属于快照隔离应有的生命周期成本。微基准不等同于生产吞吐保证。
验证证据与边界
本次核对并复用同一代码 revision 的本地证据,没有重复启动大规模 UT:
- 相同新测试在修复前 8 个场景全部失败;race 报告直接指向 HandleRowsInsert/Delete 与保留快照读者的冲突。
- 修复后 8 个场景通过,覆盖重复插入/删除、同版本插删两种顺序、noData 两种模式、batch 重排、发布前后、真实行扫描和主键迭代。
- owning logtailreplay 包普通/race 测试通过;定向
-race -count=100通过;scoped vet/molint/增量 lint 及 diff 检查通过。以上本地运行平台为 Darwin arm64。 - 查询时 GitHub Linux UT、coverage、SCA/shared build 等仍在运行,不能视为已经通过;MongoDB E2E 已通过。
该证据确认的是共享 RowEntry 的 COW/并发缺陷及本补丁的修复效果,不证明某次生产事故发生了重复回放,也不能据此承诺此前的连续空结果事故已定位或修复。
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 598b782e3d2c03f3044c2ad05d51eea3012d2c84
Assessment: approve
The narrow copy-on-write fix preserves published RowEntry values, identity and delete precedence. It reuses existing replacement/publication paths without copying immutable payloads or adding synchronization.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
Reviewed both changed files, all four discussion entries, linked issue and affected publication/reader/CDC/GC consumers.
-
Unchanged regression fails all eight baseline cases; fixed focused race passes all eight. Adaptive 100-repeat race check passes 100 roots and 800 subcases.
-
Normal and race owning-package runs each pass 146 root tests, with one existing skip.
-
Allocation controls confirm +112 B and one allocation per existing-key replay. Build, vet, formatting and diff checks pass.
-
Final audit verified clean source and correlated 15 execution receipts with retained logs.
Limitations:
-
TestCountTombstoneRowsWithRealObject remains skipped.
-
Validation covers the replay component; production duplicate delivery and incident root cause remain unproven.
-
Allocation measurements do not establish production throughput or total retained memory; old snapshots retain their original payloads.
What type of PR is this?
Which issue(s) this PR fixes:
issue #32613
What this PR does / why we need it:
Backport only the existing-RowEntry copy-on-write correction from main #30617 (
b58d92746d619a9313fe48590eb1d491f5fe8056) to 4.2-dev. Base:51c0af67a207f7a30dddb4bc385c3466ae5696de.PartitionState.Copy()copies B-tree nodes, not the*RowEntryelements they reference. Both row handlers previously mutated an already-published entry when replay matched its(BlockID, RowID, Time). The unpublished mutation therefore escaped into old snapshots and raced their readers.This is not a full cherry-pick: no composite CLUSTER BY feature, batch-compaction change, new lock/cache/state machine, public API, persisted format, or TN protocol change is included. The incident's duplicate-delivery/overlap precondition remains unproven; this PR fixes the demonstrated replay ownership defect, not a claimed incident root cause.
Validation
macOS arm64, Go 1.26.4, native libraries freshly built from this 4.2 base (
make -j2 cgo). Go validation usesGOMAXPROCS=2,GOMEMLIMIT=3GiB,-p=1, explicit TMPDIR, and the repository CGo test wrapper.-race-race -count=100go vet, repositorymolint, configured golangci-lint v2.6.2 built with Go 1.26.4git diff --checkTested with:
No new SQL BVT: SQL cannot directly request replay of an identical physical row version with a different batch position. The regression exercises the real replay handlers, publication, scan and PK iterator contracts without sleeps, a cluster, or a probabilistic SQL reproducer. No end-to-end incident reproduction is claimed.
Cost and self-review
Existing one-row repeated-replay benchmarks (
-benchtime=100ms -count=3, same toolchain) show exactly +112 B and +1 allocation per existing-key replay for both handlers (INSERT: 1056→1168 B/op; DELETE: 1392→1504 B/op). No payload copy or new-key allocation is added. This is a local allocation check, not a claim about production throughput.Focused bug fix: no feature design document needed. Both handler branches and their row/PK readers have been reviewed; compatibility, delete precedence and identity are preserved. No merge or release is requested by this PR.