Repository navigation
fix(ivfflat): keep flushed appendable entries on the replay owner (4.2-dev) - #33153
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? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
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: 42713c6aabc7d64753d7efbf337a29717bf29795
Assessment: request_changes
Keeping flushed appendable entries on the replay owner fixes duplicate and missing candidates in the replay tests and preserves immutable-object distribution. The PR also adds a legacy wire mode that conflicts with 4.2’s shutdown-only upgrade policy.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/sql/compile/ivf_ownership_protocol.go:34: A distributed IVF query sends a table-function or entries-scan instruction to another CN.
Impact: The fix adds two wire opcodes, fragment validation, and nested context propagation to maintain two ownership rules. Unmarked fragments retain the old rule that can duplicate or omit a visible candidate across flush replay.
Evidence: The pinned upgrade policy prohibits new legacy encode/decode paths for older peers.remoterun.gouses these opcodes only for in-cluster query execution. The scheduler already places the replay owner at ordinal zero, andscope.go:1071already has the scan identity needed to apply one ownership rule. Keep the existing opcodes, apply the corrected rule uniformly, and update the rollout guidance to describe a full-cluster shutdown.
Validation:
-
Verified the frozen patch, isolation preflight, and native build inputs. Receipts and retained logs are indexed in
review-validation.md. -
Passed 19 focused test roots across compile, plan, and readutil, including all four replay orderings, immutable-object distribution, and the single-CN control (
checks/1795515955992215621-2.json,focused.jsonl). -
Passed the four-CN frontend SQL test for ordered IVF results and strict query-pool behavior (
checks/1795516084716753947-2.json,frontend.jsonl). -
Compared the released appendable flag producer and reader against the candidate (
checks/1795515771620266666-2.json,release-trace.stdout). v4.2.9 release, v4.2.8 hotfix.
Limitations:
- The deterministic mixed-replay test exercised the storage and scan components. The frontend test used a same-version cluster. Released-format compatibility was checked at source level.
A remote scan reconstructs the committed snapshot, not the ingress CN's pending writes. Prove membership of the actual owner in the resolved pool and reserve a worker slot for it before enforcing the cap. Fail closed if it cannot participate. Leave read-only and local queries unchanged.
Apply the appendable-object rule using the scan partition and physical locality. 4.2 uses full-cluster shutdown upgrades; IVF needs neither new pipeline opcodes nor a fallback to the old ownership rule. Keep immutable object hashing and the separate writable-workspace admission check unchanged.
…tes (4.2-dev) (#33155) ## What type of PR is this? - [x] BUG - [x] Test and CI ## Which issue(s) this PR fixes: Fixes #33150. Branch-adapted backport of the applicable execution-placement fixes from #29452 (main merge `a97f9c940bba`). ## What this PR does / why we need it: A `SINK_SCAN` reads a process-local producer register; a hash join consumes a process-local JoinMap. Nesting these under a sole remote probe does not transport those dependencies. On a synchronous indexed UPDATE the remote hash build can end up waiting on a register for which no producer was shipped. Increasing a timeout does not create that producer. Keep the owner of local-only operators; when the inputs cross the ownership boundary, transfer batches through the normal merge/connector before constructing the JOIN. A remotely eligible scan can remain remote. No timeout, JoinMap cleanup behavior, index format or transaction semantics are changed. When the coordinator is one of several probe CNs, it can host either a SINK_SCAN or a WINDOW build. It broadcasts the resulting batches through the existing receivers, and each peer probes with its own HashBuild and JoinMap. A topology without a coordinator host, a forced-single join, and a shuffle involving WINDOW retain their coordinator fallback. ### Backport boundary The numeric-CAST string-domain inference and physical ASOF build-left entry points from the upstream change do not exist on this branch. Do not introduce those main-only features to backport their guards. The updated 4.2 base includes #33169, the backport of the singleton reader fix from #27796 for #27755. With the JOIN placement fix **alone**, a one-remote-worker UPDATE could commit the new base row and full-text postings but leave **zero** IVF entries for that PK. The physical index failure was independently observed from both CNs after a writer-commit fence. The write uses the current IVF version and centroids; when those source rows were still in memory a singleton remote block reader silently skipped them. Flushing just those sources changed this control from FAIL to PASS. This is why the companion reader fix is needed here; flushing production tables is **not** the fix. The singleton remote worker now uses the relation it opened at the statement snapshot to read the complete input. Distributed remote workers retain the persisted-block reader and its original partitioning. The branch's account context, membership filters and cancellation path are preserved. ### Validation - Compiler/wire control: old 4.2-dev fails the three misplaced-owner cases; local parallelism and legal remote transport are controls, not things to disable. Check forced single-probe and WINDOW placement as well as empty input and cancellation. - Public SQL: an isolated two-CN MO cluster, one eligible peer, `query_max_workers=1`, synchronous full-text + IVFFLAT indexes. Check the actual peer for the windowed reads, selected remote worker and index operations for UPDATE, and the ordinary control on the coordinator. Exercise zero matches, ROLLBACK, then COMMIT. Fence both observers at the writer commit timestamp and independently check base text/vector, physical IVF entry count and stored vector, and old/new full-text postings. - Negative/positive controls: the base remote indexed UPDATE times out on empty input; JOIN-only returns, but the committed PK has 0 matching physical IVF rows on both observers. Flushing just the metadata and centroids hides the reader defect. The committed regression instead deliberately leaves these two tables **unflushed**. A separate one-row table also checks the same remote SELECT before and after its own flush. - **Review regression:** With the exact d227e96 production files and the final regression tests, the coordinator-first, coordinator-last, and mixed-source build cases all lost the peer join (1 probe stage instead of 2). All three pass on 69e6e21. The tests round-trip the peer pipeline, verify its HashJoin and colocated HashBuild, matching JoinMap tag and remote receiver UUID/address, and verify the original producer register. No-host and forced-single controls still gather safely. - **Standalone (69e6e21, Linux/amd64, Go 1.26.4):** full compiler package passed (34.408s); four focused compiler controls including all 11 placement cases passed five repetitions with `-race -short -tags matrixone_test`; scoped `go vet` passed. Isolated two-CN SQL fixture passed (16.68s). The peer read row 42 before and after flush. Both observers saw IVF total/exact `1/1`, and old/new full-text postings `1/0` after rollback and `0/1` after commit, with the correct base text and vector. - **Combined integration, not a PR dependency merge:** locally merged exactly 69e6e21 and #33153 at e746fb5 with no conflicts. The IVF replay/wire, JOIN placement, singleton reader and writable-workspace placement regressions passed together; the isolated two-CN public SQL fixture passed again (16.66s). That validation used the explicit-transaction scheduling guard from #33153. The current PR also carries that same scheduling commit, independently of the IVF changes. These results establish correctness and plan placement, not a production throughput benchmark. The local race result above is targeted, not a full compiler race result. ### Follow-up to review 6043625892 The writable workspace belongs to the ingress CN. AP statements after a write now require that owner to be eligible and included in the selected worker set. With a one-worker cap the owner executes the scan. When the owner is draining or excluded by placement, the statement returns an explicit scheduling error. Read-only transactions can still use a sole remote worker. The shared scheduling change comes from commit `fa605a7846` of #33153. On the reviewed head `69e6e2109b`, an ordinary unflushed table contained committed key 42. A transaction deleted 42, inserted 43, and a remote SELECT succeeded with key 42. On the revised head, the draining ingress rejects that query with `current-cn-draining`. The eligible owner returns just key 43. In the WINDOW regression, the reviewed head collapsed three valid two-probe broadcasts to one stage. The revised head retains both JOINs with the coordinator listed first, last, or with a mixed build. The tests also check the coordinator WINDOW, the decoded peer HashJoin/HashBuild and its dispatch registration, and the no-host, forced-single and shuffle cases. Tested revision: `bd998a2ed0` against 4.2 base `bb197e5118`. The complete compiler, scheduler, and isolated two-CN SQL packages passed. The SQL fixture also checked FULLTEXT postings and physical IVF entries after both rollback and commit. - A separate public SQL comparison used two Working CNs and 131,072 probe rows. Both revisions returned 131,072 rows and a sum of 327,680. The executed plan on `69e6e2109b` had the WINDOW and hash join on the coordinator and no hash join or hash build on the peer. On `bd998a2ed0` the WINDOW stayed on the coordinator, and both CNs had their own hash join and hash build. This checks operator placement; no throughput comparison was made. - A three-CN SQL fixture with 8,600,005 rows exercised read-your-writes and downstream materialization. A Working owner with a cap of one or two workers returned the replacement key and all three observers read the correct committed summary. A draining owner received an explicit error on both SELECT and INSERT … SELECT and wrote no summary. Prepared SELECTs passed for both owner states. The first run timed out at a preliminary EXPLAIN ANALYZE scheduling check in the two prepared cases, before executing them. Their successful rerun used EXPLAIN VERBOSE for that preliminary check and executed the prepared queries and materializations against the full dataset. - The JOIN placement, compiler workspace, and worker-selection regressions passed three repetitions with `-race -short -tags matrixone_test`. Scoped `go vet` passed and incremental lint reported zero issues. Approved-by: XuPeng-SH <[email protected]>
|
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: 80c9f7b26cc0aef01e460915d6b3d11befb25c84
Assessment: approve
The IVF entries scan now assigns an appendable snapshot file and its in-memory replay representation to the same ordinal-zero owner, preserving a single visible candidate across mixed replay states while immutable objects retain ObjectID distribution. The change reuses existing scan identity and shuffle ownership rather than adding a protocol mode; the previous legacy-wire finding is resolved. The workspace-owner scheduling safeguard in the patch is already identical on the pinned target base.
Model: gpt-6.1-terra / max
Session: 01a2110f-4081-7e00-8415-e36a337ad118 · slot 0 · generation 12
Validation:
-
Isolation preflight passed (checks/1795597239048354285-3.json; preflight.log).
-
The full pkg/sql/schedule package passed with the assigned test executor (checks/1795597280408408157-2.json; schedule-test.log).
-
Focused pkg/sql/compile and pkg/sql/plan tests passed, including both scan routes across all four replay-order combinations, single-CN and immutable-object controls, native instruction encoding and workspace placement (checks/1795597958801675161-2.json; focused-test.log).
-
Native prerequisites were built in the diagnostic directory from source-matched cgo and third-party inputs; build logs and command receipts are retained. The preceding review recorded a four-CN same-version frontend SQL test and release-format source trace on the earlier head; the current tests cover the changed ownership rule and removal of the wire mode.
Limitations:
-
The mixed-replay matrix was exercised at the storage and scan-component boundary, not through a synchronized multi-CN SQL replay test on this head. The earlier review reports its frontend SQL test on a previous head.
-
The prior review reports comparing v4.2.9 and the v4.2.8 hotfix appendable-flag producers; the v4.2.9 tag is not present in this checkout and that release-artifact trace was not independently rerun here.
❌ Left the queue ·
|
## What type of PR is this? - [x] BUG - [x] Test and CI ## Which issue(s) this PR fixes Refs #33149 (main implementation; #33153 is the 4.2 companion). ## What this PR does / why we need it At the same read snapshot, two CNs can have applied different parts of the flush logtail. One can see an IVF entry in replay memory and the other can see the same entry in the old appendable object's file with its original commit timestamp. Assigning replay rows to the memory owner but assigning the appendable file by ObjectID can return the entry twice, or not at all. The historical Top‑10 observation did not retain per-CN candidate RowIDs; the deterministic storage test demonstrates the failure mechanism independently. Check the appendable flag before the IVF ObjectID hash in the existing storage shuffle predicate. Both representations follow the existing replay-memory reader (`IsLocalCN`); immutable objects still use the full ObjectID hash. Non-IVF shuffle and single-reader behavior are unchanged. There is no post-LIMIT deduplication, index format change, new MORPC version, protobuf marker, query-wide peer probe, or old-peer fallback. Existing protocol checks for executed scans and their session knobs remain unchanged from main. ### Verification - Storage regression with real replay rows, flushed appendable file and later immutable replacement; both mixed replay orders and both aligned controls. - Compiler regression with a failing peer: a partitionable IVF scan beneath literal `LIMIT 0` compiles without a peer probe; the `LIMIT 1` control still propagates the peer error. Placement coverage switches ingress with two and three workers. - Two-CN SQL regression: exact ordered primary keys from both ingress CNs, remote execution in the physical plan, and transaction rollback/commit checks. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes
Refs #33149 (
4.2-dev).What this PR does / why we need it
In the 4.2 SQL-based IVF search, an inner entries scan can be locally executed on more than one CN. Only one of those readers owns the committed in-memory rows. An appendable file and its pre-flush memory representation must have that same logical owner at an identical logical snapshot. Otherwise opposing CN replay orders produce a duplicate or an omission, even when each CN's own view is correct.
Do not change how immutable objects are distributed and do not hide the error with a DISTINCT. No index rebuild, catalog/data migration, or change to score calculation.
Upgrade (4.2): stop the entire cluster (CN, TN, LogService and proxy), replace all binaries, then restart. Rolling upgrades, mixed-version service and downgrade are not supported. All workers apply one rule using the existing scan identity and partition ordinal. No new pipeline opcode, capability negotiation, legacy fallback, or change to persisted data is involved.
IVF validation
TableFunctionandTableScanoperators. The remote codec is identical to the 4.2-dev base.4.2 safeguard: read your own writes on AP scans
A second, independent wrong-result case is covered here without taking #33155 or the main scheduling refactor. After an explicit transaction inserts one key and deletes another, a remote-only AP scan can see the previous committed snapshot. An
INSERT … SELECTcan then successfully commit the wrong summary. A correct source table and an unchanged total row count are not sufficient checks.At execution, only an AP query whose transaction has already written must include the workspace-owning CN among the eligible workers. If a worker cap applies, that CN gets a slot; a Draining/Drained, excluded or out-of-pool owner cannot be silently replaced by a peer. Other workers can still participate. Read-only transactions keep the existing routing. AP prepares don't cache a physical pipeline on 4.2; the check runs when the statement executes. This additional fix does not change JOIN, index algorithms, storage, or the wire format. It cannot repair previously materialized results.
On
fa605a784, the four-CN frontend IVF test passed (17.72s), as did the full compile and schedule packages, the new scheduling test under race (100 repetitions), scoped vet and incremental golangci-lint (0 findings).Two-CN SQL witness (8,600,001 rows, flushed source, no optimizer hint or forced routing,
query_max_workers=1): on the original PR head42713c6athe dirty copy committed successfully: both observers saw source key 43 but persisted summary(marker=42, old=1, new=0, total=8600001). The identical business oracle failed on that build. Onfa605a784the read-only control used the actual remote worker. On the Draining ingress, both dirty operations failed withcurrent-cn-draining; after committing the previous INSERT/DELETE, two fresh observers saw source key 43 and no summary row. On the Working ingress the same transaction and materialization succeeded; both observers saw key 43 and the exact summary(marker=43, old=0, new=1, total=8600001). The public SQL witness passed in 17.67s. This is not a fix for the indexed UPDATE JOIN wait in #33150.After removing the mixed-version path in
e746fb523, the same 8,600,001-row public SQL witness passed again (33.84s), including both post-commit observers. The compile, plan, schedule, engine and readutil packages, the disttae uncommitted-ownership control, scoped vet and incremental lint passed on this revision.