Skip to content

fix(view): activate durable metadata refresh - #27734

Closed
ck89119 wants to merge 75 commits into
matrixorigin:mainfrom
ck89119:issue-26227-activation-main-clean
Closed

ck89119 wants to merge 75 commits into
matrixorigin:mainfrom
ck89119:issue-26227-activation-main-clean

Conversation

@ck89119

@ck89119 ck89119 commented Aug 27, 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 #26227

What this PR does / why we need it:

This is the final activation layer for the View metadata lifecycle built by #27267 and #27370 on top of the durable admission contract from #27430.

It:

  • advertises refresh support only after a CN observes the exact final catalog version and offset in READY state;
  • lets HAKeeper activate refresh only after every HAKeeper replica and known CN supports the lifecycle;
  • fences public metadata readers before a new membership epoch can require catalog revalidation;
  • runs one bounded, stopper-owned recovery worker per CN and acknowledges an epoch only after the durable catalog pass reaches a terminal state;
  • keeps refresh sealed when an epoch advance is canceled, rejects metadata-sensitive work from an older transaction epoch, and fences lifecycle-unaware CN or HAKeeper rollback;
  • enables fail-closed behavior for DESC, SHOW COLUMNS, information_schema.columns, and current-catalog CTAS while ordinary View queries continue to rebind the stored SQL;
  • preserves snapshot, subscription, restore, identity, and typed catalog-readiness behavior;
  • seeds revalidation through an idempotent version-offset upgrade.

The activation authority is the replicated HAKeeper admission epoch. No local MOCluster snapshot can independently authorize refresh.

Historical validation (not current-head evidence):

Design artifact

  • Status: Approved.
  • Current design: View Metadata Lifecycle, including section 12.1 and the wait-for argument.
  • Historical approved checkpoint: 8c2332ecbbfc6e6c2196e734d345875b2edac134; review 5126100008 on bb1e8259c3f8f30f20a8617925c4c81f3243094b.
  • Approved lock-protocol semantic checkpoint: a97f8074d7514428d042de482650c7b4f3f855e1; review 5218046900 by fengttt on cec64fc8abfe9b069987c1ead07b681f4d9a883a.
  • Current conformance head: a0fa7058fdf0093bf161f14454030e92879b2318 (base 66b1672403); documentation head: 95d99e7aa211b8e3ae82be41b768f11a707834fb. Changes after the approval head merge main, align test fixtures, and restore the documented post-lock atomic validation contract by restarting the owned DATA BRANCH DELETE admission/lock/validation transaction on an RC retry; they do not change the approved lock-protocol semantics.
  • Background Require/Start revalidation and CTL recovery now wait for the legacy View gate before trying SNAPSHOT with FastFail. They never wait for SNAPSHOT while holding View; errors return to the transaction owner for rollback. Successful recovery still retains both gates. Frontend/older-CN ordering and owner COMMIT write validation remain unchanged.

Lock-protocol checkpoint validation (a97f8074d7):

  • Full compile package: normal and race passed.
  • Deterministic recovery lock-policy/error regression: race, 100 repetitions passed.
  • Previously failing TestIssue26087ConcurrentDataBranchQuota: race, 3 repetitions passed (the same command failed before this fix).
  • Complete TestDataBranchDiffAsFile: normal and race passed, without retries or weaker assertions.
  • Two-CN restore commit fence and View/SNAPSHOT gate-order SQL regressions: race passed.
  • CN ViewMetadata/BootstrapRetirement focused tests passed.
  • Focused coverage: recovery gate helper and Require/Start revalidation 100%; CTL entry 87.5%.
  • Full current BVT/CI and a new mixed-version binary sequence have not been verified. The historical evidence below is not relabeled as current-head validation.

Latest CI follow-up (28a63bd5b4):

  • Fixed the overly narrow waiter assertion in TestIssue27040ConcurrentIfNotExistsDatabaseClone: identify the first clone by its exact destination catalog key, then require a waiter behind that transaction on the lineage or destination-catalog boundary. Early-return and committed uniqueness/data assertions remain unchanged.
  • Focused test passed three times each in normal, race, and frontend/compile/lockservice coverage-instrumented modes; the full issues package passed.
  • Run 34308560098 had this real coverage-test failure. Ordinary UT and both BVT jobs were interrupted at the same cancellation time; their incomplete executions are not counted as passes. No new production workaround or blind retry was added.

Review closure evidence

  • Metadata-sensitive statement classification is AST-based at the frontend admission boundary. It walks table references for information_schema.columns; comments/formatting cannot bypass the fence, while CTE aliases and string literals do not create false positives.
  • Historical PR-head binary evidence: d3a06e7978d9eee2453be5b0f6b0d02a2172cbc9; exact old/base binary: 6b8987741df912f38cece5bd026349d79672faf9.
  • A real 1 LogService/HAKeeper + 1 TN + 2 independently replaced CN sequence passed: all-old stale metadata (VARCHAR(12)), one-new/one-old capability-disabled legacy metadata (VARCHAR(12)), all-new activation (VARCHAR(48)), same-UUID CN restart, old-binary rollback denied before ingress, new-binary recovery, snapshot restore revalidation, and immediate whole-cluster restart.
  • The first restart run exposed a 30s startup deadline vs. old-generation expiry race. The final head preserves the old-owner safety fence and gives admission a second discovery window; CN/HAKeeper normal and race owning-package tests pass.
  • Historical CI checkpoint 6f15067b02 fixed Rows lifecycle SCA findings and added bounded lifecycle waits to four pre-existing View BVTs; the lifecycle BVT followed by all four affected tests passed 220/220. That historical BVT/build/lint evidence remains supplementary rather than being relabeled as current-head evidence.
  • Historical approved semantic checkpoint 351397e59a286ff13cef6113904f24313310a03c separates provisional epoch admission from metadata authority: ordinary base-table and binary prepared/cached planning remain available after authority expiry, while SHOW COLUMNS and information_schema.columns fail closed and recover after renewal. The frontend boundary test passes normally and with -race -count=100; full frontend, compile, and CN owning-package UTs pass.
  • The provisional gate remains sealed after a canceled epoch advance until requestedEpoch is published; focused fence race stress covers this path. Successful metadata completion now releases while sensitivity is still set, deterministically resetting the connection write deadline before clearing statement state.
  • The previous unrelated TestIssue26114CrossAccountBranchQuotaAndOwnership failure is outside this View lifecycle diff; Coverage failed only because a required producer failed.
  • Upstream upgrade Target/Release jobs are hard-disabled with if: false; those SKIPPED jobs are not counted as evidence.

Review round 2 closure

  • Epoch-0 metadata-sensitive readers now acquire a generation lease; TestViewMetadataInitialRefreshLeaseBlocksFirstAdvance proves the first Advance(1) cannot publish until that lease drains.
  • Same-UUID replacement snapshots now carry the authoritative remaining owner-expiry ticks and tick rate persisted by the HAKeeper RSM. CN startup derives its deadline from that owner expiry plus one discovery/reconciliation window; custom discovery=5s, owner remaining=30.1s yields a 36s budget rather than the old fixed 10s.
  • The AST detector is CTE-scope-aware. An unqualified columns shadowed by a CTE under default information_schema is ordinary work, while an explicitly qualified relation and a real information_schema.columns reference inside a CTE still acquire the lease.
  • Historical lifecycle-protocol revision (49364cd460, superseded and not current-head evidence) mixed-version run against base (6b8987741d) passed all-old, partial fail-closed, all-new activation, snapshot restore, same-UUID restart, old-binary rollback denial, recovery, and immediate full-cluster restart.

@mergify mergify Bot added the kind/bug Something isn't working label Aug 27, 2026
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Aug 27, 2026
@ck89119

ck89119 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed in 80ed6eb1676fbc90110c1f9cfc14f30652a51fae.

The design document and PR body now consistently record the lifecycle design as approved. They link fengttt's approval review 5218046900 on cec64fc8abfe9b069987c1ead07b681f4d9a883a, which contains the background lock-coordination semantic checkpoint a97f8074d7514428d042de482650c7b4f3f855e1.

The records now distinguish the approved semantic checkpoint, current conformance head, and documentation head, and explicitly state that the subsequent main merges, fixture alignment, and documentation updates do not alter the approved lock protocol.

Could you please re-review the updated approval/conformance record?

@aptend aptend 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.

Re-review of exact head 80ed6eb1676fbc90110c1f9cfc14f30652a51fae against base 091825aac2c8785d912f8d3eceb0e38de320e57a and my previous reviewed head 157d30c54b3754dac17991df5bba9b29a0026db5.

I read all 22 historical reviews and all 6 review threads (including the stale/outdated unresolved design-gate thread), checked the increment since my prior review, and rechecked the full diff. The prior task-index idempotence blocker is closed, and the design plus a97f8074d7514428d042de482650c7b4f3f855e1 lock-protocol checkpoint now have traceable approval. One integration blocker remains on the current activation head.

The exact-head GitHub run 35050888991 attempt 1 failed independently in both Ubuntu/x86 UT and UT Coverage at TestIssue26068DataBranchDatabaseIdentityLifecycle/delete_validates_after_exclusive_database_lock: after the concurrent CREATE TABLE commits, DATA BRANCH DELETE DATABASE returns txn need retry in rc mode instead of performing the required post-lock validation and returning the inactive-branch-table error. This is not just a remote-run artifact: on this head, the shared-cluster race sequence through the tests preceding issue 26068, repeated with -count=5, reproduced the same failure in two local runs (the second failed 3/5 iterations); the identical command on exact base passed 5/5. The isolated issue test passes (-count=3 normal and -race -count=10), which is why this needs shared-cluster/stateful regression coverage rather than another isolated rerun.

The failure surfaces at pkg/frontend/data_branch.go:899-925: the owned pessimistic-RC background transaction crosses the SNAPSHOT lineage barrier in getLineageOwnerMutationExecutor, then lockDataBranchDeleteDatabaseTarget waits for the target mo_database row. After the creator commits, the lock returns ErrTxnNeedRetry; internal background execution does not retry the statement, so the retry leaks to the client before validateDataBranchDeleteDatabaseTarget can inspect local_t. Please make this owned transaction safely restart and repeat admission + target locking + validation on this retry (or otherwise restore the same atomic post-lock contract), and retain a deterministic shared-cluster regression.

Validation: make thirdparties; owning packages pkg/bootstrap/versions/v4_0_6, pkg/hakeeper, pkg/logservice, pkg/cnservice, pkg/sql/compile, and pkg/frontend pass; isolated issue test normal/race passes as noted; current-main merge-tree is clean. git diff --check only reports the two existing trailing-space table rows in pub_sub_view_columns.result. SCA, shared build, Proxy BVT, and pessimistic BVT are green; the required UT/coverage failure remains blocking.

Comment thread pkg/sql/compile/view_metadata.go Resolved

@aptend aptend 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.

Deep re-review completed on exact head 79de124d71f727a66576a0051ae138e486bc9e8e against base 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 and my previous reviewed head 80ed6eb1676fbc90110c1f9cfc14f30652a51fae.

I read all 24 historical reviews, all 7 review threads including the author reply and current resolution state, and the PR conversation; compared the complete increment and rechecked the previously reviewed full-diff closures. The prior DATA BRANCH blocker is closed. On the first target-database-lock ErrTxnNeedRetry / ErrTxnNeedRetryWithDefChanged, a7e85733cb restarts only the owned, non-shared background transaction, reacquires the lineage lifecycle gate, then repeats the target lock and post-lock validation. Shared/explicit transactions, nested lock ownership, and non-retry errors preserve their old behavior; the restart is bounded to one attempt. The later main merge has an empty remerge diff, so it introduced no PR-specific conflict resolution.

The older blockers remain closed on this head: the approved design/lock checkpoints are recorded, task-index upgrade idempotence still parses the physical task-table definition with its all-three-index rerun regression, target-name indexes keep scoped restore cleanup seekable, and the real shared-catalog two-CN restore barrier remains intact.

Exact-head evidence: make thirdparties; focused restart/retry helpers under -race -count=10; issue 26068 alone under -race -count=5; the complete preceding shared-cluster sequence through issue 26068 under -race -count=5; the real two-CN restore barrier under race; full pkg/frontend and pkg/sql/compile; and the task-index idempotence regression all passed. git diff --check reports only the two established table-formatting spaces in pub_sub_view_columns.result. Exact conformance head 4e9b829e76 also has successful required UT, coverage, SCA, and BVT checks. The current-head PROXY BVT failure occurred while pulling eclipse-temurin from Docker Hub (connection reset by peer) before any MatrixOne container started, so it is not product evidence.

I found no remaining correctness, lifecycle, concurrency, compatibility, performance, or test-architecture blocker.

This branch had an error being deployed

1 failed 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 size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants