Repository navigation
Fix AUTO_INCREMENT cache after rolled-back DROP DATABASE - #29397
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29395
What this PR does / why we need it:
Cancelling
DROP DATABASEafter 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 laterCOMMITof earlier successful work then retired the restored table's allocator.This change makes transaction-close actions opt into statement ownership.
RollbackLastStatementdiscards 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 DATABASEimmediately 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 withKILL 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 vetand incrementalgolangci-lintpassed for the changed compile/integration-test packages. An adjacent oldTestDropDatabase_SnapshotAdvancemock test panics onmissing lock serviceat 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.