Repository navigation
perf: reduce CDC watermark and persisted PK check overhead - #32939
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. |
|
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: 95297334fa6ec2ac8d67f3d875b43e2564acc82d
Assessment: approve
The existing data-block scan owns its filter setup. Moving that setup under the candidate check avoids needless allocations after pruning and preserves the conflict result, candidate cap, tombstone scan, and cancellation behavior. The local comparison confirmed the allocation savings and found essentially identical allocation in the surviving-block control.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
Validation:
-
Preflight, diff hygiene, and the head-matched native build passed. See checks/1795084592419023764-3.json, checks/1795084592739248515-32.json, and checks/1795084628472235761-6.json and their retained logs.
-
The full disttae package passed normally and with -race. A focused race run also passed the persisted data, tombstone, history and cancellation tests. See disttae-normal-long.jsonl, disttae-race-retry.jsonl, and disttae-race-focused.jsonl with receipts checks/1795085316538025005-2.json, checks/1795085215645618893-2.json, and checks/1795085334640353129-2.json.
-
The real engine conflict-check entry point returned the expected result on both revisions. Pruned data fell from 17,584 to 13,816 B/op and from 48 to 13 allocs/op with one key. With 4,096 keys it fell from about 222,480 to 177,616 B/op and from 4,147 to 4,108 allocs/op. The surviving-block control remained at 100 allocs/op. See bench-base.log and bench-candidate.log with receipts checks/1795084923038211824-3.json and checks/1795085055516064829-2.json.
-
Alternating base and candidate runs reproduced the large-key allocation savings and measured 188–201 µs/op for the base and 173–182 µs/op for the candidate. See loop-base-1.log, loop-candidate-1.log, loop-base-2.log, and loop-candidate-2.log with receipts checks/1795085247033283681-3.json, checks/1795085259414976438-196.json, checks/1795085263952317063-390.json, and checks/1795085268395448372-2.json.
Limitations:
-
The benchmark used a local persisted-object fixture. Production SQL latency and throughput were outside the measured scope.
-
The first race attempt stopped at the host Go version check and was rerun with Go 1.27.1. The first normal run reached its package timeout and the longer retry completed. Frozen incremental SCA was still in progress.
|
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: 3b69ba39292092e5c718da6c0231a24972c21acf
Assessment: approve
The PK checker skips filter construction when pruning leaves no data blocks or when more than 32 blocks trigger the existing conservative conflict result. It preserves tombstone checks, row timestamp checks, and permit cleanup. CDC buffering reuses the metric label and formats timestamps only when Debug logging is enabled. The prior approval’s conclusion about the zero-candidate path still holds at this head.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
Validation:
-
Both packages passed their short race suites. Focused race tests also passed, including VARCHAR modified and upsert checks that read 32 data blocks at the limit and zero above it. See owner-race.jsonl and focused-race.jsonl.
-
Two paired runs using merge-base production files as the control measured allocations per operation dropping from 48 to 13 after pruning, 121 to 87 above the block limit, and 15 to 5 for CDC buffering at Info. The surviving-block control stayed at 100. See baseline-probe.log and candidate-probe-short.log.
-
CDC probes verified identical Debug event fields and commit metric increments on both versions. Neither version emitted the buffer event at Info. See log-parity.log.
-
The diff check, isolation preflight, and native build passed. validation-reconciliation.json matches the retained logs to their command, source, and exit receipts.
Limitations:
- Performance measurements cover component calls on one host. The frozen CI snapshot still showed multi-CN integration checks pending.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Coverage observation for commit 3b69ba39292092e5c718da6c0231a24972c21acf (not a claim of a production defect):
The closed, unmerged #32938 added pkg/cdc/watermark_updater_logging_test.go for the Info/Debug records, cached watermarks and counter. This PR carries the CDC production change, but not that test; both PRs use the same base.
The CI coverage job passes overall at 31/38, but its final-result-files profile records pkg/cdc/watermark_updater.go:2228.3,2239.1 1 0: the Debug log body was not exercised by the collected UT and BVT coverage profiles. The earlier review reports local log-parity probes, but those probes do not establish committed CI coverage.
Please retain the focused regression from #32938, or an equivalent test of the Debug and Info behavior, watermark state and counter, in this PR. I inspected the CI artifact and diffs; I did not run tests locally. This is a targeted coverage observation, not a complete review.
|
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: 3b69ba39292092e5c718da6c0231a24972c21acf
Assessment: request_changes
The prior runtime validation still applies. The follow-up identified a test delivery gap in the CDC logging change. The new Debug guard needs a focused regression test in the package suite. The persisted PK assessment still holds.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/cdc/watermark_updater.go:2227: The new logger-level branch in UpdateWatermarkOnly controls whether CDC emits the watermark buffer event.
Impact: The committed tests can pass if Debug stops emitting the event, emits incorrect watermark fields, or if log level starts affecting the commit counter.
Evidence: The pinned testing-contract.md requires focused unit coverage for changed internal behavior. The exact-head probe verified the contract through a temporary Go overlay, and the tracked CDC suite has no assertion for this event. Add a focused test through UpdateWatermarkOnly that checks the Debug event’s key and old and new watermarks, its absence at Info, and the same buffered state and commit counter increments at both levels.
Validation:
-
Reconciled the prior exact-head package and focused race passes, paired benchmarks, and CDC parity probe with their retained logs and successful receipts. The parity probe confirmed identical Debug fields and counter increments on both revisions, with no buffer event at Info.
-
Verified the tracked test inventory and the prior probe’s overlay mapping. See followup-validation.log and checks/1795104642298323134-2.json.
Limitations:
- The frozen discussion quotes the CI profile’s zero-hit block. The raw profile was outside the supplied snapshot. The finding is based on the tracked tests and verified overlay.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
This change is a behavior-preserving performance trim and I found no new blocking or non-blocking defects. HEAD 3b69ba3 matches the PR head and the three-commit diff touches only pkg/cdc/watermark_updater.go, pkg/vm/engine/disttae/txn_table.go, and the PK-check budget test. In PKPersistedBetween, PK-filter construction is now skipped when pruning leaves no candidate blocks or when the >32-block conservative bailout fires; a normalized diff of the function plus a case analysis (zero candidates with and without tombstone checking, 1-32 candidates, over-budget, and every cancellation, read-error, semaphore, metric, and cleanup path) shows each path returns the same result as origin/main. The only observable delta is that ConstructBasePKFilter/ConstructBlockPKFilter errors can no longer surface on the zero-candidate path, where the filter would be unused; the no-conflict conclusion there rests on the already-completed zone-map and bloom-filter pruning, so the removal cannot weaken correctness, and the tombstone check, candidate_blocks_bailout result, permit acquire/release pairing, and counters are unchanged, with the data loop still releasing its permit before the tombstone phase. In UpdateWatermarkOnly, the new guard logutil.GetSkip1Logger().Core().Enabled(zap.DebugLevel) is exactly the check zap v1.27.1's Logger.check applies to logutil.Debug through the same skip-1 logger, so emitted events are identical and only disabled-log argument formatting is skipped; reusing tableLabel for the log key field is value-identical because WatermarkKey.String is a pure fmt.Sprintf, and the commit counter still increments unconditionally. The extended 32/33-block budget test exercises the changed function through the modified-key arm, adds an upserted arm (routed through the delegated pkUpsertPersistedBetween for this plain int64 PK), and now asserts mpool balance and semaphore drain, strengthening resource-handling coverage. Limitation: the disttae and cdc package tests could not run in this checkout because the cgo prerequisites built only by make cgo/thirdparties (roaring.h, xxhash.h, usearch.h, jemalloc.h) are absent, and per review constraints I did not build them; verification is therefore static (gofmt on all changed files, equivalence analysis) plus the CI unit-test and coverage runs at this head as corroboration only. One prior item remains open at this head and I have not re-raised it: review 5978779593 (and coverage observation 5978652038) requested the focused CDC Debug-level regression test from closed #32938 (pkg/cdc/watermark_updater_logging_test.go), which this PR does not carry.
|
mo-bot review · Commit: New discussion was assessed; the previous review remains unchanged. |
|
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: 90ab7ff72dfd5103734f2fca895c82c8a36293d6
Assessment: approve
The PK check skips unused filter setup while preserving tombstone checks, the conservative result above 32 blocks, cancellation, and I/O cleanup. CDC reuses the metric label and formats timestamps only when Debug is enabled. The committed Info and Debug regression resolves the prior coverage finding.
Model: gpt-6.2-sol / xhigh
Session: 01a1ee7f-fdcb-7b83-ad57-3b17a0e9d494 · slot 1 · generation 1
Validation:
-
Verified the frozen head, patch, whitespace, native build inputs, and runtime isolation preflight.
-
The CDC package passed under the race detector on this head. The committed logging test passed 100 repetitions, checking event fields, buffered watermarks, and counter increments.
-
Reconciled prior disttae race and boundary checks with the identical production and PK test sources. Paired benchmarks measured allocations per call falling from 48 to 13 after pruning, 121 to 87 above budget, and 15 to 5 for CDC at Info. The surviving-block control stayed at 100.
-
Matched five current-head receipts and six retained receipts to their logs. Accounted for all 12 discussion entries.
Limitations:
- The benchmarks measured component calls on one host. Current-head integration and coverage checks were still in progress in the frozen CI snapshot.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32278 (C02 and C28).
What this PR does / why we need it:
A persisted primary-key check prepared a data filter even when pruning left no candidate blocks or the candidate count had already exceeded the I/O budget. Check these cases first, while preserving the tombstone check, conservative conflict result, and existing cancellation and I/O cleanup. The 32/33-block boundary test now exercises both modified-key and upsert checks and verifies reads and resource balance.
Buffering a CDC watermark formatted the table key twice and rendered timestamps before a disabled Debug log could be rejected. Reuse the metric label and prepare the structured fields only when Debug is enabled. This PR incorporates the production change from #32938.
Local Go 1.27.1 microbenchmarks on the public conflict-check path reduced allocations from 48 to 13 per call for a pruned object, and from 121 to 87 for an over-budget object; single-hit and 32-block controls retained their previous allocation counts. A repeated CDC watermark update with Debug disabled fell from 11 to 4 allocations per call. These measure local operations, not end-to-end throughput.
Validation: focused persisted-data, tombstone, time-window, cancellation and history tests; complete CDC and disttae package race runs; a focused race run of the updated 32/33-block cases; go vet and incremental golangci-lint for both packages. The CI coverage merge passed with 31/38 changed blocks covered (81.58%); the two BVT groups and Linux/arm64 SCA also passed.
The committed CDC regression calls UpdateWatermarkOnly at Info and Debug. It checks the buffered value and counter after each update, and checks that the Debug event retains the key and old and new watermarks. The performance measurements and prior CI coverage above describe the unchanged production diff.
On the follow-up commit, both focused subtests, the full CDC package under the race detector, go vet, molint, and incremental golangci-lint passed. New GitHub CI runs on the updated head.