cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

rac2: [dnm] implement handle raft event

Open kvoli opened this issue 1 year ago • 1 comments

This commit implements HandleRaftEvent on the RangeController. When HandleRaftEvent is called by the Processor on the leader, the RangeController will perform local replica state management for the range and potentially return tokens if admitted has advanced. Additionally, any entries will subject to admission control will have corresponding tokens deducted and tracked.

Resolves: #129668 Release note: None

kvoli avatar Aug 27 '24 21:08 kvoli

This change is Reviewable

cockroach-teamcity avatar Aug 27 '24 21:08 cockroach-teamcity

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] avatar Aug 29 '24 16:08 blathers-crl[bot]

TYFTR!

bors r=sumeerbhola

kvoli avatar Aug 29 '24 17:08 kvoli

I'm confused. rangeController is relying on external synchronization (raftMu) for calls to itself (other than the WaitForEval path), which is why it doesn't have a mutex for its replicaMap. Any change to connectedState for a replicaSendStream happens in the context of this external synchronization, and AFAIK, all reads of connectedState too. That is, we call updateVoterSets while holding raftMu. Did I miss something? In the prototype there was at least one path that did not hold raftMu, specifically TokenAvailableNotification.Notify, so replicaSendStream did need its own mutex.

sumeerbhola avatar Aug 29 '24 18:08 sumeerbhola

I'm confused. rangeController is relying on external synchronization (raftMu) for calls to itself (other than the WaitForEval path), which is why it doesn't have a mutex for its replicaMap.

My mistake, this was incorrect:

[...] but updateVoterSets reads the connectedState which can be written without holding the RangeController.mu This mu synchronizes this access. It could also be an atomic for now but we will need the mu later.

You're right, updateVoterSets is only called while holding raftMu, the synchronization on the replica send stream here is premature. I was confusing something.

kvoli avatar Aug 29 '24 22:08 kvoli