mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
Implement TaskDeletion in the index scheduler
This commit is contained in:
parent
ee352b6c7c
commit
05753c663f
4 changed files with 248 additions and 14 deletions
|
@ -8,7 +8,7 @@ use std::{fmt::Write, path::PathBuf, str::FromStr};
|
|||
use time::{Duration, OffsetDateTime};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{Error, TaskId};
|
||||
use crate::{Error, Query, TaskId};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -170,6 +170,10 @@ pub enum KindWithContent {
|
|||
CancelTask {
|
||||
tasks: Vec<TaskId>,
|
||||
},
|
||||
DeleteTasks {
|
||||
query: String,
|
||||
tasks: Vec<TaskId>,
|
||||
},
|
||||
DumpExport {
|
||||
output: PathBuf,
|
||||
},
|
||||
|
@ -200,6 +204,7 @@ impl KindWithContent {
|
|||
KindWithContent::IndexUpdate { .. } => Kind::IndexUpdate,
|
||||
KindWithContent::IndexSwap { .. } => Kind::IndexSwap,
|
||||
KindWithContent::CancelTask { .. } => Kind::CancelTask,
|
||||
KindWithContent::DeleteTasks { .. } => Kind::DeleteTasks,
|
||||
KindWithContent::DumpExport { .. } => Kind::DumpExport,
|
||||
KindWithContent::Snapshot => Kind::Snapshot,
|
||||
}
|
||||
|
@ -222,6 +227,7 @@ impl KindWithContent {
|
|||
| IndexUpdate { .. }
|
||||
| IndexSwap { .. }
|
||||
| CancelTask { .. }
|
||||
| DeleteTasks { .. }
|
||||
| DumpExport { .. }
|
||||
| Snapshot => Ok(()), // There is nothing to persist for all these tasks
|
||||
}
|
||||
|
@ -244,6 +250,7 @@ impl KindWithContent {
|
|||
| IndexUpdate { .. }
|
||||
| IndexSwap { .. }
|
||||
| CancelTask { .. }
|
||||
| DeleteTasks { .. }
|
||||
| DumpExport { .. }
|
||||
| Snapshot => Ok(()), // There is no data associated with all these tasks
|
||||
}
|
||||
|
@ -253,7 +260,7 @@ impl KindWithContent {
|
|||
use KindWithContent::*;
|
||||
|
||||
match self {
|
||||
DumpExport { .. } | Snapshot | CancelTask { .. } => None,
|
||||
DumpExport { .. } | Snapshot | CancelTask { .. } | DeleteTasks { .. } => None,
|
||||
DocumentImport { index_uid, .. }
|
||||
| DocumentDeletion { index_uid, .. }
|
||||
| DocumentClear { index_uid }
|
||||
|
@ -299,6 +306,11 @@ impl KindWithContent {
|
|||
KindWithContent::CancelTask { .. } => {
|
||||
todo!()
|
||||
}
|
||||
KindWithContent::DeleteTasks { query, tasks } => Some(Details::DeleteTasks {
|
||||
matched_tasks: tasks.len(),
|
||||
deleted_tasks: None,
|
||||
original_query: query.clone(),
|
||||
}),
|
||||
KindWithContent::DumpExport { .. } => None,
|
||||
KindWithContent::Snapshot => None,
|
||||
}
|
||||
|
@ -322,6 +334,7 @@ pub enum Kind {
|
|||
IndexUpdate,
|
||||
IndexSwap,
|
||||
CancelTask,
|
||||
DeleteTasks,
|
||||
DumpExport,
|
||||
Snapshot,
|
||||
}
|
||||
|
@ -352,6 +365,7 @@ impl FromStr for Kind {
|
|||
"index_update" => Ok(Kind::IndexUpdate),
|
||||
"index_swap" => Ok(Kind::IndexSwap),
|
||||
"cancel_task" => Ok(Kind::CancelTask),
|
||||
"delete_tasks" => Ok(Kind::DeleteTasks),
|
||||
"dump_export" => Ok(Kind::DumpExport),
|
||||
"snapshot" => Ok(Kind::Snapshot),
|
||||
s => Err(Error::InvalidKind(s.to_string())),
|
||||
|
@ -384,6 +398,12 @@ pub enum Details {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
ClearAll { deleted_documents: Option<u64> },
|
||||
#[serde(rename_all = "camelCase")]
|
||||
DeleteTasks {
|
||||
matched_tasks: usize,
|
||||
deleted_tasks: Option<usize>,
|
||||
original_query: String,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Dump { dump_uid: String },
|
||||
}
|
||||
|
||||
|
@ -437,3 +457,25 @@ fn serialize_duration<S: Serializer>(
|
|||
None => serializer.serialize_none(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use milli::heed::{types::SerdeJson, BytesDecode, BytesEncode};
|
||||
|
||||
use crate::assert_smol_debug_snapshot;
|
||||
|
||||
use super::Details;
|
||||
|
||||
#[test]
|
||||
fn bad_deser() {
|
||||
let details = Details::DeleteTasks {
|
||||
matched_tasks: 1,
|
||||
deleted_tasks: None,
|
||||
original_query: "hello".to_owned(),
|
||||
};
|
||||
let serialised = SerdeJson::<Details>::bytes_encode(&details).unwrap();
|
||||
let deserialised = SerdeJson::<Details>::bytes_decode(&serialised).unwrap();
|
||||
assert_smol_debug_snapshot!(details, @r###"DeleteTasks { matched_tasks: 1, deleted_tasks: None, original_query: "hello" }"###);
|
||||
assert_smol_debug_snapshot!(deserialised, @"Settings { settings: Settings { displayed_attributes: NotSet, searchable_attributes: NotSet, filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, synonyms: NotSet, distinct_attribute: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, _kind: PhantomData } }");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue