Repository navigation
fix(frontend): prevent publication grants from recreating dropped subscriber IDs - #32936
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 ↓. |
|
Independent two-CN review of 07d9e10: the old-ID fix works (baseline retained one normal grant after DROP, PR retained zero, healthy subscriber still read value 7). Canceling a waiting publication released DROP and left no partial catalog rows. This is not proof of the revoked, named QA orphan in #32900; please keep that issue open. Merge decision needed: a one-target publication can block unrelated DROP ACCOUNT. With The planner compares the lock node’s estimated output, not the size of the resolved ID set. The PR acquires the lock before source DB validation and can hold it across that independent wait. Recommendation: retain same-ID exclusion; before merging, demonstrate that a one-ID grant under the low threshold lets an unrelated DROP finish while still blocking DROP of the target, or explicitly accept the broader DDL blocking as a trade-off. Do not disable escalation globally. The independent pre-existing missing-grant interleaving is tracked separately in #32941. |
|
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: 07d9e1073817b70848e6db52fd09c076d0d7e2c0
Assessment: request_changes
The shared account-ID lock prevents the reproduced stale grant. At a supported low lock threshold, the planner widens even a one-recipient grant to a table-wide lock, delaying DROP ACCOUNT for an unrelated tenant.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/frontend/publication_subscription.go:2946: CREATE PUBLICATION targets one account with max-row-lock-count=16 and waits for its source database lock while another CN drops a different account.
Impact: The unrelated DROP ACCOUNT waits behind the publication transaction because the shared lock covers all of mo_account. The low-threshold probe reproduced the wait. At the default threshold, the unrelated DROP completed while the publication still waited on its source database.
Evidence: The catalog scan estimates 1,000 rows for a single ID, so pkg/sql/plan/build_util.go:82 promotes the shared lock before source database validation. EXPLAIN VERBOSE and the two-CN wait observation are retained in lock-scope-verbose.jsonl with receipt 1795088648882406157-2.json. Use exact primary-key locks for bounded recipient sets and keep the post-lock existence check so DROP of a selected recipient still conflicts.
Validation:
-
The committed two-CN stale-grant regression passed normally and under -race. The focused race run also passed publication and restore tests. See attempt-1/embed-normal.jsonl and attempt-1/focused-race.jsonl with receipts 1795088528847747580-2.json and 1795088632596011998-2.json.
-
The corrected low-threshold probe confirmed the table lock and unrelated DROP wait. The default-threshold subtest passed its DROP control in attempt-1/lock-scope.jsonl. The initial low-threshold assertion used plain EXPLAIN, which omits lock granularity.
-
The frontend suite passed after excluding Test_openNewFile_nilCtx, which tried to write into the read-only checkout. See frontend-normal.jsonl in the model-switch directory and receipt 1795088672355114183-2.json.
Limitations:
|
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: 8660e4408463daaac20fd37c4cf978c43748e6a6
Assessment: request_changes
The exact account-ID locks prevent grants to deleted accounts and resolve the prior contention with unrelated account drops. The early existence check introduces a separate race in CREATE PUBLICATION IF NOT EXISTS.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/frontend/publication_subscription.go:397: Run CREATE PUBLICATION IF NOT EXISTS for an existing name, specifying a table that does not yet exist in a different source database. After the early name lookup, drop the old publication and commit, then create the requested table before CREATE validates it.
Impact: CREATE can return success while the publication is absent. The requested source was invalid while the old publication existed, and once the source became valid the statement needed to create the publication.
Evidence: Line 316 reads the publication without locking it. Source validation runs later and can see newer commits in the read-committed transaction. Line 397 returns success using the earlier result. The merge base checked the publisher's name after source validation. Recheck the name there before returning success. If the name disappeared and the recipient locks were skipped, return a retryable conflict so the next attempt can acquire those locks before validating the source.
Validation:
-
Verified the frozen checkout, patch, merge base and pinned policy. See attempt-1/verify-inputs.log and receipt 1795254528118679344-2.json.
-
The focused frontend package passed, and TestDropAccountConcurrentPublicationGrant reached PASS. The combined command later timed out during the lock-scope test. See attempt-1/focused.log and receipt 1795254364477402317-2.json.
-
TestCreatePublicationExplicitTargetLockScope passed in isolation. It covered the existing-publication no-op and verified that unrelated drops completed while target drops waited for both 1 and 17 recipients. See attempt-1/lock-scope.log and receipt 1795254612785171364-2.json.
Limitations:
-
The conditional CREATE finding is based on source analysis. Both supplemental SQL probe runs reached their check deadlines before producing a test result. See attempt-1/conditional-publication-probe.log and attempt-1/conditional-publication-retry.log with receipts 1795254831949951480-2.json and 1795255198449460425-2.json.
-
The cause of the historical revoked rows in #32900 remains unverified. The concurrent account-creation gap in #32941 remains outside this fix.
|
Addressed the P2 in review 6004515836 in 4e30a13de5. I reproduced the false success on The early lookup now only determines whether to acquire recipient locks. After source validation, CREATE rechecks the name in the publisher's account. If the publication disappeared after recipient locks were skipped, the transaction returns retry code Local race-enabled validation passed for the full frontend package, ten repetitions of the conditional-publication unit tests, all four two-CN lock-scope cases, and the separate concurrent account-drop/publication-grant regression. |
|
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: 4e30a13de5aed0ae1250cdd7f69f384ae0572b89
Assessment: request_changes
Reusing the account ID lock addresses the reproduced stale grant, and the conditional CREATE recheck closes the earlier false success. The new recipient lock path still rejects valid publication creation and snapshot replay when a shared range covers the named recipients.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/frontend/publication_account_lock.go:72: At max-row-lock-count=4, create a publication for two accounts covered by another transaction's shared mo_account range, or restore a snapshot whose ACCOUNT ALL publication takes a shared range before a named publication is replayed in the same transaction.
Impact: CREATE PUBLICATION and RESTORE CLUSTER both returned MySQL error 20707. The restore failed without concurrent SQL, so retrying the same replay order with the same lock settings hits the same guard.
Evidence: pkg/lockservice/lock_table_local.go:1117 rejects an exact row request when the caller already holds the covering range. A request can first join another transaction's shared range through the code at line 1120, then hit that guard on its second recipient. Snapshot replay shares one transaction across publications at pkg/frontend/snapshot.go:4420. Preserve the named account lock scope when another transaction owns a range, and recognize compatible coverage already held by the replay transaction. Keep the post-lock recipient existence check.
Validation:
-
120 selected frontend tests passed under the race detector. See frontend-publication-race.jsonl and receipt 1795283654042467758-2.json.
-
All four committed two-CN lock scope cases passed in the dedicated race run. The committed concurrent DROP and grant test also passed in the earlier combined run, which later timed out during setup of the lock scope test. See publication-lock-scope-race.jsonl and focused-race.jsonl with receipts 1795283961253721786-2.json and 1795283757889564645-2.json.
-
Both two-CN probes returned error 20707 on the PR head and passed when only publication_subscription.go was replaced with its merge base version. See publication-range-race.jsonl, publication-snapshot-race.jsonl, and publication-baseline-race.jsonl with receipts 1795283784694094202-2.json, 1795284024379650928-2.json, and 1795283971732753842-2.json. Logs and receipts are under attempt-2/retained-validation.
Limitations:
-
The shared range failures were reproduced with a lowered lock threshold. Their frequency at default settings was not measured.
-
The #32900 evidence covers the reproduced stale grant with status 0. The cause of the historical revoked QA rows and the separate account creation race in #32941 remain open.
|
Fixed in 93a36cc. I reproduced both failures under the race detector on 4e30a13 with two CNs and a row-lock threshold of 4. The named CREATE and the cluster restore each returned MySQL 20707. The lock owner now makes the distinction at acquisition. An exact point request waits for a foreign covering range to release. A named publication can also reuse compatible coverage already held by its own transaction. It still checks the physical recipient IDs after locking, and it cannot widen the request on capacity exhaustion. With the same SQL, the named CREATE waited for the foreign range to release, committed, and yielded exactly the two requested grants. After dropping both publications and restoring the cluster, I read back five active grants for ACCOUNT ALL and the two expected active grants for the named publication. A separate lock-service test verifies that a writer can take the gap between the named IDs while a writer on a named ID conflicts until unlock. The 1- and 17-target CREATE lock-scope cases and the concurrent account DROP/publication grant regression passed. The scope test now checks that the unrelated DROP commits and that the account is absent while the publisher is still gated, so an unrelated CN-wide wait sample cannot fail it. The full lockservice, lock operator, and frontend packages passed with -race. Incremental vet and golangci-lint also passed. |
|
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: 93a36cc7c227604cf4a2731cebad8072bc6462f9
Assessment: approve
Publication writes now lock and revalidate recipient IDs using the same account keys as DROP ACCOUNT. The prior findings are resolved. Named grants retain exact lock scope, conditional CREATE rechecks publication existence before writing, and restore can reuse a covering lock it already owns.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
Validation:
-
Verified the frozen checkout, patch, and target merge. The generated LockOptions descriptor adds only optional bool field 16. See scope.log, target-merge-verification.log, and lock-descriptor.log.
-
The lock-service and SQL lock-operator suites passed under the race detector. Four focused exact-row tests also passed 100 repetitions each. See lock-race.jsonl and the four Test*-race.jsonl logs with their checks/ receipts.
-
The focused frontend race run passed 179 top-level tests. See frontend-race.jsonl and checks/1795319022192507323-2.json.
-
Three embedded two-CN race tests passed, covering concurrent DROP and ALTER, conditional CREATE and exact recipient scope, foreign covering-range waits, and restore with an owned covering range. See embed-race.jsonl and checks/1795319196684675217-2.json.
Limitations:
-
The full frontend race run failed in the unchanged Test_openNewFile_nilCtx fixture because it writes inside the read-only checkout. See frontend-package-race.jsonl and checks/1795319244814135458-2.json.
-
The fix covers the reproduced stale grant. The revoked-orphan QA cases in #32900 and the concurrent account-creation case in #32941 remain outside this review's scope.
🚫 Left the queue · pull request dequeued1 h 50 min in the queue, with no time running CI. So far
Reason Pull request #32936 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.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
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.
Before source database validation and fanout, protect the sorted physical mo_account primary keys of explicitly named recipients in the publication transaction, then verify that all selected IDs still exist. Named requests wait for foreign covering ranges to clear and acquire points. A compatible covering lock already held by the publication transaction satisfies the read without widening its scope. A missing ID or lock error aborts the statement. For ACCOUNT ALL, keep the existing shared locking read over its resolved IDs; this PR does not address concurrent account creation (#32941). 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. DROP already locks the immutable account ID exclusively before inspecting subscriptions; reuse that lock. 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 (original fix before lock-scope review)
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.Lock-scope review follow-up (
51fd169490)-race: with max-row-lock-count=16, tested both 1 and 17 explicit recipients. An unrelated DROP committed while publication still waited for its source DB (including a non-target inside the 17-ID span). A target DROP waited for publication; afterwards zero grants referenced its old ID. The original concurrent DROP/ALTER ADD regression also passed.-race. A separate full frontend-racerun on macOS hit the previously reportedtime.Localtest race ([Bug]: TestConvertRowsIntoBatchTemporalText races with Go timers when writing time.Local #32893); it was not a green full-suite race run.Shared covering range follow-up