Skip to main content

waratah_router/
lib.rs

1//! Waratah routing layer: Murmur3 consistent hashing and pattern → partition selection.
2//!
3//! Given an [`EncodedTriplePattern`], chooses a [`PartitionAxis`], an
4//! [`waratah_storage::IndexPermutation`], and a physical [`NodeId`] on that
5//! axis's virtual-node ring. Compute nodes keep a local [`RoutingTable`]
6//! (`NodeId` → `localhost:port` for the local-dev MVP).
7//!
8//! See `project_plan.md` → "Partitioning & Routing Layer (The Where)".
9
10#![deny(unused_must_use)]
11#![warn(missing_docs)]
12
13mod config;
14mod error;
15mod hash;
16mod ring;
17mod route;
18mod table;
19
20pub use config::{
21    ClusterConfig, ComputeSpec, DEFAULT_ADMIN_URL, DEFAULT_COMPUTE_ID, DEFAULT_RDF4J_URL,
22    RegistryNodeId,
23};
24pub use error::RouterError;
25pub use hash::{hash_term, murmur3_32};
26pub use ring::HashRing;
27pub use route::{
28    Route, RoutedNode, Router, RoutingSnapshot, routing_term, select_axis, select_target,
29};
30pub use table::RoutingTable;
31pub use waratah_storage::{EncodedTerm, EncodedTriplePattern, PartitionAxis};
32
33use std::fmt;
34
35/// Identifier of a physical partition node in the routing table.
36#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
37pub struct NodeId(String);
38
39impl NodeId {
40    /// Create a node id from any string-like value.
41    pub fn new(id: impl Into<String>) -> Self {
42        Self(id.into())
43    }
44
45    /// Borrow the id string.
46    pub fn as_str(&self) -> &str {
47        &self.0
48    }
49}
50
51impl fmt::Display for NodeId {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        f.write_str(&self.0)
54    }
55}
56
57impl From<&str> for NodeId {
58    fn from(value: &str) -> Self {
59        Self::new(value)
60    }
61}
62
63impl From<String> for NodeId {
64    fn from(value: String) -> Self {
65        Self::new(value)
66    }
67}
68
69impl AsRef<str> for NodeId {
70    fn as_ref(&self) -> &str {
71        self.as_str()
72    }
73}