revert refreshSnapshotAfterLock#23794
Merged
heni02 merged 1 commit intomatrixorigin:3.0-devfrom Mar 3, 2026
Merged
Conversation
Review Summary by QodoRefine snapshot refresh logic for DROP DATABASE race condition
WalkthroughsDescription• Replace generic snapshot refresh with conditional logic based on transaction isolation level • Add explicit snapshot advancement only for pessimistic RC transactions when stale • Remove unused refreshSnapshotAfterLock function and moruntime import • Update tests to verify conditional snapshot refresh behavior Diagramflowchart LR
A["DROP DATABASE acquires<br/>exclusive lock"] -->|Check isolation level| B{"Pessimistic RC<br/>transaction?"}
B -->|Yes| C{"Snapshot stale?"}
B -->|No| D["Skip refresh"]
C -->|Yes| E["Get latest commit TS"]
C -->|No| D
E --> F["Wait for logtail applied"]
F --> G["Update snapshot"]
G --> H["Call Relations<br/>with fresh snapshot"]
D --> H
File Changes1. pkg/sql/compile/ddl.go
|
Code Review by Qodo
1. GetLatestCommitTS race window
|
ouyuanning
approved these changes
Mar 3, 2026
Comment on lines
+137
to
+148
| txnOp := c.proc.GetTxnOperator() | ||
| if txnOp.Txn().IsPessimistic() && txnOp.Txn().IsRCIsolation() { | ||
| latestCommitTS := c.proc.Base.TxnClient.GetLatestCommitTS() | ||
| if txnOp.Txn().SnapshotTS.Less(latestCommitTS) { | ||
| newTS, err := c.proc.Base.TxnClient.WaitLogTailAppliedAt(c.proc.Ctx, latestCommitTS) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := txnOp.UpdateSnapshot(c.proc.Ctx, newTS); err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
1. Getlatestcommitts race window 🐞 Bug ✓ Correctness
DropDatabase now conditionally refreshes snapshot based on TxnClient.GetLatestCommitTS(), but that value can lag behind a just-committed txn because it’s updated only on ClosedEvent, which fires after commit unlock. DROP can acquire the exclusive lock during this window and skip snapshot refresh, reintroducing stale Relations() reads and orphaned catalog rows.
Agent Prompt
### Issue description
`DropDatabase` refreshes the transaction snapshot based on `TxnClient.GetLatestCommitTS()` and may skip the refresh when `latestCommitTS` is stale. `latestCommitTS` is updated via a `ClosedEvent` callback, but transaction commit unlock is deferred to run before `closeLocked()` triggers `ClosedEvent`, creating a window where a concurrent txn can commit+unlock and DROP can acquire the exclusive lock before `latestCommitTS` is advanced.
### Issue Context
This can reintroduce the stale-snapshot catalog race (DROP missing recently created tables and leaving orphan records).
### Fix Focus Areas
- Reintroduce/restore the previous approach that advances snapshot based on a monotonic current timestamp (HLC/clock) and `WaitLogTailAppliedAt(now)` after the exclusive lock is acquired.
- Keep the refresh scoped to the same txn modes intended (pessimistic + RC), but do not depend on `GetLatestCommitTS()` being up-to-date in the immediate post-commit window.
### Fix Focus Areas (code locations)
- pkg/sql/compile/ddl.go[117-150]
- (reference) pkg/txn/client/operator.go[998-1012]
- (reference) pkg/txn/client/client.go[327-333]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
1 task
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.
What type of PR is this?
Which issue(s) this PR fixes:
issue #23766
What this PR does / why we need it:
revert refreshSnapshotAfterLock