tikv / tikv/pd

tso: use OrderedSingleFlight to reduce data race on logical overflow update

Open
#10,751 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.