Repository navigation
docs: draft C02 connection encoding design (#29481) - #29651
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.
Design review of 7253b380df95ab705cba2b041c7d392e37cbaef4 against declared base / merge-base d9eb0e0ce88bec403dce4cd6c7fbdf15f19e1b03: REQUEST_CHANGES for design approval. This is an honest design-only draft, not a production regression or a claim that #29481 has been fixed. Archiving a draft and approving its implementation are different decisions.
The direction is sound: reuse the common static capability directory, keep Session/sysvars as the effective encoding owner, retain PrepareStmt's bounded long-data ownership, convert at explicit input/output boundaries, and preserve binary values without adding a payload cache, registry, worker or retry loop. The small raw-wire/SQL validation matrix is appropriate; no runtime UT/BVT/race/performance run is required merely to add this document.
The current revision does not yet define one interoperable behavior. Two inline P2 findings identify the concrete gaps: a server cannot reconstruct application-level string/byte provenance absent from the wire, and the combined session/lexing/publication protocol is left to future decisions despite an existing statement-staging owner. Before approving implementation, resolve these with exact byte/state examples and the existing owners, not a new generic conversion framework.
Also close the related items already acknowledged in section 8:
- Retain C01's explicit utf8/utf8mb3 → utf8mb4 compatibility decision as the baseline. Do not make an unapproved stricter policy the implicit prerequisite for all useful C02 work. State the implementable first-stage scope and which issue acceptance item remains deferred; a separate strict mode needs its own authorized contract.
- Pin the actual MySQL/driver oracle and the malformed-input, unrepresentable-output and partial-result failure behavior. Metadata, field lengths and error/connection disposition must be specified together. The official connection-encoding contract includes results, column names and errors, while introducer syntax does not itself change escape-processing rules.
- Name the concrete allocator/owner, return-value ownership convention, output bound and cancellation granularity for the shared codec. Define the release/commit sequence for failed rebinding and conversion after long-data materialization; simply promising atomic replacement does not explain its peak memory or terminal cleanup. Reuse current limits and lifecycle owners.
I checked the entire 141-line document against the baseline's charset admission, handshake/change-user, SET, parameter parsing/publication, long-data cleanup, result paths and staged SQL-mode execution, plus the C01 design decision. The pinned go-sql-driver/mysql v1.9.3 source confirms that non-nil []byte and string parameters can generate identical type/flag/value bytes. There are no prior substantive PR review comments to mark resolved. The owner's five acknowledged blocking decisions remain open.
Validation: local Markdown target exists; exact-range git diff --check passed; docs CI/CI Required are green. Skipped executable jobs are not counted as behavioral evidence. Change cost: implementation 0, tests 0, documentation +141/-0. No tracked edits or subagents. Keep #29481 open and preserve the draft/non-activation statements until a decision-complete revision is approved.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of ce22049f5520cfa35cfa6871222ced2c0b32c8aa against declared base / merge-base bab4b3286a0dd5683a9b291763817722233e586c: REQUEST_CHANGES — one P2 evidence-integrity blocker, not a demonstrated production regression.
Design and earlier comments
The overall direction is reasonable and materially improved. The two earlier inline design requests have been addressed in substance: §3.4 uses actual wire type/flags instead of inventing client-language string/[]byte provenance; §§3.2–3.3 place encoding publication and per-statement reparsing in the existing Session/doSetVar/staged-execution owners. I checked the resolved threads against the text rather than accepting their UI status alone. The go-sql-driver/mysql v1.9.3 packets.go SHA-256 independently matches the new JSON.
The related C01 compatibility decision is preserved: utf8/utf8mb3 continue to mean effective utf8mb4; strict mb3, native ascii connection/collation and GBK activation are not smuggled into this first stage. #29481 correctly remains open. I am not adding a mixed-version rolling-upgrade requirement.
However, the requested actual reference proof is not fully closed. Two prepared_and_lifecycle_cases[].query_hex values cannot produce their accompanying recorded responses. The inline finding identifies the exact bytes. This matters because §7.1 relies on these records to freeze the staged-error and partial-result/connection-reuse contracts before implementation.
Ownership, unhappy paths, complexity and performance
| Closure | Review outcome at design level |
|---|---|
| Q1 — conversion / binding ownership | Borrowed versus mpool-owned output, one-at-a-time copying/freeing, candidate publication and failed-execute cleanup are explicit; existing PrepareStmt/ExecRequest/session cleanup remains the owner. No second long-data history or cleanup subsystem is proposed. |
| Q2 — termination | No new worker, retry or wait dependency; conversion is required to check cancellation at bounded input intervals. Complete prior packets versus an unsent row and terminal ERR/connection close are distinguished. The claimed MySQL partial-result evidence must be repaired. |
| Q3 — retained memory / work | Existing packet, vector-area and allocator bounds are reused; peak live buffers are enumerated and session high-water caches prohibited. Identity/binary fast paths and linear conversion are appropriate goals, not measured performance results. |
I traced the current parameter type commit, long-data buffer release/error latch, clearBinaryParamState/reset/Close/session-close paths and the existing staged SQL-mode functions. No additional demonstrated resource/liveness blocker was found in this design-only revision. Actual cancellation/OOM, prepare/execute/fetch metadata, raw-wire consumer tests and allocation benchmarks still belong to implementation/activation; green CI here cannot prove an unimplemented codec.
QA and evidence
- Read both complete additions: design +198 lines and oracle JSON +874 lines; implementation 0, executable tests 0. The raw snapshot has value only when request and response stay paired; valid JSON/hex alone is insufficient.
- Independent local audit: JSON parses; all 245 explicitly named hex fields validate; 13 query and 12 prepared/lifecycle records; local Markdown targets exist. Byte decoding reproduces the two contradictions, with the correctly quoted
query_casesstaging record as the nearest control. - Exact-range
git diff --check: passed. Fresh remote main is35c15650995ed1ce12d1a7ed0601ec5cee0fe6d7; the inspected frontend/collation/allocator ownership files have no base-to-main change invalidating this analysis. - Exact-head CI Required, UT Ubuntu, SCA, coverage and the selected BVT jobs are green; skipped jobs are not proof. No new MO UT/BVT/race/benchmark or MySQL server run was performed locally for these docs. This finding is a deterministic artifact contradiction, not a claimed server reproduction.
Repair/re-capture the affected oracle entries from the same bytes actually sent, retain the corresponding response and successful post-error request, and keep SQL/backslash notation byte-accurate. A small reproducible probe/round-trip assertion is sufficient; no generic framework or additional heavy fixture is requested. The earlier architectural corrections need not be reworked. No source edits or subagents.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of f33345a against declared base/merge-base dce6063: APPROVE this design revision. No blocking findings remain. This supersedes my earlier requests for changes, but is not approval of an unimplemented C02 feature or its production activation.
Prior findings closed in substance:
- Parameter semantics use observable wire type/flags and SQL, not unrecoverable application-language string/[]byte provenance. NULL, type reuse, failed rebinding and long-data follow the existing parameter/session owners.
- Session/doSetVar publishes the effective encoding tuple; per-statement interpretation extends the existing SQL-mode staging owner. The mixed SET/mode/later-error/reset trace now specifies the state and byte boundaries without a second execution state machine.
- The corrupted request/response evidence has been repaired with a narrow checked-in probe: query_hex comes from the actual send buffer, responses from recv, and a successful SELECT 1 follows the partial-result ERR immediately on the same connection. All three historical inline threads are resolved, and I checked the corresponding text/artifacts rather than relying on the resolved flag.
Reviewer validation:
- Read the complete design, probe and reference artifact, including the r2-to-r3 delta.
- Ran the checked-in offline checker successfully; it verifies the exact quotes, dollar sign and single backslash and rejects both historical corrupted-request controls.
- Independently decoded all five recaptured raw response streams, without importing the probe parser. Column names/charset/length/type, rows, SQLSTATE/error payloads and status/termination all match the recorded structured results, with no surplus packets. This confirms the partial row -> ERR sequence and the separate successful follow-up response.
- Python syntax and exact-range whitespace checks pass; review worktrees remain free of tracked edits.
- Rechecked the existing SET/staging/parameter cleanup owners and C01's explicit utf8/utf8mb3-to-utf8mb4 contract. The inspected owner changes between the documented baseline and freshly fetched main (48f8178) are non-semantic for this design.
- Exact-head CI Required is green. No new MySQL capture, MO UT/BVT/race or performance run was performed in this review; the author's pinned reference capture is reused, not presented as reviewer execution or MO acceptance.
Design/engineering assessment: the common static capability owner plus explicit boundary conversion is appropriate. The borrowed/mpool-owned/NULL/error return contract, one-at-a-time conversion and release, candidate publication, existing long-data bounds and terminal cleanup are explicit. No new registry, worker, retry, payload cache or duplicated storage path is proposed. Cancellation is bounded; partial results distinguish an unsent row from already-complete packets and retain the existing ERR/connection-close owner. Identity fast paths and linear bounded conversion are sensible requirements, not measured performance claims.
Incremental cost is considered separately: MO production code 0, MO runtime tests 0; design +209 lines, reference snapshot +958, standalone probe +265. The executable addition is a bounded, standard-library reference collector/checker with a specific evidence-integrity purpose, not a general protocol framework.
Approval scope: approve the compatible first-stage API/state/metadata/ownership design. Preserve the C01 compatibility mapping and data identities. Strict mb3, native ascii comparison/connection domains and GBK are not implicitly enabled; implementation/activation must provide the already-listed real consumer, raw-wire, cancellation/OOM, metadata and allocation/performance evidence. No mixed-version rolling-upgrade requirement is added by this review. Keep #29481 open: these reference observations and this design approval do not establish that the feature is implemented or its full acceptance matrix passes.
Merge Queue Status
This pull request spent 1 hour 32 minutes 6 seconds in the queue, with no time running CI. ReasonPull request #29651 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
Implements the independently deliverable codec foundation from the merged C02 design (#29651, `f6c86c9c0452db27af1b0c9aceff1aa5b96aabad`, sections 3.1 and 5). - Add `pkg/common/collation/encoding` using 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 → `?`). - Compute exact output size before an accounted `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. - Reuse the codec in the existing CONVERT evaluator without opening new SQL charset admission. Preserve binary bytes, NULL/empty distinctions, constant arguments, selection lists, and utf8/utf8mb3 → utf8mb4 compatibility. Inline vector values do not consume external-area budget. - Add 203 actual MySQL Community 8.4.11 wire observations, an exclusive-output recapture probe, and offline request/row-packet pairing checks. Cover malformed continuation bytes versus incomplete source sequences, not just generic invalid UTF-8. ### 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 with `mo/main` at `0ccc989731f9c2b40d31554a44ca505c656c0e62`. Latest CI correction (`90b5bf4a2d`): [run 37956564665](https://github.com/matrixorigin/matrixone/actions/runs/37956564665) passed shared build, SCA, native checks, and Proxy/Pessimistic BVT, but failed two independent UTs. The cgroup watcher now joins an already-started cancellation `File.Close` before its task drains; a second `Close` alone cannot prove the first close completed. `TestExporter` now 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. - Go 1.27.1 / real Linux arm64 / CGO: the unchanged cgroup baseline reproduced the exact FD 0→1 failure under race ×1000. Fixed cgroup watcher tests under race ×1000, full owning system race/vet, and short/matrixone_test coverage-set mode pass. Linux pinned v2.14.0 incremental lint: 0 issues. - Go 1.27.1 / darwin arm64 / repository CGo wrapper: exporter race ×1000, full owning mometric race/vet and short/matrixone_test coverage-set mode pass. The exporter CI failure was not reproduced by the old Mac stress; its asynchronous ordering assumption is removed with a completion barrier, not sleeps/retries or weaker assertions. - After the latest main merge, codec/evaluator owning tests with `-count=1 -vet=all` pass 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. - New-head CI is pending. Prior-head BVT/native/SCA success and historical performance evidence below are revision-qualified, not a claim that new-head CI has passed. 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-value `Convert` reuses the owner and immediately finishes; ASCII replacement/allocation ownership and public charset admission are unchanged. The evaluator does not implement independent charset semantics. - At the performance-correction revision, codec/evaluator owning UT with `-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 public `RunFunctionDirectly` control proves cancelled publication returns no vector and frees its staged result back to the MPool baseline. - Controlled 128×8-byte evaluator benchmark, Go 1.27.1 / darwin arm64 / Apple M1 Pro, five 500ms samples: pre-fix medians binary 7628 and UTF8MB4 14050 ns/batch; fixed medians 3720 and 4621 (about 51%/67% lower), with 0 B/op and 0 allocs/op. - Exact `d2a0055ebe` base 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. - New-head CI is pending; the preceding head's successful CI is not claimed as validation of this change. No new service/BVT run is claimed. CI correction (`4b63d5890e`): run [37892718308](https://github.com/matrixorigin/matrixone/actions/runs/37892718308) failed before BVT/coverage execution: published Go 1.27.0 images inherited `GOTOOLCHAIN=local` despite 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. - New regression controls fail against the pre-fix recipes/downloader and pass after the correction. Full downloader tests cover native/legacy retries, HTTP fallback success, absent/exhausted fallback, corrupt/oversized payload rejection, cleanup and unchanged destinations. All four Docker/cache seed contract tests and the native build contract suite pass. - Actual primary and media endpoint downloads independently match the pinned Linux x64 ONNX checksum. A test-owned cached Linux/arm64 Go 1.26.4 image automatically selected and ran Go 1.27.1 with the current module; this is a stale-toolchain control, **not** a full CI-image or Docker build claim. - At the CI-correction revision, codec/evaluator owning tests with `-count=1 -vet=all` passed 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. - Go 1.27.1 / darwin arm64, repository CGo wrapper and verified worktree native build. - Normal owning-package tests with `-count=1 -vet=all`: `./pkg/common/collation/...` and `./pkg/sql/plan/function` passed. Codec statement coverage is approximately 99%; CONVERT helper coverage is approximately 91%. - Focused allocation/cancellation/ownership race tests, 100 repetitions of the failure-cleanup test, and the codec owning package under `-race` passed. Their relevant code/dependencies are unchanged by the main merge. - Repository-pinned golangci-lint v2.14.0 incremental checks: 0 issues; gofmt and diff checks passed. - The initial foundation at `fedbf870c987d6c624e5d8a2a7db11e525d6da96` passed `make -j8 build`. Subsequent corrections have linked owning-package validation as documented above; a new service build is not claimed. - At that initial foundation revision, existing public-path BVT in normal comparison mode: `function/func_cast.test` (252/252), `charset_collation/charset_collation_basic.sql` (297/297), and `charset_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. - Two independent final oracle captures matched exactly. Ordinary codec UT is offline and does not require MySQL. - Codec benchmarks include borrow, validation, and ASCII replacement paths; no end-to-end performance improvement is claimed. Native mpool allocation is not reported as Go heap bytes by benchmem. No BVT expected result, workflow, generated production file, or dependency was modified. CI is not yet verified. Approved by: @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
Related to #29481. This design-only draft does not fix or close the issue.
What this PR does / why we need it:
Adds the C02 connection-encoding design draft before production implementation, as required for changes to protocol, session-state ownership, and compatibility contracts.
The merged C01 design explicitly preserves the existing silent utf8/utf8mb3-to-utf8mb4 compatibility mapping, including new requests. C02's strict utf8mb3 acceptance criterion conflicts with that approved policy. This PR retains the approved compatibility mapping, defines an implementable compatible first stage, and explicitly defers strict utf8mb3 rather than making it a prerequisite for all C02 work.
The draft covers:
d9eb0e0ce88bec403dce4cd6c7fbdf15f19e1b03.Review status
Design revision r3 is not approved and is submitted for re-review. Production implementation still awaits design approval; strict utf8mb3, new-domain migration/admission, and release activation remain separately gated. No production code, defaults, metadata identities, SQL activation, or issue acceptance checkboxes are changed.
Validation
git diff --cached --check: passed.mo/main(dce60631f8). No MatrixOne production or test code changed.query_hexvalues were corrupted by reconstructing SQL through a shell-wrapped Python literal. Those old request/response pairs were invalid and are not used as proof.query_hexfrom the exact buffer passed to send and response payloads from the corresponding recv. The fixed MySQL 8.4.11 staging/state/reset/partial-result sequence was recaptured twice with identical output;SELECT 1succeeds immediately after the partial-result ERR on the same connection.