Skip to content

fix(sql): let ALTER COPY recover from concurrent writes - #33304

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:fix/32120-alter-copy-concurrent-writes
Nov 30, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:fix/32120-alter-copy-concurrent-writes

Conversation

@aptend

@aptend aptend commented Nov 26, 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:

Fixes #32120

What this PR does / why we need it:

ALTER COPY can return 20601 after a concurrent write even when the rebuilt copy already contains the committed rows. A branch created during the copy also exposes a separate risk if the recorded lineage cutoff predates rows in the replacement.

  • Let pessimistic RC COPY ALTER continue after a data-only snapshot refresh at the source table lock. Preserve terminal definition-change conflicts.
  • Validate the copy against the full snapshot the source SELECT used. When publishing lineage, also verify that the recorded cutoff covers the copied source data.
  • Rebuild at most once under the existing publication locks if either check detects a stale copy or lineage cutoff.
  • Add cross-CN SQL regressions for queued INSERT and a late historical branch whose DIFF must report the inherited INSERT.

Validation

  • make static-check-changed STATIC_CHECK_BASE=origin/main GOLANGCI_LINT_CONCURRENCY=6 passed for 33 affected packages.
  • The compile and lock operator suites passed in normal and race modes. Both new SQL regressions passed, including 26 race repetitions for late-branch DIFF and 3 for concurrent INSERT.
  • The pre-fix late-branch counterexample returned 0 differences for one inserted row. The fixed version returned 1 in all 4 runs.
  • With 3 CNs, 2 million seed rows, and 3 concurrent writers, all 18 ALTER attempts succeeded across ADD COLUMN and MODIFY COLUMN cases, including indexed tables. Writer commits, row counts, and values were verified.

@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 26, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: d242d89b23ef76ee2be6abd523f1ae1ddc70a4fe

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

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: d242d89b23ef76ee2be6abd523f1ae1ddc70a4fe

Assessment: approve

The change reuses the existing publication locks and bounded replica rebuild to recover from data-only conflicts. The copy snapshot and lineage cutoff are validated separately, and the reviewed failure paths retain the existing transaction cleanup behavior. No actionable defects remain.

Model: gpt-6.1-terra / max

Session: 01a229e8-c998-7480-862c-3017417a9175 · slot 1 · generation 38

Validation:

  • Focused compiler tests and both new two-CN SQL regressions passed; focused-tests.log, receipt checks/1796013885242669014-3.json.

  • The existing rebuild and LOAD-wait matrix passed, including commit, rollback, mixed DML, indexes, lineage, cancellation, and injected failures; rebuild-matrix.log, receipt checks/1796014001803347116-3.json.

  • The changed compiler checks and both new cross-CN regressions passed under -race in separate runs; compiler-race.log and cross-cn-race.log, receipts checks/1796014634944962411-3.json and checks/1796014784294974264-3.json.

  • Isolation preflight passed, and reused native artifacts were verified against the frozen head’s inputs. Receipt and log details are retained in review-evidence-audit.json.

Limitations:

  • The initial combined race run timed out during compilation; the selected compiler and cross-CN checks subsequently passed in separate runs.

  • The author-reported sustained three-CN workload was not independently repeated. The late-branch regression uses a deterministic snapshot-advancement hook.

@mergify mergify Bot added the queued label Nov 30, 2026
@mergify

mergify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

1 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 30 Nov, 05:02 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 05:03 · d242d89

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-scope-check.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

To get back in the queue

  • Update or rebase the branch yourself: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added dequeued and removed queued labels Nov 30, 2026
@XuPeng-SH
XuPeng-SH merged commit a181849 into matrixorigin:main Nov 30, 2026
5 of 6 checks passed
@mergify mergify Bot removed the dequeued label Nov 30, 2026

This branch was successfully deployed

No deployments
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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ALTER TABLE always fails under concurrent writes (20601)

3 participants