Skip to content

Fix AUTO_INCREMENT cache after rolled-back DROP DATABASE - #29397

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29395-autoid-rollback
Sep 27, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29395-autoid-rollback

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 27, 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:

Fixes #29395

What this PR does / why we need it:

Cancelling DROP DATABASE after an AUTO_INCREMENT table was visited rolls back its catalog changes, but the auto-increment service previously kept that table's deletion until transaction close. A later COMMIT of earlier successful work then retired the restored table's allocator.

This change makes transaction-close actions opt into statement ownership. RollbackLastStatement discards only actions registered by the failed statement, after releasing the workspace lock; earlier successful actions and transaction-global callbacks survive. Auto-increment Create/Delete use per-operation callbacks, so Reset's paired effects follow the same statement outcome. The old transaction-wide delete queue and aggregate handler are removed. Create ownership is keyed by transaction/table and exact callback identity, avoiding a table-list scan on close.

The statement-rollback unit test observes storage and the deletion queue in one lock-stable snapshot. It accepts both queued and completed deletion of the earlier statement's table, while requiring the rolled-back statement's table to retain its original cache and storage. It does not rely on the reaper's scheduling, sleeps, or changes to the global cleanup interval.

A committed public-wire regression now uses the existing shared embedded cluster. Its context-aware fault barrier stops DROP DATABASE immediately after its only AUTO_INCREMENT table's nested DROP completes, so the test cannot depend on unspecified relation order. A second connection cancels the query with KILL QUERY; the original connection then COMMITs or ROLLBACKs. The test verifies the earlier guard write's corresponding outcome, the restored row, a subsequent implicit-ID insert, and ordinary successful DROP after the fault is removed. The fault point is inert when disabled and adds one lookup per nested table DROP, with no DML-path work.

The new public test passed twice, including named COMMIT and ROLLBACK subtests. With the same test and barrier on clean main but without this PR's allocator fix, the COMMIT subtest fails on Error 1146: no such table; this is a direct before/after oracle. go vet and incremental golangci-lint passed for the changed compile/integration-test packages. An adjacent old TestDropDatabase_SnapshotAdvance mock test panics on missing lock service at both clean main and this PR before reaching the new barrier; it is not counted as a pass. Earlier validation of the unchanged allocator/operator/disttae production patch remains valid: their owning package suites passed normally and under -race, focused rollback tests passed 100 race repetitions each, and the full binary build passed. Remote CI must be assessed separately; local results do not imply CI has passed.

No new catalog I/O is added to DML or commit. The per-statement checkpoint is constant-time; rollback visits only callbacks from that statement. Shard-service deferred callbacks and broader SetOffset statement history are separate neighboring lifecycle concerns, not claimed fixed here. Reset's unit test verifies cache lifecycle only: the memory-store fixture does not model statement-level catalog rollback, and the standalone SQL probe covers DROP, not durable TRUNCATE/ALTER rollback.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of 05e8927dcd2fa8a31023641bd591442aa0b84fa4 (base 9c6fcb5b501d040ab1bcb5ada139939770468638): the AUTO_INCREMENT lifecycle change has no confirmed new production regression. I checked ordinary CREATE/DROP/TRUNCATE/Reset, statement retry and terminal callback ordering, Create readiness versus rollback/Close, per-table ownership and cache retirement, and the additional work on ordinary SQL and bulk DDL. The existing standalone SQL probe and owning-package normal/race evidence remain valid for this head; the final test-oracle correction passed 100 focused race repetitions and the package suite.

Test coverage needs one follow-up before treating this as a durable regression fix: commit a public SQL/BVT case for BEGIN + earlier successful work + a cancelled DROP DATABASE after it visits an AUTO_INCREMENT table + COMMIT, then verify the restored table's AUTO_INCREMENT insert and the untouched-table/control outcomes. The current TestDeleteStatementRollbackPreservesOnlyEarlierActions invokes the callback interface directly, while memStore has no statement-level catalog rollback; the standalone probe is not part of CI. The existing rollback_txn_on_error.sql covers earlier-work preservation after other failures but not this DDL/callback boundary.

Adjacent pre-existing issue, separate from this PR's AUTO_INCREMENT claim: when shard service is enabled for a partitioned table, shardservice.Delete still registers a transaction-scoped ClosedEvent callback. A failed DROP statement can restore metadata but retain that callback; later COMMIT can enqueue remote shard deletion and cause lazy-recreation latency on the next read. The shardservice code is unchanged by this PR. It merits its own statement-rollback regression and fix, not an unsupported assertion that this PR solves it.

Performance/lifecycle: statement start adds one operator lock; statement rollback scans only its callback suffix and clears removed slots; Create/Delete terminal processing remains linear in affected tables and adds no catalog I/O. No workload benchmark is available, so this is a code-path assessment, not a throughput claim. No new Q1-Q3 leak, hang, or unbounded retention path was established. CI's Ubuntu UT, coverage, arm64 SCA, and shared build were still pending at review time.

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cancelled DROP DATABASE leaves restored AUTO_INCREMENT tables unusable after COMMIT

2 participants