cockroachdb / cockroachdb/cockroach

kvserver/rangefeed: race-build iterator-recreation probability in CatchUpScan is loop-invariant

Open Beginner friendly
#172,426 1 comment 0 reactions 0 assignees View on GitHub
A-kv-rangefeed A-testing branch-master C-bug O-agent P-3 T-kv
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

Under race builds, `CatchUpScan` intends to recreate its iterator with ~25% probability at each new-key decision point. But the hash input is the address of the local `iter` variable ([catchup_scan.go#L271](https://github.com/cockroachdb/cockroach/blob/a7e117882b4356096b3a8ea26046baa7e5d53fce/pkg/kv/kvserver/rangefeed/catchup_scan.go#L271)), which is constant for the entire `CatchUpScan` call — it does not change when `iter` is reassigned after recreation. The result: roughly 25% of scans force recreation at *every* new key and 75% never force it, instead of an independent 25% chance per decision.

Test-coverage distribution skew only; no production impact (the hash path is gated on `util.RaceEnabled`).

**Suggested fix**

Mix in per-decision state, e.g. a counter incremented at each decision point, so consecutive decisions within one scan hash differently.

**Additional context**

Found during an agent-assisted correctness audit of the rangefeed subsystem. Code link is pinned to master @ a7e1178.

Jira issue: CRDB-65662

Contributor guide

Open the contributing guide

Research direction

Start in pkg/kv/kvserver/rangefeed/catchup_scan.go at CatchUpScan and the race-build iterator recreation decision around line 271. Verify how the hash input behaves across successive new-key decisions, then update the decision state so recreation probability is independent per decision and confirm the race-build coverage distribution is no longer scan-wide.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.