mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Fix a few index swap bugs.
1. Details of the indexSwap task 2. Query tasks with type=indexUid 3. Synchronous error message for multiple index not found
This commit is contained in:
parent
cf7b82497c
commit
9207ba68db
13 changed files with 75 additions and 35 deletions
|
@ -38,6 +38,10 @@ pub enum MeilisearchHttpError {
|
|||
.0.iter().map(|s| format!("`{}`", s)).collect::<Vec<_>>().join(", ")
|
||||
)]
|
||||
SwapDuplicateIndexesFound(Vec<String>),
|
||||
#[error("Two indexes must be given for each swap. The list `{:?}` contains {} indexes.",
|
||||
.0, .0.len()
|
||||
)]
|
||||
SwapIndexPayloadWrongLength(Vec<String>),
|
||||
#[error(transparent)]
|
||||
IndexUid(#[from] IndexUidFormatError),
|
||||
#[error(transparent)]
|
||||
|
@ -70,6 +74,7 @@ impl ErrorCode for MeilisearchHttpError {
|
|||
MeilisearchHttpError::IndexesNotFound(_) => Code::IndexNotFound,
|
||||
MeilisearchHttpError::SwapDuplicateIndexFound(_) => Code::DuplicateIndexFound,
|
||||
MeilisearchHttpError::SwapDuplicateIndexesFound(_) => Code::DuplicateIndexFound,
|
||||
MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::BadRequest,
|
||||
MeilisearchHttpError::IndexUid(e) => e.error_code(),
|
||||
MeilisearchHttpError::SerdeJson(_) => Code::Internal,
|
||||
MeilisearchHttpError::HeedError(_) => Code::Internal,
|
||||
|
|
|
@ -4,7 +4,7 @@ use actix_web::web::Data;
|
|||
use actix_web::{web, HttpResponse};
|
||||
use index_scheduler::IndexScheduler;
|
||||
use meilisearch_types::error::ResponseError;
|
||||
use meilisearch_types::tasks::KindWithContent;
|
||||
use meilisearch_types::tasks::{IndexSwap, KindWithContent};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::error::MeilisearchHttpError;
|
||||
|
@ -16,11 +16,10 @@ use crate::routes::tasks::TaskView;
|
|||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::resource("").route(web::post().to(SeqHandler(swap_indexes))));
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct SwapIndexesPayload {
|
||||
indexes: (String, String),
|
||||
indexes: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn swap_indexes(
|
||||
|
@ -33,23 +32,43 @@ pub async fn swap_indexes(
|
|||
let mut indexes_set = HashSet::<String>::default();
|
||||
let mut unknown_indexes = HashSet::new();
|
||||
let mut duplicate_indexes = HashSet::new();
|
||||
for SwapIndexesPayload { indexes: (lhs, rhs) } in params.into_inner().into_iter() {
|
||||
for SwapIndexesPayload { indexes } in params.into_inner().into_iter() {
|
||||
let (lhs, rhs) = match indexes.as_slice() {
|
||||
[lhs, rhs] => (lhs, rhs),
|
||||
_ => {
|
||||
return Err(MeilisearchHttpError::SwapIndexPayloadWrongLength(indexes).into());
|
||||
}
|
||||
};
|
||||
if !search_rules.is_index_authorized(&lhs) {
|
||||
unknown_indexes.insert(lhs.clone());
|
||||
}
|
||||
if !search_rules.is_index_authorized(&rhs) {
|
||||
unknown_indexes.insert(rhs.clone());
|
||||
}
|
||||
match index_scheduler.index(&lhs) {
|
||||
Ok(_) => (),
|
||||
Err(index_scheduler::Error::IndexNotFound(_)) => {
|
||||
unknown_indexes.insert(lhs.clone());
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
match index_scheduler.index(&rhs) {
|
||||
Ok(_) => (),
|
||||
Err(index_scheduler::Error::IndexNotFound(_)) => {
|
||||
unknown_indexes.insert(rhs.clone());
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
|
||||
swaps.push((lhs.clone(), 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);
|
||||
duplicate_indexes.insert(lhs.clone());
|
||||
}
|
||||
let is_unique_index_rhs = indexes_set.insert(rhs.clone());
|
||||
if !is_unique_index_rhs {
|
||||
duplicate_indexes.insert(rhs);
|
||||
duplicate_indexes.insert(rhs.clone());
|
||||
}
|
||||
}
|
||||
if !duplicate_indexes.is_empty() {
|
||||
|
|
|
@ -5,7 +5,9 @@ use meilisearch_types::error::ResponseError;
|
|||
use meilisearch_types::index_uid::IndexUid;
|
||||
use meilisearch_types::settings::{Settings, Unchecked};
|
||||
use meilisearch_types::star_or::StarOr;
|
||||
use meilisearch_types::tasks::{serialize_duration, Details, Kind, KindWithContent, Status, Task};
|
||||
use meilisearch_types::tasks::{
|
||||
serialize_duration, Details, IndexSwap, Kind, KindWithContent, Status, Task,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_cs::vec::CS;
|
||||
use serde_json::json;
|
||||
|
@ -103,7 +105,7 @@ pub struct DetailsView {
|
|||
#[serde(flatten)]
|
||||
pub settings: Option<Box<Settings<Unchecked>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub indexes: Option<Vec<(String, String)>>,
|
||||
pub swaps: Option<Vec<IndexSwap>>,
|
||||
}
|
||||
|
||||
impl From<Details> for DetailsView {
|
||||
|
@ -151,7 +153,7 @@ impl From<Details> for DetailsView {
|
|||
DetailsView { dump_uid: Some(dump_uid), ..DetailsView::default() }
|
||||
}
|
||||
Details::IndexSwap { swaps } => {
|
||||
DetailsView { indexes: Some(swaps), ..Default::default() }
|
||||
DetailsView { swaps: Some(swaps), ..Default::default() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue