Repository navigation
feat: add C02 bounded encoding codec foundation - #29750
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of 90b5bf4 against declared base/merge-base 0ccc989: APPROVE. Reviewed all 15 changed files and the prior review thread. No remaining blocking finding; the previous P2 CONVERT performance finding is substantively addressed.
Design and ownership: the approved C02 design in #29651 explicitly permits a codec foundation before session/prepared/result-protocol activation. This change keeps SQL charset admission in its existing resolver and conversion semantics in the codec. BorrowedConvertUsing is a stack-local sequential-batch owner shared by the evaluator and single-value Convert, not a persistent state machine or a second semantic implementation. The added state pays for amortized cancellation checks without giving up the output limit or publication check. Strict MB3 validation and internal ASCII conversion remain within the approved foundation; this does not close all of #29481.
Prior comment closure and performance: independently compared the unchanged base evaluator body with the current evaluator in one binary, using the same prebuilt vectors, constant charset, reused result buffer, 128 rows of 8 bytes, and five 500ms samples on Go1.27.1/Darwin arm64/Apple M4. Medians: binary 2804 -> 3084 ns/batch (+10.0%); UTF8MB4 2982 -> 3231 ns/batch (+8.4%). Both arms remain 0 B/op and 0 allocs/op. The previous 2.09x/3.29x regression is gone. The remaining approximately 2 ns/row buys explicit output bounds and bounded cancellation and is proportionate here. This is an evaluator microbenchmark, not a measured TP/prepared-statement throughput result; prepared executions containing CONVERT still use this evaluator. No new connection or prepared-protocol codec activation occurs.
Correctness and adversarial closure: traced SQL resolution -> evaluator -> codec -> vector append -> public result/error cleanup. Checked cumulative 4096-byte cancellation boundaries, empty values, invalid UTF8 becoming NULL versus cancellation remaining an error, large UTF8 chunks, partial masks/NULLs, constant and per-row targets, inline/external varlena limits, and final publication. The single-value API uses the same borrowed owner. Allocation failures and cancellation after allocation release untransferred output; RunFunctionDirectly discards staged vectors and restores pool usage on error. The unchanged 203 MySQL wire cases and capture helper retain the independently verified provenance from the previous review; no live recapture was needed or performed.
Additional CI-fix closures: the cgroup watcher now makes task completion wait for the actual AfterFunc close when its callback has started. Traced Stopper cancellation/task draining and Go's pollable-file Close/Read reference release: Close wakes the read, the read releases its reference before the task defer waits, and the callback closes closeDone independently. Setup failures and rejected tasks still close their FD; normal-return and cancellation paths have one effective close owner. One channel per watcher adds no growing state or TP hot-path cost. The histogram test waits for both asynchronous batches to pass the collector before restoring global configuration; no later producer operation reads that configuration. Four sends, fourteen samples, clock and capacity assertions remain intact.
Validation: repository-provenance native build completed; exact-head codec owning tests and all selected CONVERT evaluator/return-domain tests passed with count=1 and vet=all. TestExporter passed under race, count=100. Docker seed contract: all 4 tests passed. Full downloader suite passed, including both retry engines, HTTP fallback, corrupt/oversized response rejection, unchanged destinations and cleanup. HTTPS, immutable checksums, byte/time/retry bounds and atomic publication remain owned by the existing downloader. Exact-head ALL CI run 38022106429 is completed/success, including Linux UT/coverage and enabled proxy/compose BVT; Linux watcher execution evidence is reused from CI and the revision-qualified author validation, not claimed as a local Darwin execution. Skipped jobs are not counted as evidence.
Incremental quality: implementation +343/-18 across 8 files; tests/oracle/probe +957/-7 across 7 files; documentation delta 0. Reviewed these separately. Shared fixtures and the existing wire probe avoid duplicate setup; new cases prove limits, cleanup, semantic boundaries and real public-result publication rather than only helper internals. The unrelated CI repairs are small, separately committed and have concrete failure owners. No obsolete per-row generic conversion path or duplicated charset admission remains in the changed consumer. The sole prior inline review finding is resolved; no additional substantive comment remains open. Reviewer-only benchmark source/logs are retained locally, its temporary source was removed, and no production edits or subagents were used.
Merge Queue Status
This pull request spent 1 hour 15 minutes 55 seconds in the queue, including 1 hour 15 minutes 38 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #29481. Foundation batch only; this PR does not close the issue.
What this PR does / why we need it:
Implements the independently deliverable codec foundation from the merged C02 design (#29651,
f6c86c9c0452db27af1b0c9aceff1aa5b96aabad, sections 3.1 and 5).pkg/common/collation/encodingusing the existing charset enum. Keep repertoire validation separate from byte-preserving identity, connection/result replacement, and target-specific binary-source CONVERT behavior (invalid UTF-8 → NULL; ASCII high-bit bytes →?).MPool.Alloc; bound output by the caller limit and allocator maximum, check cancellation at bounded scan/allocation/publication boundaries, and release every untransferred allocation on failure.Scope deliberately not activated
No default, persisted collation identity, key format, session migration, handshake, prepared binding, or result protocol changes. ASCII conversions are internal helpers only: ASCII session/SQL admission remains unchanged. Strict utf8mb3 is validation-only; GBK and new comparison domains remain disabled.
Follow-up C02 batches still need atomic session tuples and statement staging, literal/prepared source-domain propagation and candidate binding publication, all result/metadata consumers, and the applicable ASCII client/results upgrade/release gates. This foundation is not full issue acceptance.
Validation
Current implementation revision:
90b5bf4a2d6e305e11b9220fc034a95c8b84fb39, merged withmo/mainat0ccc989731f9c2b40d31554a44ca505c656c0e62.Latest CI correction (
90b5bf4a2d): run 37956564665 passed shared build, SCA, native checks, and Proxy/Pessimistic BVT, but failed two independent UTs. The cgroup watcher now joins an already-started cancellationFile.Closebefore its task drains; a secondClosealone cannot prove the first close completed.TestExporternow awaits collector completion of both asynchronous raw-histogram batches before gathering/restoring global configuration. It retains all original 4-send/14-sample/clock/buffer-capacity assertions; production histogram dispatch remains asynchronous.-count=1 -vet=allpass again. Host pinned lint over the complete changed Go package closure reports 0 issues. Linux tests used a test-owned auto-removed container; existing services were untouched.Review performance correction (
d950b1d344): a shared, stack-local borrowed CONVERT scope consolidates small-value cancellation checks across a single evaluator batch. It checks before the first actual value, within 4096 cumulative input bytes (empty values count as one), during large UTF8 scans, and before result publication. Per-value caller/allocator limits remain enforced. Single-valueConvertreuses the owner and immediately finishes; ASCII replacement/allocation ownership and public charset admission are unchanged. The evaluator does not implement independent charset semantics.-count=1 -vet=all, codec owning race, allocation-cleanup/publication race ×100, and pinned v2.14.0 incremental lint passed. All 203 offline MySQL observations and existing NULL/const/selection/compatibility oracles remain green. A publicRunFunctionDirectlycontrol proves cancelled publication returns no vector and frees its staged result back to the MPool baseline.d2a0055ebebase evaluator versus fixed evaluator in one binary, identical prebuilt inputs/constant target/reset: medians base 3227/4084 versus fixed 3618/4662 ns/batch. Approximately 12%/14% residual local CPU overhead remains for bounded cancellation/output-budget guards; this is not a zero-overhead or end-to-end throughput claim. The actual evaluator benchmark is committed; the temporary old evaluator copy is not.CI correction (
4b63d5890e): run 37892718308 failed before BVT/coverage execution: published Go 1.27.0 images inheritedGOTOOLCHAIN=localdespite go.mod requiring 1.27.1, and native dependency downloads exhausted retries on HTTP 504. CPU source-build stages now explicitly allow go.mod-directed toolchain selection. The existing immutable, SHA256-verified HTTPS ONNX media fallback also handles curl HTTP failures (22), not only timeouts (28). No Go minimum, image tag, SQL expectations, workflow permissions, or coverage gate is weakened.-count=1 -vet=allpassed using Go 1.27.1 / darwin arm64 and the repository CGo wrapper. The later performance correction is independently validated above; do not substitute the old revision's evidence for new-head CI.Historical P2 correction and revision-qualified foundation evidence (
dc4bfb36ef): binary→ASCII CONVERT replaces each high-bit source byte rather than returning NULL. The new wire direction reproduces the previous failure; 29 binary→ASCII observations and empty/7f controls bring the fixture to 203 cases. All previous 162 records remain byte-for-byte unchanged. Target UTF8MB4 still returns NULL for invalid binary input. Ownership, byte-unit replacement, budget and cancellation controls were added.-count=1 -vet=all:./pkg/common/collation/...and./pkg/sql/plan/functionpassed. Codec statement coverage is approximately 99%; CONVERT helper coverage is approximately 91%.-racepassed. Their relevant code/dependencies are unchanged by the main merge.fedbf870c987d6c624e5d8a2a7db11e525d6da96passedmake -j8 build. Subsequent corrections have linked owning-package validation as documented above; a new service build is not claimed.function/func_cast.test(252/252),charset_collation/charset_collation_basic.sql(297/297), andcharset_collation/charset_collation_errors.sql(207/207), each twice on the same clean test-owned standalone instance after SQL and ISCP readiness. Teardown postconditions were checked. Those foundation runs used isolated ports rather than interfering with an existing service on port 6001. The P2 correction has no new BVT: ASCII SQL admission remains disabled and the evaluator still uses only binary/UTF8MB4 targets, whose owning tests passed after the fix and main merge.No BVT expected result, workflow, generated production file, or dependency was modified. CI is not yet verified.