mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 08:41:00 +00: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:
@ -1,5 +1,3 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use index_scheduler::IndexScheduler;
|
||||
@ -29,9 +27,6 @@ pub async fn swap_indexes(
|
||||
let search_rules = &index_scheduler.filters().search_rules;
|
||||
|
||||
let mut swaps = vec![];
|
||||
let mut indexes_set = BTreeSet::<String>::default();
|
||||
let mut unauthorized_indexes = BTreeSet::new();
|
||||
let mut duplicate_indexes = BTreeSet::new();
|
||||
for SwapIndexesPayload { indexes } in params.into_inner().into_iter() {
|
||||
let (lhs, rhs) = match indexes.as_slice() {
|
||||
[lhs, rhs] => (lhs, rhs),
|
||||
@ -39,34 +34,10 @@ pub async fn swap_indexes(
|
||||
return Err(MeilisearchHttpError::SwapIndexPayloadWrongLength(indexes).into());
|
||||
}
|
||||
};
|
||||
if !search_rules.is_index_authorized(lhs) {
|
||||
unauthorized_indexes.insert(lhs.clone());
|
||||
if !search_rules.is_index_authorized(lhs) || !search_rules.is_index_authorized(rhs) {
|
||||
return Err(AuthenticationError::InvalidToken.into());
|
||||
}
|
||||
if !search_rules.is_index_authorized(rhs) {
|
||||
unauthorized_indexes.insert(rhs.clone());
|
||||
}
|
||||
|
||||
swaps.push(IndexSwap { indexes: (lhs.clone(), rhs.clone()) });
|
||||
|
||||
let is_unique_index_lhs = indexes_set.insert(lhs.clone());
|
||||
if !is_unique_index_lhs {
|
||||
duplicate_indexes.insert(lhs.clone());
|
||||
}
|
||||
let is_unique_index_rhs = indexes_set.insert(rhs.clone());
|
||||
if !is_unique_index_rhs {
|
||||
duplicate_indexes.insert(rhs.clone());
|
||||
}
|
||||
}
|
||||
if !duplicate_indexes.is_empty() {
|
||||
let duplicate_indexes: Vec<_> = duplicate_indexes.into_iter().collect();
|
||||
if let [index] = duplicate_indexes.as_slice() {
|
||||
return Err(MeilisearchHttpError::SwapDuplicateIndexFound(index.clone()).into());
|
||||
} else {
|
||||
return Err(MeilisearchHttpError::SwapDuplicateIndexesFound(duplicate_indexes).into());
|
||||
}
|
||||
}
|
||||
if !unauthorized_indexes.is_empty() {
|
||||
return Err(AuthenticationError::InvalidToken.into());
|
||||
}
|
||||
|
||||
let task = KindWithContent::IndexSwap { swaps };
|
||||
|
Reference in New Issue
Block a user