Repository navigation
fix: validate database clone existence - #27058
Conversation
|
The Launch + Pessimistic BVT job did not build or execute MatrixOne: its Java |
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? |
32216f2 to
dafcd6d
Compare
|
@iamlinjunhong Addressed all three findings in 60ec4a0.
Focused/frontend race tests, parser/tree tests, the distributed BVT, |
|
@XuPeng-SH @aptend Both requested-change reviews are valid for the reviewed
The BVT now covers cross-tenant source/target name collisions and the foreign |
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed current head 19c5a41317c716acd356bb9fbc70272f2c7ca9db against merge-base bdbd613fdece966769eb68481a3e58bfbc36b30c and current origin/main.
The three P1 findings from my previous review are resolved in the current code: existence reads are account-scoped, cross-account authorization precedes the IF NOT EXISTS no-op, and implicit clones use the same encoded mo_database key in the owning pessimistic-RC background transaction with retry/recheck. I found no remaining P0/P1 blocker.
One P2 test gap remains. The production locking code appears consistent with lockMoDatabase, but the committed concurrency test replaces the exact lock boundary with a stub and therefore cannot prevent this race from regressing. The author's conversation reply and local two-client smoke result are noted, but neither is an automated regression. Details are on the inline comment.
gouhongshen
left a comment
There was a problem hiding this comment.
Addressed the inline concurrency-regression request in b061811; the automated embedded-cluster test now exercises the production lock path with two real sessions.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed current head 01138a2eefe29bd33b65d0e680005b01d3ff0572 against merge-base bdbd613fdece966769eb68481a3e58bfbc36b30c after syncing current origin/main at a5288a6b0ad5cddff150f519680d1e24a91eb8dd.
Findings: none (P0/P1/P2/P3: 0).
The prior P2 at pkg/frontend/clone_test.go:631 is resolved. The author explicitly replied in the review thread, and b06181148a6acc3451976607c174c48dce8cb918 adds the requested embedded-cluster regression with two real SQL sessions and the production lock service; 01138a2eefe29bd33b65d0e680005b01d3ff0572 makes the waiter observation robust when the catalog lock table is bound to another CN. The test holds the first transaction through CREATE/commit, observes the second waiter, and verifies the second succeeds with exactly one target and the cloned payload.
I also rechecked the full 17-file diff and relevant call chain: account-scoped source/target existence reads, authorization before the target no-op, exact mo_database key compatibility with lockMoDatabase, owning-transaction lock lifetime, RC retry rollback/begin/relock/recheck, and error cleanup. I found no remaining correctness, concurrency/lifecycle, compatibility, performance, or regression-test issue. All 25 current checks are terminal with no failed conclusion.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 01138a2eefe29bd33b65d0e680005b01d3ff0572: no blocking findings. The prior account-scope, authorization-order, and check/create atomicity issues are closed. I verified exact-key compatibility with lockMoDatabase, owning-transaction lock lifetime, RC retry/relock/recheck, snapshot/subscription and cleanup paths, and the production two-session lock-service regression. Local frontend full/focused race, parser, vet/list, and TestIssue27040ConcurrentIfNotExistsDatabaseClone all pass.
|
@Mergifyio refresh |
✅ Pull request refreshed |
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27040
Fixes #27041
What this PR does / why we need it:
CREATE DATABASE ... CLONEwas losingIF NOT EXISTSwhile parsing, so anexisting target eventually reached an unconditional
CREATE DATABASEandreturned 1007. It also accepted a nonexistent source whenever the source
metadata query produced no table rows, creating an empty destination.
This PR preserves the clause in the clone AST and formatter; verifies source
database existence at the requested snapshot; and makes an existing target a
true no-op.
The follow-up review found three correctness holes in the original target
precheck. This revision addresses them as part of the same clone-existence
contract:
snapshot tenant. A same-name database in another tenant can neither suppress
a target clone nor prove a source exists.
before an
IF NOT EXISTSno-op is possible. Non-sys callers cannot use anexisting foreign target as an account/database-name oracle.
IF NOT EXISTSdatabase clone uses an owning pessimistic RCbackground transaction to exclusively lock the exact
(account_id, database_name)catalog key. The lock is held through thedestination CREATE and released by the existing commit/rollback path. After
a lock-wait retry, the transaction restarts and rechecks the target, so a
concurrent winner makes the later statement a no-op rather than a duplicate
database error.
new account-scoped source-existence query. A non-sys caller therefore keeps
the established authorization error instead of incorrectly seeing
Unknown databaseformo_catalog,system, or another system database.The target-lock helper reuses the existing catalog lock-key encoding and lock
context mechanism; data-branch source locking is refactored only to share those
primitives. There are no new fallback paths or protocol/catalog-format
changes.
Regression proof:
IF NOT EXISTS; the distributedcase proves an existing target is unchanged and successful with the clause,
still returns 1007 without it, and clones schema and rows for an absent
target. It also proves that a tenant-only same-name target does not suppress
the sys target clone.
catalog residue (with and without
IF NOT EXISTS), real empty sourcessucceed, snapshot-only sources succeed, and missing-table cloning leaves no
table residue. A tenant-only source is explicitly rejected to sys without an
empty destination.
distributed case: a non-sys tenant cannot clone to an existing foreign target
even with
IF NOT EXISTSand a valid snapshot.derived from every
catalog.SystemDatabasesentry (including case-folding);the existing distributed
clone_privilegeandclone_sys_db_table_to_new_db_tablecases exercise the exact database-clonestatements that exposed the regression.
retry/recheck state machine; the target lock-process test proves it uses the
owning background transaction. An embedded-cluster two-client integration
test exercises the production lock boundary: the first real frontend
transaction holds the target through commit, the second clone is observed in
the real
mo_databaselock wait queue (across every CN, because the catalogtable binding can be remote), and after commit it refreshes, succeeds as a
no-op, and leaves exactly one target with one payload row.
retryable errors without an owning background transaction are returned
without an existence lookup, and the real lock entry point rejects a
non-background executor before allocating or locking catalog state.
Tests run:
./run.sh -p <this-worktree>/test/distributed/cases/ -m genrs -i clone_database_existencefollowed by
./run.sh -p <this-worktree>/test/distributed/cases/ -i clone_database_existence— passed; generated result was inspected: tenant collision clones sys data,
tenant-only source leaves count 0, and unauthorized cross-account no-op is
rejected while the sentinel remains 8.
CREATE DATABASE IF NOT EXISTS ... CLONE ...smoke test — both statements succeeded and each observed exactly one cloned
payload row.
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout 120s -run '^(TestCheckDatabaseExistsAtSnapshot|TestCheckDatabaseExistsAtSnapshotPropagatesErrors|TestCheckDatabaseExistsAtSnapshotRequiresAccountContext|TestHandleCloneDatabaseWithSourceIfNotExistsSkipsExistingTarget|TestHandleCloneDatabaseWithSourceIfNotExistsPropagatesLookupErrors|TestHandleCloneDatabaseWithSourceAuthorizesTargetBeforeIfNotExistsCheck|TestCheckCloneDatabaseTargetSerializesConcurrentIfNotExistsDecisions|TestIsCloneDatabaseTargetLockRetry|TestValidateCloneDatabaseAccounts|TestCloneCatalogLockBatch|TestWithCloneLockContext|TestCloneDatabaseTargetLockProcessUsesOwningBackgroundTxn)$' ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout 180s -run '^(TestValidateCloneDatabaseSourceAccess|TestValidateCloneDatabaseAccounts|TestHandleCloneDatabaseWithSourceIfNotExistsSkipsExistingTarget|TestHandleCloneDatabaseWithSourceAuthorizesTargetBeforeIfNotExistsCheck|TestCheckCloneDatabaseTargetSerializesConcurrentIfNotExistsDecisions|TestCheckCloneDatabaseTargetReturnsLockErrors|TestNewCloneDatabaseTargetLockProcessRequiresBackgroundExecutor|TestLockCloneDatabaseTargetRequiresBackgroundExecutor|TestCheckDatabaseExistsAtSnapshot)$' ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -race -json -count=1 -timeout 120s -run '^TestCheckCloneDatabaseTargetSerializesConcurrentIfNotExistsDecisions$' ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout 120s -run '^TestCheckCloneDatabaseTargetSerializesConcurrentIfNotExistsDecisions$' ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout 20m ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -json -count=1 -timeout=180s -run '^TestIssue27040ConcurrentIfNotExistsDatabaseClone$' ./pkg/tests/issues— passed (11.71s test, 13.03s package).
.agents/skills/mo-dev/scripts/mo-cgo-test -json -race -count=2 -timeout=240s -run '^TestIssue27040ConcurrentIfNotExistsDatabaseClone$' ./pkg/tests/issues— passed both iterations (30.30s and 1.65s).
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout 120s ./pkg/sql/parsers/dialect/mysql ./pkg/sql/parsers/treeGOWORK=off CGO_CFLAGS=... go build -mod=readonly ./pkg/frontendGOWORK=off CGO_CFLAGS=... go vet -mod=readonly ./pkg/frontendgolangci-lint run -c .golangci.yml ./pkg/frontendmake buildResidual risk: the additional exact-key lock deliberately serializes only
concurrent implicit
IF NOT EXISTSdatabase clones for the same account andname; waiting follows the existing session lock timeout. Explicit user
transactions retain their existing shared-transaction semantics.