[codex] fix DropDatabase SnapshotTS restore race - #24454
Merged
XuPeng-SH merged 9 commits intoMay 28, 2026
Merged
Conversation
gouhongshen
marked this pull request as ready for review
May 19, 2026 06:18
gouhongshen
requested review from
LeftHandCold,
XuPeng-SH,
aunjgr,
iamlinjunhong,
jiangxinmeng1 and
ouyuanning
as code owners
May 19, 2026 06:18
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
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #24381.
Fixes the data race between
Scope.DropDatabaserestoringSnapshotTSand concurrenttxnOperator.GetOverviewreads.DropDatabasestill temporarily advancesSnapshotTSafter acquiring the exclusivemo_databaselock, soRelations()continues to see tables committed before the lock was granted. The restore path now goes through a lockedTxnOperator.SetSnapshotTSmethod instead of writing throughTxnRef()directly.This PR also fixes a test-only race in
TestPushClient_PartitionStateGCTicker: the test changed the package-levelgcPartitionStateTickerwhile the ticker goroutine could still be reading it. The ticker tests now cancel and wait for their goroutines before restoring package-level intervals.Root Cause
The restore logic introduced after the DropDatabase/CLONE orphan-record fix wrote
txnOp.TxnRef().SnapshotTS = origSnapshotTSwithout holdingtxnOperator.mu.TxnRef()only protects returning the pointer; the caller's field write remains unlocked and can race withGetOverview()copyingtc.mu.txnunderRLock.The logtail ticker race was independent and test-local:
TestPushClient_PartitionStateGCTickerrestoredgcPartitionStateTickerin a defer without waiting for the spawned ticker goroutine to exit.TestPushClient_UnusedTableGCTickerhad the same lifecycle bug aroundunsubscribeProcessTicker, so it is fixed with the same helper.Changes
TxnOperator.SetSnapshotTSand implement it withtxnOperator.mu.Lock().SetSnapshotTSinDropDatabaseand in the existing lockop test helper path.StorageTxnOperatorsnapshot getter/setter and add focused coverage.DropDatabasetests to assertRelations()still runs under the advanced snapshot and the original snapshot is restored only on return.Validation
go test ./pkg/txn/client -run TestBase -count=1go test ./pkg/txn/storage/memorystorage -run TestStorageTxnOperatorSnapshotTS -count=1go test ./pkg/txn/storage/memorystorage -run TestStorageTxnOperatorSnapshotTS -count=1 -coverprofile=/tmp/memorystorage_snapshot.covergo test ./pkg/sql/compile -run TestDropDatabase_SnapshotAdvanceAndRestore -count=1go test -race ./pkg/tests/dml/ -run TestDataBranchDiffAsFile -count=1 -timeout 600sgo test -race ./pkg/vm/engine/disttae -run 'TestPushClient_(PartitionStateGCTicker|UnusedTableGCTicker)$' -count=10git diff --checkBackport
Backport PR: #24461 targeting
4.0-dev.