Repository navigation
[4.2-dev] fix(frontend): prevent publication grants from recreating dropped subscriber IDs - #32937
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: 779b97366519d997448c8aa7f166e92a4599d01b
Assessment: approve
The patch reuses account-ID row locks to serialize standalone publication grants with subscriber removal. A grant that resolves a deleted account ID rolls back before writing catalog rows. The cross-CN test observed the retryable error and verified that the surviving subscription remained usable and that a recreated account inherited no grant.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
Validation:
-
Private /tmp and loopback preflight, diff hygiene, and the head-matched native build passed. Retained logs are preflight.log, diff-check.log, and native-build.log.
-
The full pkg/frontend suite passed normally and under -race. Receipts are checks/1795084276098940394-2.json and checks/1795084376430376541-2.json, with logs frontend-normal.jsonl and frontend-race.jsonl.
-
TestDropAccountConcurrentPublicationGrant passed normally and under -race. Both runs recorded the stale ALTER returning a retryable error. Receipts are checks/1795084269137793738-2.json and checks/1795084344392589878-2.json, with logs embed-normal.jsonl and focused-race.jsonl.
-
A reviewer-only SQL probe restored a publication and a working subscription under a newly allocated account ID. Receipt checks/1795084349803416516-2.json matches restore-probe.jsonl and restore-overlay.json.
Limitations:
-
Issue #32900 remains open for the historical revoked subscription rows and their unconfirmed cause.
-
The restore probe used the default transaction mode and covered sequential restore. Concurrent restore in optimistic mode remains unverified.
✅ Merged into
|
|
Post-merge note for 4.2-dev: the independent main review found a conditional lock-footprint regression for single-target publication. The 4.2 branch also promotes lock targets based on LOCK_OP estimated Outcnt. Its planner is not identical to main. The low-threshold two-CN execution cited above tested main, not this backport. Recommend a dedicated 4.2 two-CN scope check: the target DROP must serialize; an unrelated DROP should complete while publication waits for the source DB. Compare pre-backport at the same settings, as DROP itself also locks the catalog. No production outage or default-config large-catalog reproduction is implied. The missing registration for concurrently created subscribers is separate (#32941); #32900 remains open. |
… rows (#32987) ## What type of PR is this? - [x] BUG ## Which issue does this fix? Fixes #32986. Follow-up to #32937 on `4.2-dev`. ## Change A named publication pins each immutable subscriber ID before writing grants. On 4.2 the optimizer could widen even a single-recipient locking read to the whole account table. The matching DROP has two opportunities to widen the lock as well. - Keep the existing transactional `FOR SHARE` read and existence check. For named recipients, sort the final IDs and batch the reads up to the CN's configured row-lock count. A missing ID aborts the statement with the existing retry error. - During planning, bind the internal exact-row requirement to the resolved `mo_catalog.mo_account` target. Plan copies and remote pipeline operators preserve it. That target rejects a covering range or lock-service escalation. Its unique index and pre-pipeline metadata locks keep their separate policies. - At admission, a marked point waits for a foreign covering range to clear. Exact keys can span multiple pooled segments in one transaction. Retained snapshots cover every segment during deadlock checks and unlock. - Ordinary DML submits its full set of shared metadata keys so lock admission can choose a shared range up front. Only pessimistic restore and internal task-storage transactions batch catalog metadata points. DROP ACCOUNT also uses the task service for CDC cleanup in a separate transaction. - Apply the same restriction to the single-account locking read and the final `mo_account` DELETE during DROP. The existing `ACCOUNT ALL` path still uses its previous locking policy. The separate new-account race is tracked in #32941. ## Validation - Reproduced the review report at `944a75da6f`. With one CN, `max-row-lock-count = 1` and no concurrent publication, the final account DELETE returned 20707. On the parent `53b3bc7c95`, the direct DROP succeeded but a cluster restore removing a post-snapshot account failed with 20105 on a shared metadata range. - Added `TestDropAccountWithMinimumRowLockCount`. At the same minimum, direct DROP and RESTORE CLUSTER succeed, the post-snapshot account is absent and the test table contains its original value. In a separate two-CN account snapshot test at the same minimum, the restored account had one active grant on its new ID, zero on its old ID, and read the live published value 10. - Two CNs, one TN, real MySQL DDL, row-lock threshold 16. With 1 and 17 named recipients, the unrelated DROP commits while ALTER is still held at its publication write. The wide case places the unrelated account inside the target ID range. A targeted DROP waits, then leaves zero grants for its old ID. Normal and Go race builds pass. Restoring the five production files from the unpatched branch head makes the same wide case fail at the unrelated DROP's 30-second deadline. - The existing drop/grant race and SHOW PUBLICATIONS SQL tests pass under `-race`. Recreating the same name gives it a different ID and zero inherited grants. An unaffected subscription reads the source row. - Account snapshot restore recreates ID 1 as 10001 with one active grant and reads the live source value 10. A separate optimistic CN/TN run covers ordinary DML, CREATE/ALTER publication, DROP and the surviving subscription (value 7). - Full frontend and lock operator packages pass under `-race`. Five focused planner tests pass. Changed packages pass golangci-lint. - Checked main PR #32936 at `7cd54cda1c`. Its existing CREATE lock-scope and stale-grant tests pass under `-race`. During actual ALTER, the transaction holds exactly 1 or 17 shared point locks on `mo_account`, matching every resolved ID. - In the two-CN range regression, an ordinary transaction holds a shared range before ALTER starts. ALTER waits for it, an unrelated DROP then completes while ALTER is gated at its publication write, and a targeted DROP waits for ALTER. - With a row-lock budget of 16 and a fixed-slice limit of 128, CREATE PUBLICATION grants all 129 named recipients in one transaction. After commit the other CN drops the first and last recipients and reads 127 active grants. Lock and ForwardLock carry the requested mode unchanged. Exact-row locking is a separate flag enforced at the owner. Restore and task-storage transactions use the remote owner from the first request on a proxied table through unlock. The transaction option travels with distributed execution and is cleared on transaction reuse. Normal transactions retain their existing proxy routing safeguards. - On the reviewed commit (`c891af160c`), a 17-table UPDATE failed with MySQL 20105 when a concurrent update held five overlapping metadata keys. The same SQL now commits both transactions and reads both updated values back. The minimum-budget DROP and cluster restore also pass with CDC cleanup enabled. - On the same reviewed commit, two fresh transactions each returned ErrTxnNeedRetry after an ordinary shared request followed by an exact request on the same remote row. The full SQL restore encountered an earlier multi-row proxy failure (20101). On the fix, with CN0 owning mo_account and the proxy enabled on CN1, RESTORE CLUSTER on CN1 restored the ACCOUNT ALL and named publications, with an active grant from each for the subscriber. - Wire tests cover Lock and ForwardLock with both lock modes and both exactness settings. Transaction tests exercise remote snapshots and reuse. The default threshold of 20,000 did not reproduce the original wait on the small test catalog. Large production catalogs and mixed-version clusters were not measured. Approved-by: XuPeng-SH <[email protected]> Approved-by: iamlinjunhong <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32900 (proven stale-grant path; deliberately not a closing reference).
What this PR does / why we need it:
Two different CNs can both report success for DROP ACCOUNT A and ALTER PUBLICATION ... ACCOUNT ADD B, yet leave a mo_subs row for A's deleted ID. ALTER computes its final account map before fanout. If DROP commits after that lookup, ALTER sees that the subscription no longer exists and its batch insert recreates it using the old account map. The same lookup-to-insert gap exists for CREATE PUBLICATION.
Validate the immutable IDs in the final grant set with one transaction-scoped shared locking read on mo_account, before source database validation and fanout. If any ID disappeared, roll back the statement with a retryable conflict instead of writing a partial grant or looking up the replacement by name. On this branch DROP takes the matching exclusive account lock before removing subscriptions; standalone publication CREATE/ALTER and account DROP use pessimistic RC background transactions. No schema migration, historical orphan sweep, SHOW change or change to ordinary queries. The lock set scales with the effective publication targets (including ACCOUNT ALL); a conflicting DROP/grant may wait or require a new statement.
Scope: The original QA rows were revoked (status=1) with their old subscription name and time. The reproduced stale insert is a normal grant (status=0, no subscription name/time). It proves a real violation of the same invariant, not the exact row history of either QA incident. Do not close #32900 or treat this as a repair of existing metadata.
Tested with
go test ./pkg/frontendvia the repository CGo test wrapper.pkg/frontendand the new cross-CN case also passed under-race.TestDropAccountConcurrentPublicationGrantandTestShowPublicationsMissingAccountsSQL, three repetitions via the CGo wrapper. Asserts the actual catalog rows, failed grant rollback, successful new statement, unaffected subscriber data, grant list and same-name recreation with a new ID.