Skip to main content

Module random_slicing

Module random_slicing 

Source
Expand description

Random-slicing distribution: a small, gap-free partition table over the 64-bit hash space.

The hash space is split into a contiguous run of intervals. Each interval is owned by exactly one claimant (a peer or peer-name in our terminology). Lookups are an O(log N) binary search over the interval table, where N is the claimant count.

Two construction-time invariants give the technique its name:

  1. The intervals are laid out end-to-end so their union is the entire ring. Whatever rounding remainder integer division leaves over is absorbed by the last interval, so no value of hash(key) can fail to map to a claimant.
  2. Adding or removing a claimant only re-slices its share. Keys outside the affected slice keep their assignment.

The structure is built once per rack at config-load / SIGHUP-reload time and thereafter consulted read-only by the dispatcher; see crate::cluster::dispatch.

§Examples

use dynomite::hashkit::random_slicing::RandomSlices;

let slices = RandomSlices::from_uniform(&["peer-a", "peer-b"]).unwrap();
// Either of the two claimants must own the lookup; the
// partition is gap-free by construction.
let owner = slices.claimant_for(0).unwrap();
assert!(owner == "peer-a" || owner == "peer-b");

Structs§

RandomSlices
Slice table indexed by u64 hash values.

Enums§

RandomSlicesError
Failure mode produced by the RandomSlices builders.