Expand description
Token ring math: building and querying per-rack continuums.
rebuild_continuums walks the pool’s peer list,
pushes each peer’s tokens onto the owning rack’s continuum
array, then sorts the array per rack. The dispatcher then calls
dispatch to find the peer
that owns a key. The function uses a left-leaning binary search:
- if the search token falls outside the ring (less than the first token or strictly greater than the last), wrap to the first continuum point;
- otherwise, find the smallest continuum entry whose token is
greater than or equal to the search token (mirrors
(a, b]semantics from the reference).
Both behaviours are reproduced verbatim by dispatch below.
§Examples
use dynomite::cluster::vnode::dispatch;
use dynomite::cluster::datacenter::{Continuum, Rack};
use dynomite::hashkit::DynToken;
let mut r = Rack::new("r".into(), "d".into());
r.add_peer_tokens(0, &[DynToken::from_u32(10)]);
r.add_peer_tokens(1, &[DynToken::from_u32(20)]);
r.add_peer_tokens(2, &[DynToken::from_u32(30)]);
r.sort_continuums();
assert_eq!(dispatch(r.continuums(), &DynToken::from_u32(15)), Some(1));
assert_eq!(dispatch(r.continuums(), &DynToken::from_u32(35)), Some(0));Structs§
- Peer
Tokens - Per-peer token-list shape consumed by the rebuild pass.
Functions§
- dispatch
- Find the peer that owns
tokenon the continuum. - rebuild_
continuums - Walk a list of
PeerTokensand append continuum entries to the matching rack insidedcs.