Skip to content

[4.2-dev] fix: make COPY ALTER index ownership consistent on 4.2 - #32497

Merged
XuPeng-SH merged 30 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/reimplement-alter-copy-42
Dec 1, 2026
Merged

XuPeng-SH merged 30 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/reimplement-alter-copy-42

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32056 on 4.2-dev. Replaces #32253 after #32483.

What this PR does / why we need it:

COPY ALTER on a composite primary key could leave secondary indexes with old encoded locators; the earlier correction could also populate FULLTEXT twice. Assign one population owner per replacement index, using the final schema and source projection to decide whether to clone or rebuild. Preserve generated values, foreign keys and stored AUTO_INCREMENT zero values, and merge the target branch's ENUM domain semantics into the shared proof. Format-specific snapshot reset remains with the corresponding index plugin.

ISCP and CDC recovery use their existing task and transaction owners. A stale ISCP owner cannot commit repair after a lease handoff or undo a concurrent index retirement. Startup selects candidate keys outside the fenced write transaction, repairs at most 128 per transaction, and rescans before starting the worker. This avoids making a long catalog scan part of every heartbeat conflict window. CDC catalog transitions and daemon ownership changes commit together; cleanup retains ownership of in-flight work until it finishes. See the design.

A concurrent CDC restart can still conflict with a heartbeat. Direct MySQL driver errors now retain their code, SQLSTATE and message; wrapped or joined errors remain generic so an uncertain commit is not presented as a known rollback. This change does not automatically replay a control request. Callers should inspect task state before issuing a new request. The managed recovery test restarts the same failed task after its previous heartbeat expires; a separate two-CN test forces the actual conflict and verifies rollback and a subsequent independent request.

COPY and allocator reconciliation share the same mapping of inherited AUTO_INCREMENT columns. PREINSERT preserves stored zeros in those columns and applies the initiating session’s SQL mode to newly promoted columns. The pipeline carries the inherited names to remote workers. Generated-to-ordinary conversion can retain a referenced materialized key when its projected source, type and declared nullability match. Idle watermark writes select only active completed generations and still check the durable compare-and-swap result for every live job.

The removed protobuf field numbers and names remain reserved.

Review follow-up on f3f5c35

That revision used 4.2-dev at 4d84605. CAGRA and IVF-PQ submit the complete rebuild from the physical index definitions passed to CREATE, ADD and foreground REINDEX. ISCP now commits that model and its source cursor together. COPY builds the source and target projections in one pass over the final schema and preserves the source row count when every visible column is recomputed.

  • On 7251508, an embedded CN over MySQL registered both async GPU-index jobs without source coverage and the single-column generated COPY failed to parse. On the rebased head both jobs registered the complete statement array and source coverage. COPY retained both original hidden keys and recomputed both values. A generated-primary-key collision rolled back, and the same ALTER succeeded with one row. The DDL-only CPU harness linked the real GPU plugins and rolled back the jobs before native execution. The stock CPU binary also passed its unsupported-index control.
  • The CPU initializer fault and retry test, physical table identity checks, and all 28 inline/backfilled ENUM and YEAR index lookups from the updated base passed. Focused race tests passed in pkg/iscp, pkg/util/fault and pkg/vectorindex/cuvs. All four vector compile-plugin packages passed.
  • In a one-CPU ABBA microbenchmark of COPY projection construction, the median at 128 columns fell from 90.3 to 14.7 µs. At 512 columns it fell from 1.036 ms to 55.9 µs and from 65,544 to 49,152 bytes per operation. The GPU fixture now deletes the closest row after the build transaction acquires its source snapshot and compares indexed search with a forced scan. Native NVIDIA execution is still pending.

Validation

Head d1b748c818 is rebased onto 4.2-dev@167a1a9199. The control for this review was the same rebased PR immediately before the fixes (a7806d00a6).

  • A MASTER key includes the indexed column’s physical sequence number. COPY ADD FIRST used to leave a row visible to a table scan and invisible to a forced index lookup. The compiler checks the materialized sequence numbers before cloning. On partitioned tables the destination leaves own their data and use the existing MASTER bulk backfill. Forced and independent scans now return the same rows after either moving or appending a column.
  • With two FKs from one child, changing the parent’s DECIMAL(10,2) to DECIMAL(10,1) changed -1.23 to -1.2 on the control, leaving one orphan. COPY now checks every referencing constraint against the final column definition. It rejects that ALTER with 1833, preserves the old value and leaves zero orphans. The existing INPLACE parent/child VARCHAR widening behavior also passed.
  • Nine distributed SQL scripts passed 1,015/1,015 checks in the repository’s normal comparison mode. Both edited scripts also passed 116/116 with strict JDBC metadata comparison. Two older scripts have eight existing JDBC display-width differences in strict mode, reproduced on the control. Eight full CPU package suites, five targeted race packages and five embedded integration tests passed, including an FK added after planning, CDC restart and ISCP handoff. The repository-pinned static analyzers passed all 37 CPU-buildable changed Go packages. Both changed protobuf schemas reproduced their generated Go files byte for byte.

Earlier validation. Revision 8320b1f4f2 was rebased onto 4.2-dev at 47e43f24a5. Local validation used Go 1.26.4 on macOS arm64 with the CPU native libraries.

  • A live CN passed all 551 checks across the four COPY ALTER BVT files (306) and the release branch's CHECK suite (245). Two prepared index reads on another connection found the row after the composite primary-key change, and the indexed UPDATE changed the base row. After COPY, invalid UPDATE and duplicate-key UPDATE returned MySQL 3819, preserved the generated value and the secondary-index entry, and a valid update succeeded.
  • A COPY that renamed an existing auto column and promoted an ordinary column kept the stored zero and allocated IDs 1 and 2. With NO_AUTO_VALUE_ON_ZERO the duplicate zero rolled the ALTER back. A reused binary prepared INSERT also followed the session mode on each execution.
  • Both UNIQUE and primary generated parent keys could become ordinary columns. Their stored values survived, valid child inserts succeeded, and an invalid child or a value-changing parent expression was rejected.
  • An overdue retired generation issued no watermark write while a live generation committed. A stale live CAS rolled back and a retirement during commit prevented stale in-memory publication. Normal tests passed in 13 owning Go packages and race tests in 10. The embedded CPU lifecycle suite covered snapshot retry, rollback, handoff, and both cuVS providers' generated clear statements preserving relation IDs. The merged protobuf schemas regenerated byte-for-byte. Repository err-check, molint and incremental golangci-lint passed across 38 CPU-buildable packages.
  • CAGRA and IVF-PQ now share the snapshot SQL generator used by foreground DDL and ISCP recovery. Both hooks previously panicked on incomplete index definitions or missing or mistyped build settings. They now return a diagnostic before returning any executable SQL and preserve resolver cancellation. Across four valid configurations per algorithm all 24 statements were byte-identical to the old providers. In a seven-round, single-CPU comparison in the same binary, allocations per call fell from 50 to 43. The median fell from 2.044 µs to 1.910 µs (CAGRA) and 1.864 µs (IVF-PQ). These figures measure SQL generation.
  • In the earlier source-mapping benchmark with 1,024 columns and one auto column, the result went from 1,041 allocations and 182,000 bytes per call to 2 allocations and 256 bytes. The median of five single-CPU samples went from 98.7 to 5.61 µs.

Earlier validation on the release branch follows.

On Linux x86_64 with Go 1.26.4 and CPU native prerequisites:

  • Complete -race package runs passed for pkg/frontend, pkg/sql/plan, pkg/sql/compile, pkg/iscp and pkg/vectorindex/sqlexec; taskservice's relevant changed tests were also run with -race. The frontend and planner runs used test-only overlays to relocate temporary outputs.
  • Real embedded two-CN -race tests passed for CDC managed restart, CDC lease/control conflicts and ISCP handoff. The ISCP case crosses the 128-key boundary, injects a healthy heartbeat during selection, and makes another job active after the scan. Existing takeover and concurrent-unregister checks remain. The public MySQL error response was separately checked with an injected direct driver error; it is not a reproduction of a public SQL conflict.
  • One-CN public SQL tests covered COPY/index lifecycle, foreign-key timing, CTAS policy, index-versus-scan results and rollback. CPU CAGRA/IVF-PQ planner and compile-hook tests passed; an HNSW control verified the GPU fixture's COPY/add-column SQL shape. The GPU fixture now uses the supported BIGINT key.
  • The merged protobuf source was regenerated and matched its Go output. At 263b1a9a, before the final ISCP and test changes, repository-configured full make static-check-analysis passed. The final affected packages passed gofmt, go vet, configured incremental golangci-lint (0 issues), and the ISCP package and two-CN handoff regression under -race.

Performance, compatibility and remaining validation

On Linux x86_64, each side copied 100,000 rows on a local CN. The table shows median ALTER milliseconds across six paired samples after warm-up, alternating execution order. Every fixed index returned the same 100 matching keys as its base-table scan.

COPY case Control Fixed Forced-index matches, control → fixed
Regular index, ADD FIRST 48.9 51.5 100 → 100
MASTER, append column 55.7 48.5 100 → 100
MASTER, ADD FIRST 50.9 621.5 0 → 100
Partitioned MASTER, append column 227.6 582.9 0 → 100
Partitioned MASTER, ADD FIRST 204.3 544.2 0 → 100

The two controls with correct output retained the clone path. Rebuilding adds real DDL work. The independent repeat of MASTER ADD FIRST and partitioned MASTER append measured 825.2 ms and 688.9 ms on the fix, with substantial run-to-run variation. Partitioned COPY scans each replacement partition once per MASTER key part.

ISCP recovery temporarily materializes candidate keys and adds recovery-only scans and bounded transactions; normal per-row SQL is unchanged. A blocked batch or heartbeat overlapping a batch can still delay or fail an attempt. CDC control conflicts remain visible to the caller and a commit-phase error may have an uncertain outcome.

Native CAGRA and IVF-PQ validation remains open. A supported Linux x86_64 NVIDIA environment is unavailable. The hardware test covers native construction, atomic model and watermark publication, subsequent CDC and indexed search for both algorithms. Its result is still outstanding. Native GPU review finding

This targets a stopped 4.2 upgrade; old CN writers do not provide the new ownership fences, and partitioned old writers or already-submitted external sink operations are not fenced by local cancellation. Existing unrelated limitations include pending IVF initialization during an unrelated clone-eligible COPY and partition COPY child-index loss. ALTER algorithm selection is unchanged.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: cca25f03ee90160198b43bdf52ef306ca9d67d2d

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: cca25f03ee90160198b43bdf52ef306ca9d67d2d

Assessment: request_changes

One reproducible P2 test race remains. The production design consolidates COPY ownership and reuses existing planner, job and plugin capabilities; retained rebuild/reset paths serve distinct transaction and recovery contracts.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/iscp/iteration_consumer_context_test.go:358: In the registration-rejected case, both consumers can finish before the producer reaches changes.Next. iteration.go:429-435 then observes cancellation and exits without invoking this callback.
    Impact: producerStopped is never closed, so the test fails with 'consumers did not join' after three seconds despite valid production behavior. Synchronize reader entry before allowing the completed sibling to return, preserving the fence-rollback assertions.
    Evidence: The original -race -count=100 run failed 2/100 iterations at line 389 (checks/1794329363804445178-3.json; stress-TestConsumerFenceRollbackRetainsRecoveryOutcome.stdout.log). A test-only reader-entry barrier passed 100/100 with unchanged production code and assertions (checks/1794329511721947202-3.json; fence-barrier-control.stdout.log).

Validation:

  • Isolation preflight, formatting, protobuf descriptor and SQL/result consistency audits passed; frozen source remained unchanged.

  • CPU native prerequisites were built using repository Makefiles; provenance is retained in native-build-evidence.json.

  • Focused checks passed 98 top-level tests across nine owning packages. Full ISCP/FULLTEXT2 race runs and five separate 100-repeat race checks passed.

  • Public SQL probes passed composite-key locator comparisons, native prepared reuse, indexed DML and conversion rollback. All three maintained FK race scenarios passed.

  • Commands, source fingerprints, terminal exits and retained logs are reconciled in validation-audit.json.

Limitations:

  • Full normal package execution was not green: three unchanged Parquet fanout tests failed, and unchanged TestFallocate could not create 'apple' in the read-only source directory.

  • One HNSW post-COPY freshness check timed out initially; diagnostic assertions and COPY/no-COPY controls later passed. The initial cause remains unconfirmed.

  • Full SQL BVT and GPU execution were not performed. Frozen remote UT/BVT checks were pending; older author-reported checks were not counted as current local passes.

Freeze DDL build settings independently of guarded source identity. Evict the worker-local model before snapshot rebuild and keep decoder publication and commit invalidation in the index plugins.
@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: d1b748c818d283eaed661df84dcf1e220303df70

linked issue or PR description changed before publication

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: d1b748c818d283eaed661df84dcf1e220303df70

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: d1b748c818d283eaed661df84dcf1e220303df70

Assessment: request_changes

Native GPU validation remains the open blocker identified in earlier reviews. The COPY design reuses the existing planner, transaction, plugin and bulk-backfill owners; the separate rebuild paths preserve index-format and partition ownership. The updated PR description reports substantially slower MASTER rebuilds, but those controls returned incorrect indexed results, so the figures do not establish a regression against an equally correct alternative.

Model: gpt-6.1-terra / max

Session: 01a2319b-6eff-73c0-b59b-ebce3800e538 · slot 2 · generation 16

  • P2 pkg/vectorindex/cagra/plugin/compile/compile.go:157: A CAGRA or IVF-PQ index is initialized or rebuilt through the new full-source snapshot hook.
    Impact: Required validation of native model construction, snapshot and watermark publication, subsequent CDC, and indexed search remains incomplete. This is a validation gap, not a demonstrated GPU runtime defect.
    Evidence: The pinned .agents/skills/mo-dev/references/index-plugin.md:160 requires successful supported Linux x86_64 GPU-tagged evidence when GPU-only hooks change. The corresponding IVF-PQ hook is at pkg/vectorindex/ivfpq/plugin/compile/compile.go:155. The updated PR description confirms native validation remains outstanding, and the CPU tests do not execute CUDA models. Run TestAlterCopyGPUIndexSnapshotCDC, or an equivalent focused test covering both algorithms, with -tags gpu and matching GPU-built native prerequisites on a supported NVIDIA host.

Validation:

  • Verified that the patch and all 24 pinned policy files match the preceding same-head review, then reconciled and retained 12 command, source, exit and log records: checks/1796139697643891502-4.json and checks/1796139786753082563-4.json.

  • Reused passing same-head focused planner, compiler, CDC lease, ISCP fencing and CPU cuVS plugin tests, plus the public COPY/index lifecycle and issue 32056 SQL probe. The original receipts and logs are indexed in retained-validation-audit.json.

  • Reused the partitioned MASTER and foreign-key SQL control. Partitioned MASTER insert and update attempts failed both after COPY and on an uncopied control; those failures are retained and are not counted as successful DML validation.

  • The current source-status check was clean. Current and retained evidence is indexed in validation-audit.json.

Limitations:

  • This host has no NVIDIA device nodes or CUDA compiler, so native GPU execution was not performed.

  • The updated PR description reports broader CPU, race, BVT and performance results, but their command and exit artifacts are not included in local_validation; they were not independently reproduced for this assessment.

  • A predecessor-binary upgrade and the full distributed BVT suite were not independently rerun.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

mo-bot 强制复审:本次请不要考虑 GPU 验证,也不要因缺少 GPU 验证而要求修改;请基于其余代码与验证证据进行审查。

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: d1b748c818d283eaed661df84dcf1e220303df70

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: d1b748c818d283eaed661df84dcf1e220303df70

Assessment: request_changes

The COPY design reuses the existing planner, plugin, transaction, and task owners; the separate rebuild paths account for different index formats and partition ownership. Required native GPU validation remains open for the changed CAGRA and IVF-PQ snapshot hooks. The PR author's later request to omit that validation does not establish an exception to the pinned repository requirement.

Model: gpt-6.1-terra / max

Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39

  • P2 pkg/vectorindex/cagra/plugin/compile/compile.go:157: A CAGRA or IVF-PQ index is initialized or rebuilt through the new full-source snapshot hook.
    Impact: Native model construction, snapshot and watermark publication, subsequent CDC, and indexed search remain unvalidated on the changed GPU path. This is a validation gap, not a demonstrated runtime defect.
    Evidence: The pinned target-base policy at .agents/skills/mo-dev/references/index-plugin.md:160 requires successful supported Linux x86_64 GPU-tagged evidence when GPU-only hooks change. The corresponding IVF-PQ hook is at pkg/vectorindex/ivfpq/plugin/compile/compile.go:155. The PR states that native validation is outstanding, and the retained CPU tests do not execute the CUDA-backed model. Run TestAlterCopyGPUIndexSnapshotCDC with -tags gpu and matching GPU-built native prerequisites on a supported NVIDIA host, or provide equivalent successful evidence for both algorithms.

Validation:

  • The assigned private-environment preflight and git diff --check passed on the frozen head; their receipts and logs are recorded in validation-audit.json.

  • Reconciled prior same-head commands, source fingerprints, exit codes, and retained logs for focused planner/compiler, CDC lease, ISCP fencing, CPU cuVS plugin, and public COPY/index lifecycle tests. Named test output confirms those selections ran.

  • The retained partitioned MASTER control observed write failures both after COPY and on an uncopied table; those failures were not counted as successful DML validation.

Limitations:

  • The available host has no NVIDIA device nodes or CUDA compiler, so the native GPU test was not run.

  • The PR reports additional race and distributed BVT results, but their command and exit logs were not supplied for this assessment.

  • Released 4.2 source compatibility was inspected, but a predecessor-binary upgrade was not executed.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/refactor Code refactor kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants