pub mod locator;
pub mod partitioner;
mod sharding;
pub use sharding::{InvalidShardAwarePortRange, Shard, ShardAwarePortRange, ShardCount, Sharder};
pub(crate) use sharding::{ShardInfo, ShardingError};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub struct Token {
value: i64,
}
impl Token {
#[inline]
pub fn new(value: i64) -> Self {
Self {
value: if value == i64::MIN { i64::MAX } else { value },
}
}
pub(crate) const INVALID: Self = Token { value: i64::MIN };
#[inline]
pub fn value(&self) -> i64 {
self.value
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum NodeLocationPreference {
Any,
Datacenter(String),
DatacenterAndRack(String, String),
}
impl NodeLocationPreference {
pub fn datacenter(&self) -> Option<&str> {
match self {
Self::Any => None,
Self::Datacenter(dc) | Self::DatacenterAndRack(dc, _) => Some(dc),
}
}
pub fn rack(&self) -> Option<&str> {
match self {
Self::Any | Self::Datacenter(_) => None,
Self::DatacenterAndRack(_, rack) => Some(rack),
}
}
}