Skip to content

fix: tolerate same-txn missing tables during FK cleanup - #24009

Merged
mergify[bot] merged 2 commits into
mainfrom
fix/snapshot-fk-cleanup
Mar 29, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
fix/snapshot-fk-cleanup

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • API-change
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24008 #23955

What this PR does / why we need it:

This PR fixes an intermittent snapshot restore failure during restore account ... {snapshot=...}.

The failure happens in DropDatabase -> removeFkeysRelationships() when FK cleanup revisits tables that were already deleted earlier in the same restore transaction. Before this patch, some of these expected missing-table cases could still abort the restore.

This change makes the handling symmetric across all three relevant FK-cleanup lookup surfaces:

  • opening a relation returned by Relations()
  • looking up the parent table via GetRelationById(fkey.ForeignTbl)
  • looking up child tables via GetRelationById(childId)

Only two narrow cases are tolerated:

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

All other errors still return immediately.

This PR also adds focused regression coverage for all three missing-table surfaces in pkg/sql/compile/ddl_test.go.

Validation:

  • go test ./pkg/sql/compile -run 'TestRemoveFkeysRelationshipsSkipsDeletedRelationsDuringDropDatabase|TestRemoveFkeysRelationshipsSkipsDeletedChildTableIds|TestRemoveFkeysRelationshipsSkipsDeletedParentTableIds' -count=1
  • go test ./pkg/sql/compile -count=1

@mergify mergify Bot added the queued label Mar 29, 2026
@mergify
mergify Bot merged commit c7bbad4 into main Mar 29, 2026
29 checks passed
@mergify
mergify Bot deleted the fix/snapshot-fk-cleanup branch March 29, 2026 02:56
@mergify

mergify Bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-03-29 02:56 UTC · Rule: main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-03-29 02:56 UTC · at c0267aeb27a2146834290ee0ecc6e6413ec75217

This pull request spent 5 seconds in the queue, with no time running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify mergify Bot removed the queued label Mar 29, 2026
aptend pushed a commit to aptend/matrixone that referenced this pull request Apr 2, 2026
…#24009)

This PR fixes an intermittent snapshot restore failure during `restore account ... {snapshot=...}`.

The failure happens in `DropDatabase -> removeFkeysRelationships()` when FK cleanup revisits tables that were already deleted earlier in the same restore transaction. Before this patch, some of these expected missing-table cases could still abort the restore.

This change makes the handling symmetric across all three relevant FK-cleanup lookup surfaces:

- opening a relation returned by `Relations()`
- looking up the parent table via `GetRelationById(fkey.ForeignTbl)`
- looking up child tables via `GetRelationById(childId)`

Only two narrow cases are tolerated:

- `moerr.ErrNoSuchTable`
- `moerr.ErrInternal` with `can not find table by id`

All other errors still return immediately.

This PR also adds focused regression coverage for all three missing-table surfaces in `pkg/sql/compile/ddl_test.go`.

Validation:

- `go test ./pkg/sql/compile -run 'TestRemoveFkeysRelationshipsSkipsDeletedRelationsDuringDropDatabase|TestRemoveFkeysRelationshipsSkipsDeletedChildTableIds|TestRemoveFkeysRelationshipsSkipsDeletedParentTableIds' -count=1`
- `go test ./pkg/sql/compile -count=1`

Approved by: @ouyuanning
jiangxinmeng1 added a commit to jiangxinmeng1/matrixone that referenced this pull request Apr 14, 2026
When a table has stale RefChildTbls entries pointing to non-existent
child tables, the FkChildTblsReferToMe cleanup loop in dropTableSingle
would fail with 'can not find table by id' error, blocking DROP TABLE
and DROP ACCOUNT operations.

This adds the same isMissingTableForFkCleanup error tolerance that
PR matrixorigin#24009 added to removeFkeysRelationships (DropDatabase path), but
for the DropTable path's child table lookup.

Also upgrades the existing ForeignTbl loop error check from a raw
strings.Contains to the more robust isMissingTableForFkCleanup helper.

Approved by: jiangxinmeng1

Co-authored-by: Copilot <[email protected]>
mergify Bot pushed a commit that referenced this pull request Apr 14, 2026
When a table has stale `RefChildTbls` entries pointing to non-existent child tables (due to previous operations like CDC, snapshot restore, or prior bugs), the `FkChildTblsReferToMe` cleanup loop in `dropTableSingle` fails with:

```
internal error: can not find table by id <N>: accountId: <M>
```

This blocks `DROP TABLE` and `DROP ACCOUNT` operations.

Related issue: #24008 / PR #24009 (fixed the same error in `removeFkeysRelationships` for DropDatabase path, but missed the DropTable path).

Approved by: @aunjgr
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
…#24009)

This PR fixes an intermittent snapshot restore failure during `restore account ... {snapshot=...}`.

The failure happens in `DropDatabase -> removeFkeysRelationships()` when FK cleanup revisits tables that were already deleted earlier in the same restore transaction. Before this patch, some of these expected missing-table cases could still abort the restore.

This change makes the handling symmetric across all three relevant FK-cleanup lookup surfaces:

- opening a relation returned by `Relations()`
- looking up the parent table via `GetRelationById(fkey.ForeignTbl)`
- looking up child tables via `GetRelationById(childId)`

Only two narrow cases are tolerated:

- `moerr.ErrNoSuchTable`
- `moerr.ErrInternal` with `can not find table by id`

All other errors still return immediately.

This PR also adds focused regression coverage for all three missing-table surfaces in `pkg/sql/compile/ddl_test.go`.

Validation:

- `go test ./pkg/sql/compile -run 'TestRemoveFkeysRelationshipsSkipsDeletedRelationsDuringDropDatabase|TestRemoveFkeysRelationshipsSkipsDeletedChildTableIds|TestRemoveFkeysRelationshipsSkipsDeletedParentTableIds' -count=1`
- `go test ./pkg/sql/compile -count=1`

Approved by: @ouyuanning
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
…#24132)

When a table has stale `RefChildTbls` entries pointing to non-existent child tables (due to previous operations like CDC, snapshot restore, or prior bugs), the `FkChildTblsReferToMe` cleanup loop in `dropTableSingle` fails with:

```
internal error: can not find table by id <N>: accountId: <M>
```

This blocks `DROP TABLE` and `DROP ACCOUNT` operations.

Related issue: matrixorigin#24008 / PR matrixorigin#24009 (fixed the same error in `removeFkeysRelationships` for DropDatabase path, but missed the DropTable path).

Approved by: @aunjgr

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants