Commit a9dfbe2c authored by Committed by Andrew Kimball
allocator: fix incorrect rebalance signal and target
This change fixes two bugs: - The first bug is related to the comparison of floating point numbers when considering to rebalance a range. The diversity score of two identical ranges (even the same range) may differ by a small amount. The fix is to consider candidates equal if their diversity score have very close values (within 1e-10). - The second bug has been introduced with https://github.com/cockroachdb/cockroach/pull/39157 and resulted in ignoring the newly added replica when determining what existing replica it should replace in Allocator.simulateRemoveTarget. As a result - when the first bug was triggering and unnecessary rebalancing was happening - the replica to be dropped was chosen at random (in the case where all existing replica are necessary). For example - let's say a range is constrained to have a replica in each of the regions A,B,C. We are trying to add a new replica in C. Evaluating what should be removed from the A,B,C may choose any one of them. Regardless of the choise, the constraint will be violated. If we however ask the same question for A,B,C(old),C(new) - the result will be C(old) as this will preserve the constraint (to have one replica in each region). Fixes #42715 Fixes https://github.com/cockroachlabs/support/issues/348 Release note (bug fix): the allocator now considers stores with very close diversity scores equal (all other things being the same) and doesn't attempt to rebalance. Release note (bug fix): the allocator considers the new store being added when looking for target in case of rebalance.
Showing with 43 additions and 21 deletions