Skip to content

[Bug]: Slow DROP DATABASE blocks unrelated database DDL on the global SNAPSHOT lifecycle gate #29400

Closed

Description

@XuPeng-SH

Current delivery scope (2026-09-28)

The present production deployment and active PR BVT paths use pessimistic RC by default. The required fix and performance acceptance for this issue are the demonstrated RC convoy: a slow DROP in one database must not hold unrelated database DDL behind the global SNAPSHOT gate, while preserving snapshot/PITR, branch-lineage and rollback correctness. Measure the disjoint-database progress and same-object exclusion under pessimistic RC.

This issue does not require newly supporting DROP DATABASE inside an existing pessimistic SI transaction. That rejection is the current documented lifecycle contract; see #29417, closed as a non-regression. Optimistic transaction mode is retired and is outside this issue's support and acceptance scope; the confirmed test-only optimistic RC counterexample was documented in #29401 and closed as not planned because optimistic mode is retired. Existing pessimistic SI behavior and mixed-version compatibility remain design considerations if a proposal changes shared paths or protocol. RC acceptance must not be presented as SI correctness or performance coverage. A future decision to support fixed-snapshot SI lifecycle DDL needs its own contract, conflict proof and tests.


Relationship and scope

This is a reproducible, narrower subproblem of #27575, and a merge dependency for #29393. That PR improves per-table cleanup but leaves this cross-database DDL convoy unresolved. The original #27575 report involved a high-churn database, a two-hour DROP, and a lost connection; this issue does not claim that the convoy alone caused that historical disconnection.

Related but different: #28319 covers concurrent COPY ALTER queueing on the SNAPSHOT gate; #28317 and #29335 cover internal lock-order deadlocks. This report has a single target table, a deliberately slow but successful DROP, and an unrelated DDL statement waiting on the same gate. No deadlock or data loss is required to reproduce it.

Environment and revisions

  • Independent disposable local MatrixOne service, one CN/TN/LogService, fresh data directory, ordinary persistent tables in two different databases.
  • Pre-PR main ancestor: 9c79a6edfcad5ce9635d91b0f1646d0bde375cc3.
  • Exact PR head independently retested: fdcd553b0cfe356679f43d798d645599d9ba375e (see commit-bound QA review).
  • These are local standalone reproductions. They do not establish the affected production-version range or reproduce the original deployment topology.

Actual behavior

On the pre-PR main ancestor, connection A held a transaction lock on the only table in the target database for 12 seconds. Connection B ran DROP DATABASE and waited for that table. Connection C then issued DROP TABLE against a different database, followed by a CREATE TABLE there. The DROP took 11.052 s; C took 10.036 s. Both ultimately succeeded. The DROP connection ID remained unchanged and a subsequent SELECT 1 succeeded.

During the wait, mo_catalog.mo_locks showed the target-table waiter and a separate waiter on mo_catalog.mo_feature_registry's SNAPSHOT row (table_id=272476, lock_content=4601534e415053484f5400 in that fresh service). The numeric table ID is instance-specific; the SNAPSHOT key and wait relationship are the relevant evidence.

The same class of failure remains on the exact #29393 head. In a separate QA scenario, DROP had already processed its first table and was waiting on a locked later table; an unrelated database's DROP TABLE waited on mo_feature_registry. It remained incomplete through a measured 2-second hold after the wait was observed. After KILL QUERY cancelled DROP, the unrelated DDL completed (total 2.043 s). The cancelled DROP's outer transaction then committed after statement rollback; both physical tables and their catalog identities survived, and the first table's allocator and merge-settings metadata remained valid. This cancellation scenario proves the current-head convoy and checks its immediate rollback behavior; it does not prove later background merge behavior.

Minimal reproduction

Use test-only database names on a disposable service. Prepare one row in the target table and a separate guard database:

CREATE DATABASE slow_target;
CREATE TABLE slow_target.t (id INT PRIMARY KEY, v INT);
INSERT INTO slow_target.t VALUES (1, 1);
CREATE DATABASE slow_guard;
CREATE TABLE slow_guard.g (id INT);

Run these on separate connections, in order:

  1. A: BEGIN; UPDATE slow_target.t SET v=2 WHERE id=1; Keep the transaction open for about 12 seconds, then ROLLBACK.
  2. While A is open, B: DROP DATABASE slow_target;. Observe B waiting for the target table lock in mo_catalog.mo_locks.
  3. While B is blocked, C: DROP TABLE slow_guard.g; CREATE TABLE slow_guard.g (id INT);. Observe C waiting on the SNAPSHOT feature-registry row. Keep A open to show C cannot complete during the hold.
  4. End A's transaction. B and C complete. Confirm the target database is gone and the guard table exists. Retain same-connection IDs and error results.

The measured baseline used SELECT SLEEP(12) inside A's open transaction and one-second offsets to stage the connections; the lock view, rather than the offsets alone, established the blocked states. An automated regression should synchronize on bounded, observed lock states rather than rely only on sleeps.

Cause indicated by code and lock evidence

DropDatabase at the PR head acquires lockDataBranchLineageOwnerLifecycle() before catalog lookup and target-table work. The helper updates the global SNAPSHOT lifecycle row in the DROP transaction. A slow table wait therefore lengthens the time that unrelated DDL is unable to acquire that row. The observed locks and the two-revision reproduction support this mechanism; they do not establish that deleting the gate would be safe. Snapshot/PITR and branch-lineage publication still require a correct coordination protocol.

Expected behavior / resolution criteria

  • A DROP DATABASE delayed by one table should not hold unrelated-database DDL behind that table's remaining wait solely through the global SNAPSHOT lifecycle gate. Check this with one table as well as a multi-table case; counting fewer nested SQL calls does not address this queue.
  • Preserve snapshot/PITR and branch-lineage correctness, consistent catalog/DDL lock order, foreign-key checks, and the existing DDL INFO log contract. A fix should explain the narrower or shorter safe critical section before changing lock scope.
  • Cover cancellation, statement rollback followed by outer COMMIT, and a real retry while a target table is blocked. Verify catalog identities, allocators, merge settings, and successful eventual DROP cleanup. Check that no waiter remains after cancellation. Keep the regression focused and deterministic.
  • Compare the blocked unrelated DDL against an unblocked control under the same test setup and capture lock evidence. A timeout increase or serialized test scheduling is not a product fix.

No corruption, deadlock, TN late-commit failure, or original two-hour connection-loss cause is asserted by this report.

Systemic analysis and optimization proposal (2026-09-27)

Scope of source inspection: PR head fdcd553b0cfe356679f43d798d645599d9ba375e, base 9c6fcb5b501d040ab1bcb5ada139939770468638. The analysis below extends the impact map; only the DROP DATABASE timing results above were independently reproduced in this task. Linked issues contain their own evidence at their stated revisions. This is a design proposal, not an implemented or approved fix.

Underlying contract and why the blast radius is large

The gate is a pessimistic transaction-duration exclusion mechanism; it also served as an MVCC write-conflict barrier in the now-retired optimistic mode. This historical role is useful when reading the old code, but supporting optimistic transactions is no longer a requirement for this issue. It protects a negative decision (no historical owner exists / a lineage edge can be reclaimed) against a concurrent Snapshot/PITR/branch owner publication. It also participates in restore ordering and quota admission. The row exists before any owner exists, so testing an empty owner catalog and then skipping synchronization is unsafe.

The problematic scope is the combination of a single sys-tenant row and a long owning transaction. A slow downstream table lock, catalog operation, synchronous cleanup, or client-held transaction extends the global exclusion interval. Removing repeated calls to an already-held gate does not shorten its ownership. The gate is released by transaction completion, not by return from the internal UPDATE.

unrelated DDL -> global SNAPSHOT gate -> DROP transaction -> one busy target table
                                     -> View revalidation / lineage cleanup

Consequently, one table suffices; increasing table count is not a prerequisite. The measured baseline carried approximately ten seconds of the target's remaining wait into unrelated DDL. Cross-account interference is source-reachable because the helpers explicitly resolve the same row as the system tenant; a separate cross-account runtime reproduction is still required. Ordinary DML that never enters these lifecycle paths is not claimed to acquire the gate, although it can be the blocker of an admitted DDL.

Same-pattern entry points and hidden serialization

Entry / shared resource Source-confirmed mechanism at the inspected head Evidence / boundary
DROP DATABASE, persistent DROP TABLE Lifecycle admission precedes target catalog/table locking and cleanup. This issue reproduces DROP DATABASE; DDL entry, table entry. Temporary-table retirement has a different path; do not generalize this to all temporary DDL.
COPY ALTER and persistent TRUNCATE Early pessimistic SNAPSHOT lock, followed by table locks, snapshot advancement, and the lifecycle write barrier. ALTER, TRUNCATE. #28319 reports COPY ALTER queueing/timeouts. Unconditional DELETE can reach TRUNCATE in the applicable optimized path; #29335 covers a related lock-order failure.
Snapshot/PITR publication/deletion, autocommit branch mutation, clone, DROP ACCOUNT, restore Shared lifecycle admission surrounds owner publication/mutation. A broad restore also coordinates catalog identity replacement. owner executor, snapshot admission, DROP ACCOUNT. #29208 reports high-concurrency DATA BRANCH failures. Explicit DATA BRANCH already has a distinct terminal-validation path; it is not accurate to say every branch statement holds the gate throughout the client transaction.
View metadata revalidation, including the currently disabled lifecycle layer viewMetadataRefreshAvailable() still calls transactional revalidation when disabled. That takes SNAPSHOT, then the global View catalog gate, then writes the shared revalidation marker. DROP DATABASE reaches this before its table loop; ordinary CREATE/other DDL reach it through view refresh hooks. disabled path, gate + marker SQL. Removing only the early SNAPSHOT call can merely move contention to these later operations.
CREATE ACCOUNT View-state inheritance Inherits revalidation state while taking the same global lifecycle gates. inheritance. #28079 reports View-gate account-operation queueing/timeouts at its tested revisions; this inspection establishes the current call path, not a fresh reproduction of that incident.
Participating branch-table reclaim / foreground lineage compaction A participation probe avoids the scan for ordinary non-branch tables. Once it hits, reclaim performs an unfiltered sys mo_branch_metadata SELECT ... FOR UPDATE; foreground compaction separately loads the whole DAG with locking. reclaim, whole-DAG loader, foreground compaction. This is a source-confirmed broad locking/scanning path, not a newly measured independent failure rate. Narrowing only the SNAPSHOT gate leaves this bottleneck for unrelated branch components.

The deadlock reports #28317/#29335 are related coordination defects, but are not equivalent to queueing. Establishing one consistent global lock order can remove a cycle while leaving global serialization intact.

Recommended direction: coordination by the actual conflict domain

Keep a single ownership model in the transaction layer and reuse the existing lock/transaction infrastructure. Ordinary DDL on disjoint objects should be compatible; historical-owner publication, restore, quota changes, and lineage mutation must conflict only where their effects overlap. Do not add a DROP DATABASE-specific worker pool, a second cleanup state machine, or an in-memory CN-local lock/cache.

The first version should use database-sized lifecycle domains, rather than add a new table/component lock framework immediately:

Operation Proposed logical guards
Single-database DDL, table/database Snapshot or PITR cluster shared → account shared → database exclusive
Cross-database/account branch, clone or lineage mutation shared parent scopes → all affected database scopes exclusively, in a fixed order
Account Snapshot/PITR, account restore/drop cluster shared → account exclusive
Cluster Snapshot/PITR, cluster restore or global owner-catalog replacement cluster exclusive

This deliberately permits serialization within one database initially. It addresses the demonstrated unrelated-database case with fewer moving parts. The scope set must include related databases, not just the named target. The table is a logical protocol whose implementation still requires a conflict proof for supported modes.

  1. Define the conflict matrix first. Use cluster/account/database/table identity and the actual lineage/dependency closure. A database drop excludes work on that database; unrelated databases should proceed. Account/cluster Snapshot/PITR or restore can legitimately need a broader fence. Cross-database branches, FK edits and View dependencies must include all affected scopes, not merely the SQL session's current database. Account quota admission must remain atomic with owner publication on its quota key. In particular, SNAPSHOT currently relies on global serialization; the finite BRANCH quota has a dedicated locking path, which must not be assumed to cover SNAPSHOT too.
  2. For pessimistic execution, evaluate shared ancestor guards and exclusive affected-object guards. Ordinary operations share the broad coordination scope and exclusively protect their actual mutation scope; a truly broad mutation takes the matching exclusive ancestor. Reuse existing catalog/name/identity locks where they meet the contract. Declare the whole required scope set before locking it in a canonical order; if discovery expands it or the object generation changes, restart admission rather than upgrade out of order. Account/database-wide cases may remain coarse initially; table-level refinements require measured value.
  3. Preserve supported-mode conflict safety. An UPDATE-to-shared-lock conversion needs a proof that a historical-owner absence check cannot race a new Snapshot/PITR or branch owner publication under pessimistic RC. If the shared path changes, preserve the existing pessimistic SI behavior or retain a safe fallback; this issue does not add new SI lifecycle operations. Continuing to write the single global row in every narrow operation would retain global contention. RC snapshot advancement must not erase the version against which a decision was made. Correct owner admission remains an implementation-blocking design obligation. Retired optimistic mode has no new support obligation here; see [Bug]: Optimistic RC concurrent UPDATE exposes duplicate primary-key rows (test-only mode) #29401 (closed as not planned).
  4. Remove the hidden broad work in the same closure. View invalidation should publish a transactional marker scoped to the affected dependency domain; activation/revalidation/restore must consume it with a proved fence. A shared global marker update would recreate the hotspot even if explicit gates changed. Branch reclaim should lock and revalidate the affected connected component using the existing table/parent indexes, including ancestor/sibling reachability and concurrent edge insertion. Keep synchronous semantic deletion atomic; unrelated expired lineage can use the existing bounded GC path where delayed reclamation is safe. Do not replace a whole-DAG lock with an unsafe current-table-only predicate.
  5. Keep transaction ownership through terminal cleanup. Statement cancellation/rollback must preserve prior successful statements and surviving catalog/allocator state; later COMMIT cannot apply retired intents from the failed statement. Restore must still fence replacement of the gate's catalog identity. Background work must validate physical generation before affecting a recreated object. Existing DDL INFO logs remain; report gate wait versus target wait so the next bottleneck is observable.

This direction reduces false conflict scope. It does not promise that a slow table's own DROP becomes fast, or that a truly cluster-wide restore will never delay DDL. A queued broad exclusive operation can itself affect reader admission/fairness, so that behavior also needs an explicit bounded policy and test.

Alternatives and why they do not close the issue alone

  • Parallel per-table DROP / batching: can reduce some independent work, but cannot let an unrelated DDL acquire a transaction-held global gate; it also complicates workspace ownership, rollback and callbacks.
  • Move the existing global gate to COMMIT: explicit DATA BRANCH and bounded lineage GC provide useful local precedents for short validation. The GC proof explicitly pins SI; it is not a proof for arbitrary RC DDL. Wholesale reuse is unsafe without proving stale-owner detection, RC/SI behavior and every commit owner. A single global write version can replace lock waiting with unrelated transaction aborts/retry amplification. Fast-fail is useful for bounded GC/control work, not a throughput proof for foreground DDL.
  • Wait for a target before acquiring the current gate / use FastFail: without a complete scope protocol it can invert the current lock order or retry substantial prior work, and later catalog/lineage waits still occur under the gate. Treat as a narrowly measured mitigation only.
  • Per-account gate only: bounds cross-tenant impact but does not fix the two-database same-account reproduction.
  • Feature-disabled/no-owner fast path: the current disabled View layer still needs its durable revalidation contract; an unlocked empty-owner probe races new owner publication. Neither condition permits simply deleting synchronization.

Orthogonal validation and approval gates

Use one small reusable concurrency fixture with bounded phase barriers and independent SQL/catalog oracles:

  • Progress: hold one target table; unrelated same-account database DDL and different-account DDL complete before release. Retain a same-object control that must wait. Repeat for DROP DATABASE, DROP TABLE, COPY ALTER and TRUNCATE as distinct entry paths, not a large Cartesian stress suite.
  • No shifted bottleneck: View lifecycle disabled and enabled/activation transition; two unrelated branch components; one target branch component while unrelated DAG size grows. Capture SNAPSHOT/View/DAG wait sites as well as wall time.
  • Safety: snapshot/PITR publication before/after the history probe; sibling branch delete versus edge creation/GC; cross-database dependencies; quota at its limit. Check public historical reads/DIFF/MERGE and metadata identities, not only successful SQL.
  • Unhappy paths: cancel before/after partial cleanup, statement rollback then COMMIT, real transaction retry, peer disconnect, late old-generation callback and restore replacement. Assert no leaked waiter, duplicated effect, lost allocator or invalid historical reference. TN merge events require a targeted runtime challenge before any claim about them.
  • Modes/delivery: pessimistic RC is mandatory; check existing pessimistic SI behavior only if shared paths change. Also cover multi-CN delayed visibility and mixed-version compatibility when protocol changes. Old CNs still acquire broad gates. New scoped participants cannot bypass old participants without a proven common fence and capability/epoch activation; do not assume a SQL helper change is a safe rolling upgrade.
  • Cost: vary blocker duration H, target count N and unrelated DAG size G independently. Unrelated-DDL latency should not track H for disjoint scopes; relevant cleanup should not repeatedly lock/scan all G rows per participating target. Track committed throughput, tail latency, abort/retry rate, lock count and retained memory; no claimed speedup before these measurements.

Before implementation approval, close supported-mode conflict safety, stable identity and missing-row admission, cross-scope dependency discovery, View activation/marker migration, and mixed-version fencing for any protocol change. Record these in a versioned design with an independent design review. The current analysis recommends the conflict-scope direction but does not mark those proof obligations as solved.

Independent design challenge: a separate GPT-6 Astra xhigh review of the earlier source revision agreed with the database-domain direction and identified optimistic admission, SNAPSHOT quota, View markers, whole-DAG locking, and mixed-version fencing as closure points. The optimistic-admission item is superseded by the retired-mode scope above. No implementation approval or new runtime test pass is claimed.

Activity

  1. added
    kind/bug
    on Sep 27, 2026
  2. self-assigned this
    on Sep 27, 2026
  3. XuPeng-SH commented on Sep 28, 2026

    @XuPeng-SH
    ContributorAuthor

    Scope update: optimistic transaction mode has been retired, so #29401 is deferred and optimistic interoperability is no longer a blocker for this issue. Acceptance still requires the pessimistic RC concurrency and failure-path guarantees described above. If implementation changes shared paths, preserve existing pessimistic SI behavior; if it changes a shared protocol, validate mixed-version safety. This does not expand the existing pessimistic SI DROP DATABASE transaction contract.

  4. XuPeng-SH commented on Sep 28, 2026

    @XuPeng-SH
    ContributorAuthor

    Related-issue status update: #29401 is now closed as not planned because its reproduction is confined to the retired optimistic test mode. It is not a deferred production fix or a blocker for this issue. The required acceptance scope here remains pessimistic RC, with existing pessimistic SI and mixed-version checks conditional on shared-path or protocol changes as described above.

  5. XuPeng-SH commented on Sep 28, 2026

    @XuPeng-SH
    ContributorAuthor

    Implementation status: draft PR #29457 contains the pessimistic-RC fix, rebased onto #29393 head 4233217baff; Mergify then merged current main into that draft branch. The issue commits are 0fd6044ffd4..3983ea44ad1, with current PR head 6b2818d5e69.

    The component-scoped protocol and its partitioned-delete and low-lock-budget corrections passed full affected Go packages, seven selected real two-CN issue tests, and focused live-service cancellation, explicit-transaction, cross-account, and same/unrelated-component challenges. Independent Astra xhigh commit review found no remaining confirmed blocker for the approved pessimistic-RC scope after the two corrections. Both author reviews are bound to exact commits on #29457; no new review threads were present at this check. CI is still running.

    #29393 must include this fix before it merges; the dependency is recorded on that PR. Its separate 1,000/2,000-table ≥25% performance gate remains open. First protocol activation requires the approved full maintenance cutover; this implementation does not claim rolling mixed-version safety. #29457 remains draft pending CI and the parent acceptance.

  6. Ariznawlll commented on Oct 3, 2026

    @Ariznawlll
    Collaborator

    补充修复后的复测证据:无关数据库的 DROP TABLE 已能独立推进,但公开 TRUNCATE 仍会因全局 SNAPSHOT 锁返回 20706。本次针对 issue 正文“Progress”中列出的 TRUNCATE 入口;没有把下面的结果推广为原 DROP→DROP 修复失效。

    测试版本

    • 官方 main:529ee099e32ed8c38d2806043bf1516ab0345e45,测试前后核对 main 均为此提交。
    • 日期:2026-10-03。
    • 从干净源码重新构建,独立临时数据目录,本地 1 CN + 1 TN + 1 LogService,默认 pessimistic RC,磁盘文件服务;通过 git_version() 核对运行提交。
    • 使用 PyMySQL 直连公共 SQL 接口,无 MOTR runner、无故障注入;普通主键表,没有配置业务 snapshot/PITR/branch/FK/index 依赖。
    • fix(sql): reuse ordered cleanup for DROP DATABASE #29393 的合并提交 b631e1d1a57d70f7b3252590471aa3ba243492c1 已包含在本次版本及 CI 版本中。

    原问题验证

    对照原 issue 的三个连接,使用不同数据库。初始化:

    CREATE DATABASE slow_gate_source;
    CREATE TABLE slow_gate_source.t (id INT PRIMARY KEY, v INT);
    INSERT INTO slow_gate_source.t VALUES (1,10),(2,20);
    CREATE DATABASE slow_gate_guard;
    CREATE TABLE slow_gate_guard.t (id INT PRIMARY KEY, v INT);
    INSERT INTO slow_gate_guard.t VALUES (1,10),(2,20);
    CREATE TABLE slow_gate_guard.spare (id INT);
    1. 连接 A:BEGIN; UPDATE slow_gate_source.t SET v=11 WHERE id=1;,暂不结束事务。
    2. 连接 B:执行 DROP DATABASE slow_gate_source,等待目标表锁。
    3. 观察连接查询 mo_catalog.mo_locks,确认 SNAPSHOT 行的持锁事务就是目标表锁的等待事务,再执行下面的 C;使用锁状态同步,不依赖固定 sleep。
    4. 连接 C:TRUNCATE TABLE slow_gate_guard.t,连续执行三次;均立即返回 ERROR 20706: lock options conflict, wait policy is fast fail。
    5. 仍不释放 A,C 执行 DROP TABLE slow_gate_guard.spare:成功,B 仍在等待。
    6. A 执行 ROLLBACK,B 的 DROP 成功结束;C 再执行 TRUNCATE 成功,目标表变空。

    以上 10/10 轮重复一致。无关 DROP 在释放 A 之前完成,耗时 8.189–13.997 ms;释放后 TRUNCATE 成功,耗时 9.538–13.697 ms。

    一次实测锁链(table_id 为当前实例 ID):

    SNAPSHOT holder:
    txn_id=b2831613ac2cf7e218dadce19e7397d8
    table_id=272477
    lock_content=4601534e415053484f5400
    lock_mode=Shared, lock_status=acquired
    
    target catalog/table lock:
    holder=b2831613ac2cf7e218dadce19e7397d4
    table_id=2
    waiter=b2831613ac2cf7e218dadce19e7397d8
    

    因此本地持锁者已确认是等待目标表的 DROP 事务。TRUNCATE 在目标表无业务冲突时,仍在系统 SNAPSHOT 行上申请全局独占锁而失败。

    对照验证

    1. 同样四个独立数据库,顺序执行 TRUNCATE/重新插入:每组 100/100 成功,3 组共 300/300。
    2. A 只保留普通 UPDATE 事务,B 对不同库 TRUNCATE:30/30 成功。
    3. A 保留 DROP TABLE 的生命周期共享锁,B 对无关库 DROP TABLE:30/30 成功。
    4. A 提交或回滚后,B 的 TRUNCATE:30/30 成功;上面的慢 DROP 三连接场景额外 10/10 恢复成功。

    并发复现与数据检查

    1. A 执行 BEGIN; DROP TABLE gate_probe_a.t; 后保持事务,B 对 gate_probe_b.t TRUNCATE。3 组,每组 10 轮,每轮 3 次尝试:90/90 返回 20706。mo_locks 确认 A 持有 SNAPSHOT 共享锁。
    2. 三连接慢 DROP 场景:30/30 次 TRUNCATE 返回 20706。
    3. 自然并发对照:4 个连接分别只操作各自数据库,每轮以客户端 barrier 同时开始 TRUNCATE,随后检查完整行数据并在成功时重新插入。每组 25 轮、100 次 TRUNCATE,3 组各 75 次 20706 / 25 次成功,共 225/300 次冲突。没有共享业务表,也没有显式持锁事务。此比例来自刻意同步的压力窗口,不代表线上失败率。
    4. 所有失败的 TRUNCATE 均保留目标表原始两行;成功后表为空。失败 TRUNCATE 前的 marker INSERT 按隐式提交契约保持已提交,之后 ROLLBACK 没有错误回滚该 marker。
    5. 持锁事务分别走 COMMIT/ROLLBACK,释放后没有残留 SNAPSHOT 锁;所有测试库清理成功。此次运行日志未发现 panic,未做长期泄漏或跨 CN 覆盖。

    代码分析

    未做故障注入或修改产品代码。仅对照代码解释黑盒结果:

    这属于当前实现明确保留的冲突行为,不是新发现的锁泄漏、死锁或随机锁服务错误。 但它仍不满足本 issue 正文提出的无关库 TRUNCATE 独立推进目标,需要明确该入口的验收范围。若继续保留全局 FastFail,需要对上层并发调用者明确这一限制;只增加用例重试不会消除持锁期间的跨库影响。

    回归测试

    本轮使用独立公共 SQL 复现脚本和逐次结果记录;没有修改 MOTR golden、skip、调度或产品代码。产品侧若收窄冲突域,应增加“源库 DDL 等待时,无关目标库 TRUNCATE 能完成”的回归,并保留失败原子性和同对象冲突检查。

    测试证据

    • 来源:MOTR run 37032919785 / job 111046061183。该轮 15 个 20706 失败对应系统表 ID 272477 的生命周期锁争用;本地独立复现证明不依赖 MOTR runner。
    • CI 的 MO SHA 为 9078a8bd87af49ea06f52e09d64e7740122aea61;复测 main 为上述 529ee099…。两个版本的 lifecycle_admission.go 和 issue_29400_test.go 没有差异。
    • 上面提供完整的最小 SQL、锁事务关系、重复次数和对照结果。CI 当时的具体持锁者仍未从历史日志恢复,不能把本地 DROP 事务当作那轮 CI 的已证实持锁者。
    • 本结论仅针对本文补测的跨库 TRUNCATE 进展目标;原 issue 的无关 DROP 路径在此复测中成功。

    测试结论

    测试不通过。

  7. LeftHandCold commented on Oct 7, 2026

    @LeftHandCold
    Collaborator

    Additional evidence from Main Daily, MO 5669b1683cf2188652c4ea56390e6a77ab5d13d8:

    At 2026-10-06 20:31:37.140 UTC / 2026-10-07 04:31:37.140 CST, the Fulltext comprehensive case's TRUNCATE TABLE docs failed with 20706, lock options conflict, wait policy is fast fail on the TP CN. Earlier index rebuilds, searches and result checks had passed. The truncate itself returned an error; the subsequent presence of the old rows is not evidence of a successful truncate retaining data. The empty-table/reinsert checks were not completed.

    The correlated service log records:

    txn: b75b46e3a8e38f4618dbfaff14e665a7
    lock binding table: 272477
    row count: 1
    opts: Exclusive-Row-FastFail
    error: lock options conflict, wait policy is fast fail
    

    MOTR also reported 13 cases involving the same fast-fail error class. This is a continuing DDL availability signal, rather than 13 independently established correctness bugs.

    The current lifecycle admission code still requests an exclusive global SNAPSHOT registry gate for broad table lifecycle operations, and public TRUNCATE requests prompt conflict behavior. This matches the risk domain tracked here. The present trace does not expose the holder transaction or prove that table 272477 is this exact registry relation, so I am not claiming that this Daily established the identical holder chain, a lock leak, or a regression in an unrelated Fulltext algorithm.

    The next decisive evidence is the holder and its retained gate/database/component keys at the truncate timestamp. Removing the lifecycle gate or changing fast-fail into an unbounded wait would not be a justified fix from these logs alone.

  8. iamlinjunhong commented on Oct 8, 2026

    @iamlinjunhong
    Contributor

    Additional exact-case evidence from MatrixOne PR #27716, head d33048c3c7f94eb37fcc6332f85d3e068cf372f3.

    The Linux/x64 pessimistic standalone BVT failed in run 37816787756, job 113452961523. The terminal BVT summary was TOTAL: 81751, SUCCESS: 81293, FAILED: 3, IGNORED: 455, ABNORMAL: 0; all three failures had the same stable product error:

    ERROR 20706: lock options conflict, wait policy is fast fail
    

    Exact cases:

    • snapshot/sys_restore_view_to_newnonsys_account.sql, line 297: truncate departments; returned the error.
    • stage/stage_based_stage.sql, line 60: truncate t2; returned the error.
    • The following line in the same stage case then observed two rows instead of one because the preceding TRUNCATE did not execute; this is a consequence, not a separate mechanism.

    The coverage job 113471284054 failed downstream because a required producer did not publish a complete coverage profile; it calculated no coverage verdict.

    This PR changes the information_schema.VIEWS catalog definition/protocol, bootstrap authoring, and remote View-function gates. Its diff and dependency closure do not include the lifecycle admission implementation, the stage or snapshot cases, or the BVT harness. On the same exact head, Shared Build, SCA, UT Coverage, Compose proxy BVT, Connector/J Pool Reset E2E, and the focused VIEWS validation checks passed.

    The same normalized failure class is independently present on official main in nightly run 37484909730, head 5669b1683cf2188652c4ea56390e6a77ab5d13d8: the Linux/amd64 Fulltext job 112485008277 and MOTR job 112485009712 both recorded 20706: lock options conflict, wait policy is fast fail, including a TRUNCATE case. The existing analysis here identifies the shared global SNAPSHOT lifecycle gate and public TRUNCATE fast-fail contract as the mechanism. This makes the two PR cases additional exact-case occurrences of the same open defect; the PR itself does not touch that mechanism.

    After recording this evidence, I will rerun the failed jobs of run 37816787756 once.

  9. Ariznawlll commented on Oct 9, 2026

    @Ariznawlll
    Collaborator

    补充 2026-10-09 Main Weekly 的 MOTR 锁冲突证据。这是历史 CI 日志回溯,不是新的独立最小复现。

    本轮使用 MatrixOne 官方 main 83d82b8ee0cd694e0c6a7146902d74ae4dfb415a、MOTR 337d47a033390a3853b45748da365684a5f3482c,TKE Weekly Full 1TP+2AP。运行 / MOTR job。排查 namespace mo-main-family-37874777871-1,TP CN nightly-regression-dis-tp-cn-ldzlf。

    锁冲突证据

    • 2026-10-09 08:59:22.737–09:14:01.853 UTC,12 个失败事务均在系统表 ID 272477 上申请 Exclusive-Row-FastFail,返回 ERROR 20706: lock options conflict, wait policy is fast fail。
    • 同轮 DN nightly-regression-dis-dn-0 日志明确将 272477 映射为 mo_catalog.mo_feature_registry;TP CN 在对应窗口有对 feature_code = 'SNAPSHOT' 的密集查询和更新。
    • 代表性实例:09:08:45.533 UTC,TRUNCATE TABLE motr_27922_cluster_ai 的申请事务 a95d86f79b3c3a0518dcbcc9dd8b78af 在该系统表上 fast-fail。该 TRUNCATE 未成功;其后的重复主键或行数不符,应先按前置清空失败的连锁结果解释,不能直接当作成功清空后数据损坏。

    同时发生的操作与证据边界

    • 08:59:22 的失败窗口可见 DROP ACCOUNT st_sub2 清理。
    • 09:08:45.533 的失败窗口,DROP ACCOUNT motr_ps_sub 清理从 09:08:45.452 至至少 09:08:48.961 UTC 并发进行。
    • 09:14:01.853 的失败窗口,DROP ACCOUNT priv_matrix 清理于 09:14:00.825 UTC 开始。

    三个抽查窗口均有租户删除清理并发,提示这一生命周期入口值得核对;但这不是对持锁事务的直接证明。lockservice 错误只记录申请失败的事务,未给出当刻持锁事务 ID;历史窗口也没有同步 mo_locks 持锁快照。因此不能断言 12 次均由这些 DROP ACCOUNT 引起,更不能把它们说成已经证实的“慢 DROP DATABASE”链条。它们属于本 issue 已讨论的共享 SNAPSHOT 生命周期锁风险域,尚无证据支持另开 12 个独立正确性问题。

    本次只补充 CI/服务日志证据,没有新跑最小复现或对照,没有改产品代码、MOTR 用例、golden 或 skip。若需精确确认持锁来源,应在下次复现的失败瞬间采集 mo_locks 的持锁/等待事务、lock_content、模式及对应 SQL,再按事务 ID 串联。

  10. XuPeng-SH commented on Oct 11, 2026

    @XuPeng-SH
    ContributorAuthor

    fixed

  11. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    Collaborator

    测试版本

    MatrixOne 最新固定 main@02a2823c2007d5e4fb4ada148e93743df337551a;本地单 CN/TN/LogService 服务,默认悲观 RC。测试数据均为独立临时库。

    原问题验证

    按照原 issue 的锁链,在 A 连接中先 BEGIN; UPDATE target.t ... 持有目标表行锁;B 并发 DROP DATABASE target 被该锁挡住;B 尚未完成时,C 对完全不同数据库执行 DROP TABLE guard.g; CREATE TABLE guard.g ...; INSERT。当前 main 上 C 没有被全局 SNAPSHOT gate 拖入 B 的等待队列,3 次独立重建的耗时分别为 0.027 / 0.021 / 0.023 秒。三次 C 完成时 B 仍在等待;A 回滚后 B 正常完成(B 全程约 0.53 秒),目标库被移除,guard 表及插入行保持正确。

    Happy Path 覆盖

    • 不相关数据库的 DROP/CREATE/INSERT 在慢 DROP 持锁期间继续推进;完成后读取 guard 表为 1 行。
    • 目标表阻塞解除后,DROP DATABASE 成功,目标库元数据计数为 0。
    • 三次使用全新目标库和 guard 库,均符合相同结果。

    Unhappy Path 覆盖

    • 明确断言 B 在 C 运行期间未提前完成,避免把“没有形成阻塞”的假通过当成修复。
    • 超时/错误会使脚本失败,并在 finally 回滚 holder、等待线程、清理自身数据库;没有依赖放宽锁等待或修改全局配置。
    • main 中已有 TestIssue29400... Go 定向测试覆盖跨 CN/锁门控、COPY ALTER 保留门控失败、DROP TABLE/DATABASE reclaim 错误回滚、branch 子分区及外键 clone 等;本次整体定向测试通过。

    白盒验证

    执行 go test ./pkg/tests/issues -run '^TestIssue29400' -count=1 -timeout=20m,结果 ok(37.605 秒)。与本次真实 SQL 复现的独立数据库前进性共同验证,不仅检查最终结果,也检查阻塞窗口内的进展。

    回归测试

    该问题的关键是跨连接时序、锁作用域、取消/回滚和跨 CN 同步,现有 Go 并发测试比串行 MOTR SQL golden 更合适,因此本次不新增只能检查最终状态的 MOTR。尚未在原生产多 CN/长时 DROP 的 TKE 环境重跑;本轮 0.5 秒受控阻塞也不是长时吞吐基准。

    测试证据

    • 本地受控 SQL 脚本 qa-oct12/validate_29400.py,3/3;C 耗时 0.027 / 0.021 / 0.023 秒,B 在 C 完成时均未结束,释放 A 后 3/3 成功。
    • 同脚本额外按全新临时库复跑 12 轮,12/12 成功;C 的独立库 DDL 耗时 0.022–0.040 秒,均在 B 仍被目标表阻塞时完成。
    • Go 定向测试:pkg/tests/issues/issue_29400_test.go,TestIssue29400... 全部通过。

    在上述验证范围内,原 issue 的跨库 DDL convoy 已消失;尚未把本地单 CN 测试等同于原生产拓扑的性能验收。现转回研发核对其预期的多 CN 验收边界。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

4.3-devkind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions