diff --git a/crates/milli/src/update/new/indexer/mod.rs b/crates/milli/src/update/new/indexer/mod.rs index a6ba3a919..b24081c02 100644 --- a/crates/milli/src/update/new/indexer/mod.rs +++ b/crates/milli/src/update/new/indexer/mod.rs @@ -36,6 +36,7 @@ mod guess_primary_key; mod partial_dump; mod post_processing; pub mod settings_changes; +pub mod sharding; mod update_by_function; mod write; diff --git a/crates/milli/src/update/new/indexer/sharding.rs b/crates/milli/src/update/new/indexer/sharding.rs new file mode 100644 index 000000000..c0322f868 --- /dev/null +++ b/crates/milli/src/update/new/indexer/sharding.rs @@ -0,0 +1,22 @@ +// Copyright © 2025 Meilisearch Some Rights Reserved +// This file is part of Meilisearch Enterprise Edition (EE). +// Use of this source code is governed by the Business Source License 1.1, +// as found in the LICENSE-EE file or at + +use std::hash::{BuildHasher as _, BuildHasherDefault}; + +pub struct Shards { + pub own: Vec, + pub others: Vec, +} + +impl Shards { + pub fn must_process(&self, docid: &str) -> bool { + let hasher = BuildHasherDefault::::new(); + let to_hash = |shard: &String| hasher.hash_one((shard, docid)); + + let max_hash = self.others.iter().map(to_hash).max().unwrap_or_default(); + + self.own.iter().map(to_hash).any(|hash| hash > max_hash) + } +}