pub struct DistributedRouter<F: RecFamily> { /* private fields */ }Expand description
Routes records to shards exactly as a ClickHouse Distributed table
with sharding expression xxHash64(<key column>) would (see the
module docs for the algorithm and the ordering contract).
Construct via ClickHouseSink::router
so weights come from the validated config and cannot disagree with the
endpoint topology; DistributedRouter::new is the programmatic
escape hatch. Cloning is free (a fn pointer and a shared weights
table) — the terminal stage clones one router per pipeline thread.
Implementations§
Source§impl<F: RecFamily> DistributedRouter<F>
impl<F: RecFamily> DistributedRouter<F>
Sourcepub fn new(
extract: KeyExtractor<F>,
weights: &[u32],
) -> Result<Self, ConfigError>
pub fn new( extract: KeyExtractor<F>, weights: &[u32], ) -> Result<Self, ConfigError>
Programmatic constructor: weights in shard-config order, each
>= 1. Prefer ClickHouseSink::router,
which sources weights from the validated YAML.
Sourcepub fn hash_key(key: ShardKey<'_>) -> u64
pub fn hash_key(key: ShardKey<'_>) -> u64
Hash a key exactly as ClickHouse’s xxHash64(col): canonical XXH64,
seed 0, over the key’s canonical bytes (strings as UTF-8, integers
as little-endian fixed-width bytes).
Sourcepub fn shard_for_hash(&self, hash: u64) -> usize
pub fn shard_for_hash(&self, hash: u64) -> usize
Weight-interval selection for a precomputed hash: hash % total
mapped onto consecutive half-open intervals in config order.
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
The shard count this router was constructed for.