diff --git a/crates/miroir-core/src/anti_entropy.rs b/crates/miroir-core/src/anti_entropy.rs index 8713be4..b82a341 100644 --- a/crates/miroir-core/src/anti_entropy.rs +++ b/crates/miroir-core/src/anti_entropy.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use crate::migration::{MigrationConfig, MigrationCoordinator, MigrationError}; +use crate::migration::{MigrationConfig, MigrationError}; /// Anti-entropy configuration (plan ยง13.8). #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/miroir-core/src/lib.rs b/crates/miroir-core/src/lib.rs index 336af15..40cdae0 100644 --- a/crates/miroir-core/src/lib.rs +++ b/crates/miroir-core/src/lib.rs @@ -2,9 +2,12 @@ //! //! Provides routing, merging, and topology logic for the Miroir distributed search proxy. +pub mod anti_entropy; pub mod config; pub mod error; pub mod merger; +pub mod migration; +pub mod reshard; pub mod router; pub mod scatter; pub mod task; diff --git a/crates/miroir-core/src/router.rs b/crates/miroir-core/src/router.rs index 92b5459..37bbd10 100644 --- a/crates/miroir-core/src/router.rs +++ b/crates/miroir-core/src/router.rs @@ -1,8 +1,8 @@ //! Rendezvous hash-based routing and shard assignment. use crate::topology::{Group, NodeId, Topology}; -use twox_hash::XxHash64; use std::hash::{Hash, Hasher}; +use twox_hash::XxHash64; /// Compute a rendezvous score for a shard+node pair. /// @@ -23,14 +23,19 @@ pub fn assign_shard_in_group(shard_id: u32, group_nodes: &[NodeId], rf: usize) - .map(|n| (score(shard_id, n.as_str()), n)) .collect(); scored.sort_unstable_by(|a, b| b.0.cmp(&a.0)); - scored.into_iter().take(rf).map(|(_, n)| n.clone()).collect() + scored + .into_iter() + .take(rf) + .map(|(_, n)| n.clone()) + .collect() } /// All write targets for a document: the RF nodes in EACH replica group. pub fn write_targets(shard_id: u32, topology: &Topology) -> Vec { - topology.groups().flat_map(|group| { - assign_shard_in_group(shard_id, group.nodes(), topology.rf()) - }).collect() + topology + .groups() + .flat_map(|group| assign_shard_in_group(shard_id, group.nodes(), topology.rf())) + .collect() } /// Select the replica group for a query (round-robin by query counter). @@ -40,11 +45,15 @@ pub fn query_group(query_seq: u64, replica_groups: u32) -> u32 { /// The covering set for a search: one node per shard within the chosen group. pub fn covering_set(shard_count: u32, group: &Group, rf: usize, query_seq: u64) -> Vec { - (0..shard_count).map(|shard_id| { - let replicas = assign_shard_in_group(shard_id, group.nodes(), rf); - // rotate through replicas for intra-group load balancing - replicas[(query_seq as usize) % replicas.len()].clone() - }).collect::>().into_iter().collect() + (0..shard_count) + .map(|shard_id| { + let replicas = assign_shard_in_group(shard_id, group.nodes(), rf); + // rotate through replicas for intra-group load balancing + replicas[(query_seq as usize) % replicas.len()].clone() + }) + .collect::>() + .into_iter() + .collect() } /// Compute the shard ID for a document's primary key. diff --git a/crates/miroir-core/src/task.rs b/crates/miroir-core/src/task.rs index 59011a7..f62f177 100644 --- a/crates/miroir-core/src/task.rs +++ b/crates/miroir-core/src/task.rs @@ -17,7 +17,12 @@ pub trait TaskRegistry: Send + Sync { fn update_status(&self, miroir_id: &str, status: TaskStatus) -> Result<()>; /// Update node task status. - fn update_node_task(&self, miroir_id: &str, node_id: &str, node_status: NodeTaskStatus) -> Result<()>; + fn update_node_task( + &self, + miroir_id: &str, + node_id: &str, + node_status: NodeTaskStatus, + ) -> Result<()>; /// List tasks with optional filtering. fn list(&self, filter: TaskFilter) -> Result>; @@ -126,7 +131,12 @@ impl TaskRegistry for StubTaskRegistry { Ok(()) } - fn update_node_task(&self, _miroir_id: &str, _node_id: &str, _node_status: NodeTaskStatus) -> Result<()> { + fn update_node_task( + &self, + _miroir_id: &str, + _node_id: &str, + _node_status: NodeTaskStatus, + ) -> Result<()> { Ok(()) } diff --git a/crates/miroir-core/src/topology.rs b/crates/miroir-core/src/topology.rs index 4cc5cdd..c5cb886 100644 --- a/crates/miroir-core/src/topology.rs +++ b/crates/miroir-core/src/topology.rs @@ -143,12 +143,12 @@ impl Topology { /// Add a node to the topology. pub fn add_node(&mut self, node: Node) { let group_id = node.replica_group as usize; - + // Ensure group exists while self.groups.len() <= group_id { self.groups.push(Group::new(self.groups.len() as u32)); } - + self.groups[group_id].add_node(node.id.clone()); self.nodes.insert(node.id.clone(), node); }