Skip to content

restore account may fail during DropDatabase FK cleanup when FK-related tables were already deleted in the same txn #24008

Closed

Description

@XuPeng-SH

Problem

restore account ... {snapshot=...} can intermittently fail during snapshot restore. A representative failure looks like:

restore account acc01{snapshot="sp10"}
no such table acc_test02.aff01

After that, the restore does not fully converge to the snapshot state.

Root cause

The failure path is in restoreToAccountFromTS() -> DropDatabase -> removeFkeysRelationships().

During restore, FK-related tables may already be deleted earlier in the same restore transaction. Later FK cleanup still revisits them through three lookup surfaces:

  • database.Relation(...) on names returned by Relations()
  • parent lookup via GetRelationById(fkey.ForeignTbl)
  • child lookup via GetRelationById(childId)

Those surfaces can legitimately return:

  • ErrNoSuchTable
  • ErrInternal with can not find table by id ... Deleted in txn

These are expected same-transaction missing-table states, but they can still abort restore if treated as fatal.

Expected behavior

FK cleanup during DropDatabase should skip these same-transaction missing-table cases and continue restore, while still surfacing unrelated errors.

Fix direction

Unify the three FK-cleanup lookup paths behind a narrow helper that only tolerates:

  • moerr.ErrNoSuchTable
  • moerr.ErrInternal containing can not find table by id

All other errors should still be returned.

Validation

Compile-level regression coverage:

  • TestRemoveFkeysRelationshipsSkipsDeletedRelationsDuringDropDatabase
  • TestRemoveFkeysRelationshipsSkipsDeletedChildTableIds
  • TestRemoveFkeysRelationshipsSkipsDeletedParentTableIds

Validated with:

CGO_CFLAGS='-I/home/xupeng/matrixone/thirdparties/install/include' \
CGO_LDFLAGS='-L/home/xupeng/matrixone/thirdparties/install/lib' \
LD_LIBRARY_PATH='/home/xupeng/matrixone/thirdparties/install/lib' \
go test ./pkg/sql/compile -count=1

Activity

  1. added a commit that references this issue on Mar 29, 2026
    68a6b79
  2. self-assigned this
    on Mar 29, 2026
  3. added
    kind/bug
    severity/s0
    on Mar 29, 2026
  4. added theissue type on Mar 29, 2026
  5. added this to the MO-202603 milestone on Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions