tso: use OrderedSingleFlight to reduce data race on logical overflow update
- Dominant language
- Go
- Stars
- 1.2k
- Forks
- 783
- Avg merge
- 5d 21h
- Merged PRs (30d)
- 36
Description
## Enhancement Task
### Problem
In `timestampOracle.getTS`, when the TSO logical part overflows (`overflowedLogical`),
multiple concurrent goroutines can simultaneously call `updateTimestamp(overflowUpdate)`.
This causes redundant concurrent writes to the in-memory TSO state (`tsoMux`) and
unnecessary repeated etcd writes, and can trigger data races under the race detector.
### Solution
Wrap the `updateTimestamp(overflowUpdate)` call in `getTS` with `OrderedSingleFlight.Do`,
so that concurrent overflow-triggered updates are coalesced into a single execution.
The ordered guarantee ensures each caller gets a result from an execution that began
after its own arrival, preventing stale-result issues.
### Affected Files
- `pkg/tso/tso.go`
- `pkg/tso/allocator.go`
Contributor guide
Assessment
This issue has not been assessed yet.