Repository navigation
fix(logtail): reduce consumer backlog pressure - #24323
mergify[bot] merged 3 commits into
Conversation
Co-authored-by: Copilot <[email protected]>
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
There was a problem hiding this comment.
Pull request overview
This PR targets CN-side logtail consumer backpressure seen in write-heavy workloads (issue #24322) by removing redundant per-routine timestamp commands for update responses that already carry table logtails, and by making timestamp waiter notifications non-blocking and coalesced.
Changes:
- Coalesce per-routine “applied timestamp” advancement into the last table-logtail command for that routine (and skip timestamp-only commands for those routines).
- Make
timestampWaiter.NotifyLatestCommitTSnon-blocking and coalesce notifications to the latest timestamp via an atomic pointer. - Add focused unit tests covering both behaviors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/vm/engine/disttae/logtail_consumer.go | Coalesces per-routine applied timestamp advancement into the last table-logtail command to reduce consumer queue pressure. |
| pkg/vm/engine/disttae/logtail_consumer_test.go | Adds a test ensuring update responses avoid redundant timestamp-only commands for routines that already receive table logtails. |
| pkg/txn/client/timestamp_waiter.go | Makes commit-ts notifications non-blocking and coalesces them to the latest timestamp to avoid blocking logtail consumers. |
| pkg/txn/client/timestamp_waiter_test.go | Adds tests verifying non-blocking notify behavior and bounded draining in fetchLatestTS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
LeftHandCold
left a comment
There was a problem hiding this comment.
Reviewed the latest head e11668b against issue #24322 and the existing review thread.
I checked the timestamp waiter coalescing path and the logtail consumer timestamp advancement semantics: routines that receive table logtails now advance applied time only after consuming the last logtail for that response, while routines without table logtails still get timestamp-only commands, so the global min applied timestamp remains conservative. The redundant timestamp wakeup comment is addressed by only enqueueing a wakeup when the pending notified timestamp advances.
Local targeted validation passed for pkg/txn/client and pkg/vm/engine/disttae, including the race timestamp-waiter tests and the new dispatch update response tests. I do not see remaining correctness blockers. Two Upgrade CI launch checks are still pending, so merging should still wait for those to complete.
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM. Well-targeted fix for the logtail consumer backlog issue.
Problem
Under write-heavy load, every UpdateResponse sends N table logtail commands + 1 separate cmdToUpdateTime to every consumer routine. The timestamp commands are redundant for routines that already receive table logtails, but still occupy channel slots. Combined with the blocking NotifyLatestCommitTS (which blocks when the 64-slot channel is full), this cascades into signal-chan-len reaching 7000+.
Fix correctness
Logtail timestamp coalescing:
- For routines with table logtails: timestamp is piggybacked on the last table logtail command (
notifyApplied=true), eliminating the separatecmdToUpdateTime - Applied timestamp only advances after the last logtail is consumed — this preserves the invariant that "routine X's applied ts = latest fully-consumed response"
- Routines without logtails still receive standalone
cmdToUpdateTime— global min applied timestamp semantics preserved
Non-blocking timestamp waiter:
notifiedCbecomes a pure signal channel (chan struct{})- Actual timestamp stored via CAS in
atomic.Pointer(monotonically increasing viaGreaterEqcheck) NotifyLatestCommitTSnever blocks: CAS-store the max ts, then non-blocking signal send- No data loss: even if signals are dropped,
handleEventwakeup reads the latest ts from the atomic pointer fetchLatestTSbounds drain tomaxNotifiedCountiterations — prevents unbounded loop under burst
Pool hygiene: cmdToConsumeLog fields zeroed before Put back to pool — prevents stale logtail data leakage on reuse.
Tests cover: non-blocking under full channel, redundant wakeup skip, bounded drain, coalescing verification, and timestamp advancement ordering.
Merge Queue Status
This pull request spent 11 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
gouhongshen
left a comment
There was a problem hiding this comment.
🔍 Code Review Report — 七人陪审团
📊 概览
| 指标 | 值 |
|---|---|
| 审查文件数 | 4 |
| 总发现数 | 7 |
| 🔴 Must Fix | 0 |
| 🟡 Should Fix | 3 |
| 🟢 Nit | 4 |
| 🧨 破坏性测试结论 | 部分充分 |
📝 总结
设计扎实。signal-only channel + atomic pointer 是经典 lock-free notification coalescing 模式,两阶段 dispatch 正确消除了 per-response 冗余 timestamp command。核心安全不变量(handleEvent 中 latest.Less(ts) 单调递增保护)确保即使 ABA race 或 spurious wakeup 也不会破坏正确性。预期 signal channel backlog 从 7k+ 下降到 bounded 水平。
🧨 破坏性测试审判
- 结论: 部分充分
- 已覆盖失败模式: channel-full 非阻塞、冗余唤醒跳过、无界 drain 防护、timestamp coalescing 顺序、last-logtail-then-advance 语义
- 缺失失败模式: 多 goroutine CAS 并发竞争(
-race模式压力测试)、waiter 在 signal 被 coalesce/drop 时仍被唤醒的端到端验证 - 裁决理由: 单元测试覆盖了关键逻辑分支,但均为低并发场景。核心设计通过 monotonic advancement guard 保证正确性,并发测试是 belt-and-suspenders 但非阻塞项
🟡 Should Fix
1. Pool 重置逐字段写是维护陷阱 — logtail_consumer.go:2084-2090
- 类别: 可维护性
- 发现者: 老K(架构), 补丁犬 (共识)
- 描述:
cmdToConsumeLog.actiondefer 中逐字段清零,新增字段时易遗漏。对比cmdToUpdateTime直接 Put 不清零 — 风格不一致。 - 根治方案: 用结构体整体赋零
*cmd = cmdToConsumeLog{},一行搞定不可能漏字段。
2. 双遍历 list 重复过滤逻辑 — logtail_consumer.go:1845-1866
- 类别: 可维护性
- 发现者: 老K(架构), 补丁犬 (共识)
- 描述: Pass 1 和 Pass 2 对同一 list 调用相同的
ifShouldNotDistribute过滤。改一漏一是定时炸弹。 - 根治方案: Pass 1 中同时记录应分发的 index 列表,Pass 2 只遍历该列表。或使用 per-consumer slice 结构,单遍建立 + last index 自然为
len(entries)-1。
3. 建议补充并发压力测试 — timestamp_waiter_test.go
- 类别: 测试
- 发现者: 测姐
- 描述:
storeNotified/takeNotified是 CAS retry loop,原 bug 场景是高压写入,但所有新测试只用 1 个 goroutine。建议补充-race模式下多 goroutine 并发 hammer 测试验证 CAS 单调性。 - 建议: 加一个
TestNotifyLatestCommitTSConcurrentMonotonicity用 64 goroutines × 10000 iterations 压测。
🟢 Nit
1. storeNotified ABA race 注释 — timestamp_waiter.go:159
- 建议在
storeNotified上方加注释: "May succeed with a stale ts due to ABA race with takeNotified; harmless because handleEvent enforces monotonic advancement."
2. Commit 历史可 squash — PR 级别
- commit 3 (
fix: skip redundant timestamp waiter wakeups) 是对 commit 1 CAS 通知设计的补充优化。storeNotified一开始就应该返回 bool 并在 caller 处判断。建议 squash 为单个干净 commit。
3. sendTableLogTail wrapper 可能冗余 — logtail_consumer.go:1934
- 如果没有其他调用方使用旧签名,可以删除这个 1-line wrapper。
4. 空 LogtailList 边界测试 — logtail_consumer_test.go
dispatchUpdateResponse在LogtailList为空时所有 consumer 应走cmdToUpdateTime路径,建议补一个小测试。
💬 陪审团分歧记录
| 议题 | 老K | 铁壁 | 闪电 | 测姐 | 补丁犬 | 裁决 |
|---|---|---|---|---|---|---|
| 错误路径 timestamp 丢失是否为 🔴 | — | — | — | — | 🔴 | 🟢 pre-existing (errHappen=true 导致后续所有 cmd 被 skip,旧代码同样如此) |
| 并发测试缺失是否阻塞合入 | — | — | — | 🔴 阻塞 | — | 🟡 不阻塞 (monotonic guard 保证正确性,并发测试是加强项) |
| Two-pass O(2N) 是否需优化 | — | — | 不需要 (~6μs) | — | 可维护性改 | 🟡 可维护性角度建议改,性能角度无需 |
LGTM 👍 核心设计正确,fix 解决了实际问题。上述 🟡 建议可在本 PR 或 follow-up 中处理。
Fixes the CN logtail consumer backlog risk found in nightly sysbench write-heavy regressions. The bad run had `logtail.consumer.slow.*` in the `update_pk_1000` window, with `signal-chan-len` around 7373~7738 on one CN consumer routine. The good control run using the same MO image did not have these slow logs in the same case window. No sysbench reconnect/retry storm, workspace quota shortage, or UPDATE table-lock upgrade was found. This PR reduces internal backpressure without changing table assignment or increasing consumer routine count: - coalesces update-response timestamp commands for routines that already have table logtail commands, - advances the routine applied timestamp only after that routine consumes the last table logtail for the response, - keeps timestamp-only commands for routines that do not receive table logtails, preserving global min applied timestamp semantics, - makes timestamp waiter commit-ts notifications non-blocking and coalesced to the latest timestamp, - adds tests for non-blocking timestamp notifications, bounded notification draining, and logtail timestamp advancement ordering. Approved by: @gouhongshen, @XuPeng-SH, @iamlinjunhong
…atrixorigin#24330) Fixes the CN logtail consumer backlog risk found in nightly sysbench write-heavy regressions. The bad run had `logtail.consumer.slow.*` in the `update_pk_1000` window, with `signal-chan-len` around 7373~7738 on one CN consumer routine. The good control run using the same MO image did not have these slow logs in the same case window. No sysbench reconnect/retry storm, workspace quota shortage, or UPDATE table-lock upgrade was found. This PR reduces internal backpressure without changing table assignment or increasing consumer routine count: - coalesces update-response timestamp commands for routines that already have table logtail commands, - advances the routine applied timestamp only after that routine consumes the last table logtail for the response, - keeps timestamp-only commands for routines that do not receive table logtails, preserving global min applied timestamp semantics, - makes timestamp waiter commit-ts notifications non-blocking and coalesced to the latest timestamp, - adds tests for non-blocking timestamp notifications, bounded notification draining, and logtail timestamp advancement ordering. Approved by: @gouhongshen, @XuPeng-SH, @iamlinjunhong
…atrixorigin#24330) Fixes the CN logtail consumer backlog risk found in nightly sysbench write-heavy regressions. The bad run had `logtail.consumer.slow.*` in the `update_pk_1000` window, with `signal-chan-len` around 7373~7738 on one CN consumer routine. The good control run using the same MO image did not have these slow logs in the same case window. No sysbench reconnect/retry storm, workspace quota shortage, or UPDATE table-lock upgrade was found. This PR reduces internal backpressure without changing table assignment or increasing consumer routine count: - coalesces update-response timestamp commands for routines that already have table logtail commands, - advances the routine applied timestamp only after that routine consumes the last table logtail for the response, - keeps timestamp-only commands for routines that do not receive table logtails, preserving global min applied timestamp semantics, - makes timestamp waiter commit-ts notifications non-blocking and coalesced to the latest timestamp, - adds tests for non-blocking timestamp notifications, bounded notification draining, and logtail timestamp advancement ordering. Approved by: @gouhongshen, @XuPeng-SH, @iamlinjunhong
…atrixorigin#24330) Fixes the CN logtail consumer backlog risk found in nightly sysbench write-heavy regressions. The bad run had `logtail.consumer.slow.*` in the `update_pk_1000` window, with `signal-chan-len` around 7373~7738 on one CN consumer routine. The good control run using the same MO image did not have these slow logs in the same case window. No sysbench reconnect/retry storm, workspace quota shortage, or UPDATE table-lock upgrade was found. This PR reduces internal backpressure without changing table assignment or increasing consumer routine count: - coalesces update-response timestamp commands for routines that already have table logtail commands, - advances the routine applied timestamp only after that routine consumes the last table logtail for the response, - keeps timestamp-only commands for routines that do not receive table logtails, preserving global min applied timestamp semantics, - makes timestamp waiter commit-ts notifications non-blocking and coalesced to the latest timestamp, - adds tests for non-blocking timestamp notifications, bounded notification draining, and logtail timestamp advancement ordering. Approved by: @gouhongshen, @XuPeng-SH, @iamlinjunhong
What type of PR is this?
Which issue(s) this PR fixes:
issue #24322
What this PR does / why we need it:
Fixes the CN logtail consumer backlog risk found in nightly sysbench write-heavy regressions.
The bad run had
logtail.consumer.slow.*in theupdate_pk_1000window, withsignal-chan-lenaround 7373~7738 on one CN consumer routine. The good control run using the same MO image did not have these slow logs in the same case window. No sysbench reconnect/retry storm, workspace quota shortage, or UPDATE table-lock upgrade was found.This PR reduces internal backpressure without changing table assignment or increasing consumer routine count:
Validation