Skip to content

fix(bootstrap): recheck CDC watermark prerequisites in the 4.0.11 upgrade (#30215) - #30642

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
daviszhen:fix-30215-cdc-upgrade
Oct 20, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
daviszhen:fix-30215-cdc-upgrade

Conversation

@daviszhen

@daviszhen daviszhen commented Oct 20, 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:

issue #30215

What this PR does / why we need it:

A fresh official v4.2.5 store (catalog 4.0.6) cannot become SQL-ready on current main. The catalog upgrade aborts at step 4.0.10 -> 4.0.11 with:

alter table mo_catalog.mo_cdc_watermark add column pending_source_table_id ... after owner_generation
-- Unknown column 'owner_generation' in 'Columns Set'

checkTenantUpgrade keeps failing, so authentication never completes and clients hit read timeouts.

Root cause

The entries that add source_table_id and owner_generation to mo_cdc_watermark live in the v4_0_6 cluster handler — but they were merged there after the v4.2.5 release cut. A cluster first deployed at catalog 4.0.6 has already consumed the 4.0.6 step, so its upgrade chain starts at 4.0.6 -> 4.0.7 (driven by the v4_0_7 list) and those entries never run. The chain then reaches 4.0.11, whose pending_source_table_id ALTER anchors AFTER owner_generation on a column that does not exist.

Fix

Recheck both prerequisite columns at the head of the v4_0_11 cluster list, before the entries anchored on them — same idiom already used by the v4_0_11 list itself ('columns deliberately introduced after 4.0.10'). Every entry is gated by its per-column CheckFunc (skip if present), so:

  • stores whose chain did run the v4_0_6 handler (deployed at ≤ 4.0.5) see zero extra DDL and upgrade identically;
  • stores first deployed at exactly 4.0.6 (v4.2.5) now install the anchors before the dependent ALTERs.

The handler retains its published VersionOffset = 2, independently of the four checked entries. The two prerequisite checks repair the existing migration rather than introduce a new handler identity. This preserves recovery of stores with an unfinished (4.0.11, offset 2) target.

Tests

  • Added TestDoCheckUpgradeRetainsHistoricalCDCWatermarkTarget, using the production registry and the persisted literal offset 2. It exercises canResumeUpgrade and doCheckUpgrade for both pending and already-completed cluster steps, verifies that the retained route is read without scheduling a replacement, and keeps mismatched offsets rejected. The test fails before the offset fix and passes after it.
  • TestCDCWatermarkUpgradeAdmission extended: prerequisites run ahead of the anchored columns, already-present columns are skipped (post-retrofit stores issue 0 DDL), protocol gates still block DDL until every CN reaches MORPCVersion106. TestCDCWatermarkColumnsUpgradeMetadata pins the new entry order. go test ./pkg/bootstrap/... all pass.

Real upgrade-path verification (exact reporter scenario, local 1-LogService/TN/CN)

  1. Built the official v4.2.5 sources (1a44f3db), initialized a fresh store, loaded the reporter's row (1,42); confirmed catalog 4.0.6 state 2 and mo_cdc_watermark without the new columns. Clean SIGINT stop.
  2. Bug repro: started an unfixed main binary (309f618995) on a copy of that store → identical failure: Unknown column 'owner_generation', failed to handle version upgrade: 4th: 4.0.10 -> 4.0.11, login ERROR 1815 (HY000): context deadline exceeded / checkTenantUpgrade.
  3. Recovery after failed attempt: started this fix on the failed store → chain completes, all four columns present, login works, row preserved, final 4.0.17 state 2.
  4. Straight path: fresh second v4.2.5 store + this fix directly → every step 4.0.6 → … → 4.0.17 state 2, zero missing-column errors, login & data intact.

…rade (matrixorigin#30215)

Clusters first deployed at catalog 4.0.6 (shipped as v4.2.5) never execute
the v4_0_6 cluster handler: their upgrade chain starts at step 4.0.6 ->
4.0.7, driven by the v4_0_7 list. The entries adding mo_cdc_watermark
columns source_table_id and owner_generation were merged into the
already-consumed v4_0_6 handler after the v4.2.5 cut. Those clusters then
reach 4.0.10 -> 4.0.11, whose pending_source_table_id ALTER anchors after
owner_generation, and the upgrade aborts with
"Unknown column 'owner_generation'", leaving checkTenantUpgrade failing
and SQL login permanently blocked.

Recheck both prerequisite columns at the head of the v4_0_11 cluster list,
ahead of the entries anchored on them. Each addition is gated by the
existing column CheckFunc, so stores that did run the v4_0_6 handler
upgrade identically with no extra DDL.

Verified end to end: a fresh v4.2.5 (1a44f3d) store upgraded by an
unfixed main binary reproduces the reported missing-column failure and
1815 login block; the same store upgraded (and, separately, recovered
after the failed attempt) by this fix completes the chain to 4.0.17, adds
all four columns, preserves user rows, and restores authenticated logins.
@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 →

@daviszhen

Copy link
Copy Markdown
Contributor Author

Local verification at head 6994c12, exact reporter scenario (1 LogService / 1 TN / 1 CN, fresh fresh-store init each time):

Store A — straight upgrade path

  • v4.2.5 (1a44f3db) fresh init: INSERT (1,42) into upgrade_min.t; catalog 4.0.6/offset 5/state 2; mo_cdc_watermark = 6 base columns. Clean SIGINT exit 0.
  • This fix's binary on the same store: authenticated login immediate; select * from upgrade_min.t = (1, 42); mo_version = 4.0.17 state 2; all 11 columns present incl. source_table_id, owner_generation, pending_source_table_id, target_identity; every mo_upgrade step 4.0.6→4.0.17 state 2; 0 missing-column errors in server log.

Store B — bug repro on unfixed main, then recovery

  • Second fresh v4.2.5 store, then baseline main @ 309f618: reproduces the issue text verbatim — Unknown column 'owner_generation' in 'Columns Set', failed to handle version upgrade: 4th: 4.0.10 -> 4.0.11 (true, false, 0, 0), state 0, client ERROR 1815 (HY000): context deadline exceeded / internal error: checkTenantUpgrade.
  • This fix's binary on that already-failed store: upgrade resumes, columns added, login restored, row preserved, final 4.0.17 state 2.

Unit: go test ./pkg/bootstrap/... all pass at 6994c12 (incl. extended v4_0_11 admission tests for entry order, idempotent skip, and protocol gating).

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 91b2d51bf726780763657c808212e410b94ad659

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-xupeng · review

Commit: 91b2d51bf726780763657c808212e410b94ad659

Assessment: request_changes

The prerequisite repair is correctly ordered and idempotent, but it changes the persisted 4.0.11 handler identity and breaks interrupted-upgrade recovery.

Model: gpt-6-astra / xhigh

Session: 01a14d34-4e51-79a3-a62d-6c9c16279dc8 · slot 0 · generation 0

  • P1 pkg/bootstrap/versions/v4_0_11/cluster_upgrade_list.go:38: Start the candidate against a store with an unfinished upgrade targeting catalog 4.0.11, offset 2—the identity advertised when 4.0.11 was the final registered handler.
    Impact: Adding these entries changes VersionOffset from 2 to 4 because upgrade.go:32 derives it from the list length. canResumeUpgrade rejects the mismatch, and doCheckUpgrade takes its Fatal path before running the repair. Preserve the historical offset and add a recovery regression using the real registered handler.
    Evidence: service_upgrade.go:312 requires exact offset equality; lines 186–193 reject an unfinished incompatible target. TestReviewRetainedCDCUpgradeTarget passed its offset-2 metadata control but failed with the actual candidate handler. Retained evidence: upgrade-tests.log and checks/1792484762702901382-2.json under the assigned diagnostic directory.

Validation:

  • Reviewed the complete delta, migration prerequisites, schema consumers, protocol gates, transaction ownership, and recovery coordinator.

  • Isolation preflight passed; native prerequisites were built and provenance verified through repository owners.

  • Both v4_0_11 tests passed, including all six admission scenarios. The additional recovery diagnostic reproduced the finding; the combined command exited 1.

  • Reconciled commands, exact-head fingerprints, exit receipts, and retained logs in validation-audit.json. Source and diagnostic clone remain clean.

Limitations:

  • No live database upgrade or restart was executed; the diagnostic exercised the real recovery-admission method.

  • The full bootstrap suite was not run. Author live-upgrade reports concern an earlier commit and lack retained execution receipts in the supplied evidence.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Addressed both reviews in abe5af055c.

The 4.0.11 handler now retains its published VersionOffset = 2 instead of deriving it from the expanded entry list. The two added entries recheck prerequisites for the existing migration; they must not change the identity used to resume a persisted upgrade. Recovery admission still requires an exact offset match.

Added TestDoCheckUpgradeRetainsHistoricalCDCWatermarkTarget against the production registry. Its catalog fixture uses the literal persisted (4.0.11, 2) identity and the original cluster/tenant flags. It covers a pending cluster step and a completed step whose target has not yet committed Ready, exercises canResumeUpgrade and doCheckUpgrade, verifies that recovery reads the retained offset-2 route without creating a replacement, and rejects offset 4. The test fails on the previous code and passes with the fix. The handler metadata test independently pins the published offset.

Validation on macOS arm64 / Go 1.27.1:

  • Focused historical-target recovery and CDC admission/metadata tests: passed.
  • pkg/bootstrap/... suite with -count=1: passed.
  • Final owning-package rerun after fixture cleanup: passed.
  • Incremental go vet and configured golangci-lint: passed (0 issues).

Before this update, the existing head's CI checks, including the rerun Ubuntu UT, were all successful. The pushed commit starts a new CI run; its results are pending.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Reviewed the complete four-file delta at abe5af055cbbe44561e489e17706725de7d0e008 against 79298b10e2114246c6ef41bde709dbbb4a20bca4, including both prior reviews and the latest recovery fix.

No new blocking finding; approve from the source-review perspective, subject to required CI completing successfully.

  • The prerequisite definitions match the original 4.0.6 migration, and the execution order is correct: source_table_id -> owner_generation -> pending_source_table_id -> target_identity.
  • Per-column checks skip existing columns. Missing-column DDL remains behind MORPCVersion106, and check/DDL errors propagate immediately through the existing transaction-owned upgrade path.
  • Pinning VersionOffset = 2 preserves the published handler identity rather than conflating identity with the expanded entry count. This closes the previous recovery blocker: canResumeUpgrade still requires exact offset equality, and doCheckUpgrade retains the persisted historical route.
  • The new production-registry fixture uses literal historical offset 2, covers both pending and Ready cluster steps while the target remains unfinished, verifies the retained route is read, and keeps offset 4 rejected. Existing schema-admission tests cover absent/present prerequisites and mixed-protocol rejection.

Validation limits: git diff --check passed. My focused local bootstrap test attempt stopped at the repository CGo prerequisite check (missing matching libmo.dylib; primary-worktree native-input reuse rejected), before any test execution. The latest author reports focused recovery tests and pkg/bootstrap/... passing; I have not independently rerun those tests or the live v4.2.5 store upgrade. Current-head UT/SCA/Coverage and both BVT legs were still running when checked; upgrade-compatibility jobs were skipped, not passed.

This is a review comment only, not a formal GitHub approval or a claim that CI is green.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: abe5af055cbbe44561e489e17706725de7d0e008

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: abe5af055cbbe44561e489e17706725de7d0e008

Review belongs to an older commit; it is not a review of the current head.

@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: abe5af055cbbe44561e489e17706725de7d0e008

Assessment: approve

Reviewed the complete four-file delta and affected callers. The prerequisite checks correctly reuse the existing migration executor, preserve ordering and protocol gating, and propagate failures through the transaction owner. Pinning offset 2 closes both earlier recovery findings without weakening identity checks. Added costs are confined to upgrade attempts; no ordinary SQL path changes. No unresolved actionable findings.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Frozen current-head CI reports successful Ubuntu UT, coverage, Linux/arm64 static analysis, shared build, and both BVT legs. The author also reports focused recovery/admission tests and the bootstrap suite passing at this head.

  • Independently reconciled six retained command/source/exit receipts and log hashes. Verified 11,609 prior tracked inputs and 190 unchanged native inputs. Reused 12 CDC partial-schema and failure-boundary cases whose execution logic remains unchanged; earlier recovery failures were treated only as historical controls.

  • Verified the new regression uses the production registry, literal historical offset 2, pending and completed cluster steps, retained-route reads, and rejection of offset 4.

  • Local source/evidence audit and git diff --check passed; source remained unchanged. Receipt: checks/1792491301464133314-4.json. Detailed evidence: /home/xupeng/.local/state/mo-bot/jobs/2028fa31f5d376ac6f8abad9/attempt-1/validation-audit.json.

Limitations:

  • No Go tests or live-store upgrade were rerun in this attempt. Current-head CI evidence contains terminal statuses, not raw per-test logs.

  • Upgrade-compatibility jobs were skipped. The historical v4.2.5 live-upgrade report lacks retained raw logs and is not claimed as independently verified current-head execution.

  • The linked issue's full body was not supplied; review covered the concrete failure and recovery contract documented in the supplied PR and comments.

@mergify mergify Bot added the queued label Oct 20, 2026
@mergify

mergify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-20 10:18 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-20 13:58 UTC · at fc2106c19d8ee433b9d1153d225036f48ddd8264

This pull request spent 3 hours 39 minutes 44 seconds in the queue, with no time running CI.

Reason

Pull request #30642 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

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

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — fc2106c1 Deployed Oct 20, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued 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.

3 participants