Skip to content

[Bug]: restore account to new non-sys account can fail with no such table acc_test02.aff01 #23955

Closed

Description

@gouhongshen

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

3.0-dev

Commit ID

latest

Other Environment Information

- Hardware parameters: GitHub Actions runner
- OS type: Linux
- Others:
  - Observed in PR #23952 BVT
  - Failing case: test/distributed/cases/snapshot/sys_restore_to_newnonsys_account.sql
  - Log source: mo-service.log from the failed CI run

Actual Behavior

In BVT, restore account acc01 from snapshot sp07 to account acc02; fails with:

no such table acc_test02.aff01

Relevant executor output from the CI failure:

2026-03-25 07:54:13 ERROR Executor:269 - [/home/runner/_work/matrixone/matrixone/matrixone/test/distributed/cases/snapshot/sys_restore_to_newnonsys_account.sql][row:262][restore account acc01 from snapshot sp07 to account acc02;] was executed failed, con[id=0, user=dump, ***
2026-03-25 07:54:13 ERROR Executor:271 - [EXPECT RESULT]:
null
2026-03-25 07:54:13 ERROR Executor:272 - [ACTUAL RESULT]:
no such table acc_test02.aff01

From mo-service.log, the restore path reports that the target account/database/tables are missing during restore:

30199. Failed to get database acc_test02, error: ExpectedEOB
30200. error: no such table acc_test02.pri01
30201. error: no such table acc_test02.aff01
30244. Failed to get database acc_test02, error: ExpectedEOB
30245. error: Can't drop database 'acc_test02'; database doesn't exist

This suggests that restore-to-new-non-sys-account can leave acc_test02 and its child tables missing or only partially rebuilt.

Expected Behavior

restore account acc01 from snapshot sp07 to account acc02; should succeed, and the restored account acc02 should contain the snapshot contents from sp07, including the objects under acc_test02 such as pri01 and aff01.

Steps to Reproduce

1. Run the snapshot BVT case: `test/distributed/cases/snapshot/sys_restore_to_newnonsys_account.sql`.
2. In that case, create snapshot `sp07` for account `acc01`, make additional changes after the snapshot, then run:
   `restore account acc01 from snapshot sp07 to account acc02;`
3. Observe the restore fail at line 262 with:
   `no such table acc_test02.aff01`

Relevant SQL fragment:

```sql
drop snapshot if exists sp07;
create snapshot sp07 for account acc01;

-- @session:id=1&user=acc01:test_account&password=111
use test01;
drop table table01;
insert into table02 values(134, 'database');
-- @session

restore account acc01 from snapshot sp07 to account acc02;

### Additional information

Focused log excerpt from `mo-service.log`:

```text
{"level":"ERROR","time":"2026/03/25 07:51:30.467090 +0000","name":"cn-service","caller":"frontend/compiler_context.go:218","msg":"Failed to get database","databaseName":"acc_test02","error":"ExpectedEOB",...}
{"level":"ERROR","time":"2026/03/25 07:51:30.475385 +0000","caller":"disttae/txn_database.go:169","msg":"error: no such table acc_test02.pri01",...}
{"level":"ERROR","time":"2026/03/25 07:51:30.493881 +0000","caller":"disttae/txn_database.go:169","msg":"error: no such table acc_test02.aff01",...}
{"level":"ERROR","time":"2026/03/25 07:51:30.928652 +0000","caller":"compile/ddl.go:136","msg":"error: Can't drop database 'acc_test02'; database doesn't exist",...}

This looks unrelated to the dedupjoin retry fix in PR #23952: the failing logs are in snapshot/account restore code paths (frontend/compiler_context.go, disttae/txn_database.go, compile/ddl.go), and I did not find any checkSnapshotAdvancedDuplicates / ErrTxnNeedRetry traces around the failure window.

Activity

  1. self-assigned this
    on Mar 25, 2026
  2. added
    kind/bug
    on Mar 25, 2026
  3. XuPeng-SH commented on Apr 6, 2026

    @XuPeng-SH
    Contributor

    Root Cause Analysis from Code Tracing

    I traced the full code path for the snapshot restore FK table failure. The error "no such table repub02.aff01" (or acc_test02.aff01) is not an FK ordering issue — it's a catalog cache / transaction workspace visibility issue during clone source resolution.

    Evidence

    From the logs in this issue:

    Failed to get database acc_test02, error: ExpectedEOB
    error: no such table acc_test02.pri01
    error: no such table acc_test02.aff01
    

    Both pri01 (parent, no FK) and aff01 (child with FK) fail. The database itself returns ExpectedEOB. This rules out FK ordering as the cause.

    Code Path Trace

    1. doRestoreSnapshot() (snapshot.go:528) starts a transaction (begin;)
    2. restoreToAccount() (snapshot.go:892) drops ALL databases (dropDb() at line 928), then recreates them from snapshot
    3. FK tables are deferred to restoreTablesWithFk() (snapshot.go:1279)
    4. recreateTable() executes clone SQL: create table X clone X {MO_TS = <ts>}
    5. TableClone() (ddl.go:3277) calls CreateTable() → FK validation calls ctx.Resolve(parentDb, parentTable, nil)
    6. TxnCompilerContext.Resolve() → getRelation() → Database() returns ExpectedEOB

    Why ExpectedEOB?

    The restore flow drops the database and recreates it within the same transaction:

    • dropDb() drops the original repub02 (database ID = X)
    • bh.Exec(createDbSql) recreates repub02 (database ID = Y, new ID)

    The clone source repub02.aff01 {MO_TS = <ts>} tries to resolve the database at the historical timestamp. But:

    • The OLD database (ID=X) was dropped in this transaction
    • The NEW database (ID=Y) was created in this transaction but may not be visible in the catalog cache at MO_TS
    • The Database() call in compiler_context.go:354 sees the new database but can't resolve historical data through it → ExpectedEOB

    Why It's Flaky

    This is a race condition between:

    • Transaction workspace writes (database creation)
    • Catalog cache visibility for historical snapshot reads
    • The CompilerContext's Resolve() may read from a stale catalog cache snapshot

    Relevant Code Locations

    Location What it does
    snapshot.go:928 dropDb() drops database
    snapshot.go:1100 Creates database from snapshot
    snapshot.go:1472 Clone SQL execution
    ddl.go:3284-3288 TableClone() → CreateTable()
    build_ddl.go:4606 FK validation: ctx.Resolve(parentDb, parentTable)
    compiler_context.go:354-361 Database() → ExpectedEOB → returns nil
    compiler_context.go:375-380 Relation() → ErrNoSuchTable → returns nil

    Possible Fix Approaches

    1. Don't drop/recreate databases during account restore — instead drop individual tables and clone them. This preserves the database ID so historical resolution works.
    2. Use snapshot-based resolution for clone source instead of MO_TS when the database was recently recreated (already partially done for cross-account restore at line 1484)
    3. Ensure catalog cache is flushed/updated after database creation before attempting clone operations
    4. Add retry logic in restoreTablesWithFk() for transient ExpectedEOB / ErrNoSuchTable errors during clone
  4. added 5 commits that reference this issue on Apr 6, 2026
    f73e4bb
    50477bc
    cfcdd72
    8353a1d
    be7dec6
  5. LeftHandCold commented on Apr 27, 2026

    @LeftHandCold
    Collaborator

    补充一组新的复现样本,症状与本 issue 一致,来自 PR #24206 的 BVT:

    BVT failure details from the job log:

    2026-04-27 14:00:17 ERROR Executor:269 - [test/distributed/cases/snapshot/cluster_level_snapshot_restore_to_nonsys_account.sql][row:212][restore account acc01 from snapshot sp04;] was executed failed
    EXPECT RESULT:
    null
    ACTUAL RESULT:
    no such table acc_test02.aff01
    
    2026-04-27 14:00:17 ERROR Executor:199 - [row:216][select count(*) from acc_test02.pri01;] was executed failed
    EXPECT RESULT:
    count(*)
    4
    ACTUAL RESULT:
    count(*)
    5
    
    2026-04-27 14:00:17 ERROR Executor:199 - [row:218][select count(*) from acc_test03.table01;] was executed failed
    EXPECT RESULT:
    count(*)
    2
    ACTUAL RESULT:
    count(*)
    0
    
    2026-04-27 14:00:17 ERROR Executor:269 - [row:219][select count(*) from acc_test03.table02;] was executed failed
    EXPECT RESULT:
    count(*)
    1
    ACTUAL RESULT:
    SQL parser error: table "table02" does not exist
    
    2026-04-27 14:00:17 ERROR Executor:199 - [row:220][select count(*) from acc_test03.table03;] was executed failed
    EXPECT RESULT:
    count(*)
    2
    ACTUAL RESULT:
    count(*)
    1
    

    从这次 BVT 看,问题不只是 restore 语句本身报 no such table acc_test02.aff01,restore 结束后目标 account 下多个对象/数据也没有恢复到预期状态:

    • acc_test02.aff01 缺失
    • acc_test02.pri01 行数多 1
    • acc_test03.table01 行数从预期 2 变成 0
    • acc_test03.table02 直接不存在
    • acc_test03.table03 行数从预期 2 变成 1

    这说明 cluster-level snapshot restore to non-sys account 仍然可能留下部分对象缺失或数据不一致。

  6. gouhongshen commented on Jun 8, 2026

    @gouhongshen
    ContributorAuthor

    should be fixed by #24747, #24748, #24749

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