mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
Move index swap error handling from meilisearch-http to index-scheduler
And make index_not_found error asynchronous, since we can't know whether the index will exist by the time the index swap task is processed. Improve the index-swap test to verify that future tasks are not swapped and to test the new error messages that were introduced.
This commit is contained in:
parent
b44cc62320
commit
78ffa00f98
11 changed files with 305 additions and 63 deletions
|
@ -1,5 +1,6 @@
|
|||
//! Utility functions on the DBs. Mainly getter and setters.
|
||||
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
use std::ops::Bound;
|
||||
|
||||
use meilisearch_types::heed::types::{DecodeIgnore, OwnedType};
|
||||
|
@ -296,6 +297,33 @@ pub(crate) fn filter_out_references_to_newer_tasks(task: &mut Task) {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn check_index_swap_validity(task: &Task) -> Result<()> {
|
||||
let swaps =
|
||||
if let KindWithContent::IndexSwap { swaps } = &task.kind { swaps } else { return Ok(()) };
|
||||
let mut all_indexes = HashSet::new();
|
||||
let mut duplicate_indexes = BTreeSet::new();
|
||||
for IndexSwap { indexes: (lhs, rhs) } in swaps {
|
||||
for name in [lhs, rhs] {
|
||||
let is_new = all_indexes.insert(name);
|
||||
if !is_new {
|
||||
duplicate_indexes.insert(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !duplicate_indexes.is_empty() {
|
||||
if duplicate_indexes.len() == 1 {
|
||||
return Err(Error::SwapDuplicateIndexFound(
|
||||
duplicate_indexes.into_iter().next().unwrap().clone(),
|
||||
));
|
||||
} else {
|
||||
return Err(Error::SwapDuplicateIndexesFound(
|
||||
duplicate_indexes.into_iter().cloned().collect(),
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl IndexScheduler {
|
||||
/// Asserts that the index scheduler's content is internally consistent.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue