cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

kvserver: [dnm] relocate replica when scattering range with 1 replica

Open kvoli opened this issue 9 months ago • 2 comments

When a range with exactly 1 replica is scattered it could only add an additional replica to a valid store, without also removing the existing replica. This left ranges post-scatter over-replicated and not random -- as only the newly added replica would be randomly placed. The cause is the replicate queue falling back to adding a replica, instead of both adding and removing a replica in an atomic operation.

Relocate the range, instead of processing via the replicate queue. The relocation carries out the multi-step add+remove. A remaining issue is that the existing replica will currently never be selected as a target when having an existing high replica count.

Distribution without patch:

  store_id | replica_count | replica_distribution | lease_count | lease_distribution
-----------+---------------+----------------------+-------------+---------------------
         1 |          1001 | ##########           |         500 | ##########
         5 |           291 | ###                  |         147 | ###
         4 |           275 | ###                  |         137 | ###
         3 |           229 | ###                  |         118 | ###
         2 |           206 | ###                  |          99 | ##

Distribution with patch:

  store_id | replica_count | replica_distribution | lease_count | lease_distribution
-----------+---------------+----------------------+-------------+---------------------
         2 |           326 | ##########           |         326 | ##########
         4 |           294 | ##########           |         294 | ##########
         3 |           193 | ######               |         193 | ######
         5 |           188 | ######               |         188 | ######

Resolves: #124171 Release note: None

kvoli avatar May 14 '24 22:05 kvoli

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

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

blathers-crl[bot] avatar May 14 '24 22:05 blathers-crl[bot]

This change is Reviewable

cockroach-teamcity avatar May 14 '24 22:05 cockroach-teamcity