Add new milli::update:🆕:indexer::sharding module

This commit is contained in:
Louis Dureuil
2025-07-29 13:56:47 +02:00
parent 907055ed08
commit e62a807b60
2 changed files with 23 additions and 0 deletions

View File

@ -36,6 +36,7 @@ mod guess_primary_key;
mod partial_dump; mod partial_dump;
mod post_processing; mod post_processing;
pub mod settings_changes; pub mod settings_changes;
pub mod sharding;
mod update_by_function; mod update_by_function;
mod write; mod write;

View File

@ -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 <https://mariadb.com/bsl11>
use std::hash::{BuildHasher as _, BuildHasherDefault};
pub struct Shards {
pub own: Vec<String>,
pub others: Vec<String>,
}
impl Shards {
pub fn must_process(&self, docid: &str) -> bool {
let hasher = BuildHasherDefault::<twox_hash::XxHash3_64>::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)
}
}