cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.11k stars 3.81k forks source link

kvserver: simplify replicasByKey handling #74384

Closed tbg closed 11 months ago

tbg commented 2 years ago

Is your feature request related to a problem? Please describe.

In https://github.com/cockroachdb/cockroach/issues/73721 we found a bug in our replica handling that could lead to data corruption. The basic problem is that the Store maintains a mapping of keyspace to Replica/Placeholder but code interacts very directly with it and it's easy to mess it up.

In addition to this, (*Replica).Desc() provides the key bounds of the replica object within the btree, which is deadlock prone (and also means that (*Replica).setDescLocked has an affect on the btree. This is all fairly cryptic and it would likely be better not to require a mutex when looking up a Replica from the tree, and to make any bounds adjustments explicit.

Describe the solution you'd like

Mediate all mutations to the Store's mapping (including handling of uninitialized Replicas) through an API that enforces that Replica insertion or bounds changes go through a ReplicaPlaceholder. In particular,

Describe alternatives you've considered

Additional context

Jira issue: CRDB-12057

github-actions[bot] commented 11 months ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!