mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-30 03:30:49 +00:00
The midpoint() algorithm to find a token between two tokens doesn't work correctly in case of wraparound. The code tried to handle this case, but did it wrong. So this patch fixes the midpoint() algorithm, and adds clearer comments about why the fixed algorithm is correct. This patch also modifies two midpoint() tests in partitioner_test, which were incorrect - they verified that midpoint() returns some expected values, but expected values were wrong! We also add to the test a more fundemental test of midpoint() correctness, which doesn't check the midpoint against a known value (which is easy to get wrong, like indeed happened); Rather we simply check that the midpoint is really inside the range (according to the token ordering operator). This simple test failed with the old implementation of midpoint() and passes with the new one. Signed-off-by: Nadav Har'El <nyh@scylladb.com>