Skip to content

[Bug]: CREATE ACCOUNT globally serializes on the View metadata gate and times out concurrent account operations #28079

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

Incident: a2d9070974cd42fc11ac530e52f962a696df9089

Still present in current main: ffc8d9f0625c76e87ba967984ce19db2d082b0ba

Other Environment Information

Actual Behavior

The normal-concurrency create_drop_account case completed, but
create_drop_account_high caused account lifecycle operations to wait for
roughly 60-100 seconds and then fail at the client connection timeout.

The high-concurrency case started at 2026-09-02 05:32:36 UTC:

CREATE side:
VUSER   : 50
SUCCESS : 260
RT_MAX  : 75574 ms
RT_AVG  : 64650.75 ms

DROP side:
VUSER   : 20
SUCCESS : 764
ERROR   : 37
RT_MAX  : 100089 ms
RT_AVG  : 4947.66 ms

The failed requests were DROP ACCOUNT IF EXISTS ... statements. They
reported:

Communications link failure
The last packet successfully received from the server was about 100,000
milliseconds ago.

This is not evidence of a network disconnect by itself. It is the client-side
surface after the SQL request receives no response for the JDBC timeout.

Proven Regression Cause

PR #27370, merge commit dae2725bef5c81dcb9b5d2fab9a48afe37e2c760,
added this call inside every CREATE ACCOUNT transaction:

inheritViewMetadataRevalidation(ctx, bh, serviceID, newTenantID)

Code:

  • if rtnErr = inheritViewMetadataRevalidation(ctx, bh, ses.GetService(), newTenant.GetTenantID()); rtnErr != nil {
    return rtnErr
    }
  • func inheritViewMetadataRevalidation(
    ctx context.Context,
    bh BackgroundExec,
    serviceID string,
    accountID uint32,
    ) error {
    if err := bh.Exec(ctx, catalog.ViewMetadataLifecycleGateSQL); err != nil {
    if !compile.ViewMetadataRefreshEnabled(serviceID) &&
    (moerr.IsMoErrCode(err, moerr.ErrNoSuchTable) || moerr.IsMoErrCode(err, moerr.ErrBadDB)) {
    return nil
    }
    return err
    }
    err := bh.Exec(ctx, fmt.Sprintf(
    "insert into %s.%s (%s) select %d,0,0,0,'%s','%s',0,0,0,0,0,'','','','',d.source_relation_kind,'',0,null,0,d.dependency_generation "+
    "from %s.%s d where d.account_id=0 and d.target_relation_id=0 and d.dependency_ordinal=0 "+
    "and d.source_relation_kind in ('%s','%s','%s','%s') and not exists (select 1 from %s.%s a "+
    "where a.account_id=%d and a.target_relation_id=0 and a.dependency_ordinal=0)",
    catalog.MO_CATALOG, catalog.MO_VIEW_DEPENDENCIES, catalog.MoViewDependenciesColumns,
    accountID, catalog.LegacyViewScanCursorDatabase, catalog.LegacyViewScanCursorRelation,
    catalog.MO_CATALOG, catalog.MO_VIEW_DEPENDENCIES,
    catalog.ViewRefreshStatusRevalidateRequired, catalog.ViewRefreshStatusRevalidateScan,
    catalog.ViewRefreshStatusActivated, catalog.ViewRefreshStatusLegacyScan,
    catalog.MO_CATALOG, catalog.MO_VIEW_DEPENDENCIES, accountID))

The function unconditionally executes:

SELECT rel_id
FROM mo_catalog.mo_tables
WHERE account_id = 0
  AND reldatabase = 'mo_catalog'
  AND relname = 'mo_view_refresh'
FOR UPDATE;

Definition:

  • const ViewMetadataLifecycleGateSQL = "select rel_id from mo_catalog.mo_tables " +
    "where account_id=0 and reldatabase='mo_catalog' and relname='mo_view_refresh' for update"

All concurrent account creations therefore contend for the same system-account
catalog row. The lock is held in the surrounding account-creation transaction,
which converts independent tenant creation into one global serial queue.
Concurrent DROP work then overlaps the backed-up account lifecycle workload and
eventually reaches its 100-second client timeout.

CN logs in the incident window contain hundreds of long lock waits on the same
mo_catalog/mo_view_refresh row key. Before #27370, comparable concurrent
account runs had no such gate-row wait burst.

ViewMetadataRefreshEnabled=false does not avoid the lock. The code executes
the FOR UPDATE first and only consults that flag while handling a
missing-table/missing-database error.

No commit between the incident revision and current main changes either
inheritViewMetadataRevalidation or ViewMetadataLifecycleGateSQL.
Therefore the regression remains reachable on current main.

PR #27370 references #26227, but #26227 tracks stale View schema metadata. It
does not track this account-concurrency regression.

Expected Behavior

Creating unrelated accounts must not serialize on one global catalog row.
Concurrent CREATE/DROP ACCOUNT operations should either make bounded progress
or return a database error; they must not stall until the client reports a
connection failure.

The View metadata lifecycle must retain its correctness fence without placing
the whole account-creation transaction behind one globally exclusive row lock.

Steps to Reproduce

1. Deploy a distributed MatrixOne cluster containing PR #27370.
2. Run the normal account concurrency case as a control:
   ./start.sh -h <proxy> -c cases/ddl/create_drop_account/ -g
3. Run the high-concurrency case:
   ./start.sh -h <proxy> -c cases/ddl/create_drop_account_high/ -g
4. Use 50 CREATE workers and 20 DROP workers, as in run 33523792810.
5. Record CREATE/DROP latency and query CN lockservice logs for the
   mo_catalog.mo_view_refresh row.

Expected discriminator:

  • a revision before dae2725bef5 does not show the global gate-row wait
    queue;
  • dae2725bef5 and current main do;
  • a valid fix must remove the queue while preserving View metadata lifecycle
    correctness and transaction atomicity.

Additional information

Activity

  1. added
    kind/bug
    on Sep 3, 2026
  2. assigned and unassigned on Sep 28, 2026
  3. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:干净源码 worktree;定向 Go UT/集成回归(涉及 Proxy/CN 的路径使用对应组件级并发与协议模拟)
    • 测试日期:2026-10-02

    原问题验证

    在上述 commit 运行 issue 对应的定向回归。并发 CREATE ACCOUNT 共享 lifecycle gate,但不再因 View metadata 全局串行而超时;temporary alter 保持 optimistic transaction。

    Happy Path 覆盖

    覆盖多 account 并发创建和正常 refresh。

    Unhappy Path 覆盖

    覆盖 view refresh failure、temporary alter 与并发 lifecycle;失败不泄漏 gate。

    白盒验证

    关联修复 #28436、#29234 已进入当前 main。直接执行并检查的定向测试为:pkg/tests/issues/issue_28079_test.go 的三个 lifecycle regression tests。

    回归测试

    本问题依赖内部故障注入、并发时序、catalog/optimizer 状态或多组件协议边界,无法由普通 SQL golden 稳定构造,因此不放入 MOTR;回归保留在 MatrixOne UT/BVT 层。对应定向测试在精确 commit 上通过,且未修改用户工作区。

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 定向测试:pkg/tests/issues/issue_28079_test.go 的三个 lifecycle regression tests
    • 当前结果:并发 CREATE ACCOUNT 共享 lifecycle gate,但不再因 View metadata 全局串行而超时;temporary alter 保持 optimistic transaction。
    • 关联 PR:#28436、#29234

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions