From e62a807b600a56a45e3a88f2adc6f8313635b76d Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 29 Jul 2025 13:56:47 +0200 Subject: [PATCH] Add new `milli::update::new::indexer::sharding` module --- crates/milli/src/update/new/indexer/mod.rs | 1 + .../milli/src/update/new/indexer/sharding.rs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 crates/milli/src/update/new/indexer/sharding.rs 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) + } +}