diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 3066b3492..aa9847e23 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -6,7 +6,7 @@ use log::debug; use meilisearch_lib::index_controller::updates::status::{UpdateResult, UpdateStatus}; use serde::{Deserialize, Serialize}; -use meilisearch_lib::{MeiliSearch, RegisterUpdate}; +use meilisearch_lib::{MeiliSearch, Update}; use meilisearch_lib::index::{Settings, Unchecked}; use crate::error::ResponseError; @@ -52,7 +52,7 @@ impl From<&UpdateStatus> for UpdateType { fn from(other: &UpdateStatus) -> Self { use milli::update::IndexDocumentsMethod::*; match other.meta() { - RegisterUpdate::DocumentAddition{ method, .. } => { + Update::DocumentAddition{ method, .. } => { let number = match other { UpdateStatus::Processed(processed) => match processed.success { UpdateResult::DocumentsAddition(ref addition) => { @@ -69,11 +69,11 @@ impl From<&UpdateStatus> for UpdateType { _ => unreachable!(), } } - RegisterUpdate::Settings(settings) => UpdateType::Settings { + Update::Settings(settings) => UpdateType::Settings { settings: settings.clone(), }, - RegisterUpdate::ClearDocuments => UpdateType::ClearAll, - RegisterUpdate::DeleteDocuments(ids) => UpdateType::DocumentsDeletion { + Update::ClearDocuments => UpdateType::ClearAll, + Update::DeleteDocuments(ids) => UpdateType::DocumentsDeletion { number: Some(ids.len()), }, } diff --git a/meilisearch-lib/src/index/updates.rs b/meilisearch-lib/src/index/updates.rs index 44558fdae..b5035443a 100644 --- a/meilisearch-lib/src/index/updates.rs +++ b/meilisearch-lib/src/index/updates.rs @@ -8,7 +8,7 @@ use milli::update::{IndexDocumentsMethod, Setting, UpdateBuilder}; use serde::{Deserialize, Serialize, Serializer}; use uuid::Uuid; -use crate::RegisterUpdate; +use crate::Update; use crate::index_controller::updates::status::{Failed, Processed, Processing, UpdateResult}; use super::{Index, IndexMeta}; @@ -170,19 +170,19 @@ impl Index { let result = (|| { let mut txn = self.write_txn()?; let result = match update.meta() { - RegisterUpdate::DocumentAddition { primary_key, content_uuid, method } => { + Update::DocumentAddition { primary_key, content_uuid, method } => { self.update_documents(&mut txn, *method, *content_uuid, update_builder, primary_key.as_deref()) } - RegisterUpdate::Settings(settings) => { + Update::Settings(settings) => { let settings = settings.clone().check(); self.update_settings(&mut txn, &settings, update_builder) }, - RegisterUpdate::ClearDocuments => { + Update::ClearDocuments => { let builder = update_builder.clear_documents(&mut txn, self); let _count = builder.execute()?; Ok(UpdateResult::Other) }, - RegisterUpdate::DeleteDocuments(ids) => { + Update::DeleteDocuments(ids) => { let mut builder = update_builder.delete_documents(&mut txn, self)?; // We ignore unexisting document ids diff --git a/meilisearch-lib/src/index_controller/index_resolver/mod.rs b/meilisearch-lib/src/index_controller/index_resolver/mod.rs index d41c37ac6..f04b3f42b 100644 --- a/meilisearch-lib/src/index_controller/index_resolver/mod.rs +++ b/meilisearch-lib/src/index_controller/index_resolver/mod.rs @@ -36,7 +36,7 @@ impl IndexResolver { let indexes_path = src.as_ref().join("indexes"); let indexes = indexes_path.read_dir()?; - let update_handler = UpdateHandler::new(indexer_opts).unwrap(); + let update_handler = UpdateHandler::new(indexer_opts)?; for index in indexes { let index = index?; Index::load_dump(&index.path(), &dst, index_db_size, &update_handler)?; diff --git a/meilisearch-lib/src/index_controller/updates/mod.rs b/meilisearch-lib/src/index_controller/updates/mod.rs index 5296c03e5..3823f6b70 100644 --- a/meilisearch-lib/src/index_controller/updates/mod.rs +++ b/meilisearch-lib/src/index_controller/updates/mod.rs @@ -45,18 +45,6 @@ pub fn create_update_handler( Ok(sender) } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum RegisterUpdate { - DeleteDocuments(Vec), - DocumentAddition { - primary_key: Option, - method: IndexDocumentsMethod, - content_uuid: Uuid, - }, - Settings(Settings), - ClearDocuments, -} - /// A wrapper type to implement read on a `Stream>`. struct StreamReader { stream: S, @@ -209,15 +197,15 @@ impl UpdateLoop { }).await??; - RegisterUpdate::DocumentAddition { + store::Update::DocumentAddition { primary_key, method, content_uuid, } } - Update::Settings(settings) => RegisterUpdate::Settings(settings), - Update::ClearDocuments => RegisterUpdate::ClearDocuments, - Update::DeleteDocuments(ids) => RegisterUpdate::DeleteDocuments(ids), + Update::Settings(settings) => store::Update::Settings(settings), + Update::ClearDocuments => store::Update::ClearDocuments, + Update::DeleteDocuments(ids) => store::Update::DeleteDocuments(ids), }; let store = self.store.clone(); diff --git a/meilisearch-lib/src/index_controller/updates/status.rs b/meilisearch-lib/src/index_controller/updates/status.rs index 7716473ab..3108fe638 100644 --- a/meilisearch-lib/src/index_controller/updates/status.rs +++ b/meilisearch-lib/src/index_controller/updates/status.rs @@ -6,7 +6,7 @@ use meilisearch_error::{Code, ErrorCode}; use milli::update::{DocumentAdditionResult, IndexDocumentsMethod}; use serde::{Deserialize, Serialize}; -use crate::{RegisterUpdate, index::{Settings, Unchecked}}; +use crate::{Update, index::{Settings, Unchecked}}; #[derive(Debug, Clone, Serialize, Deserialize)] pub enum UpdateResult { @@ -34,12 +34,12 @@ pub enum UpdateMeta { #[serde(rename_all = "camelCase")] pub struct Enqueued { pub update_id: u64, - pub meta: RegisterUpdate, + pub meta: Update, pub enqueued_at: DateTime, } impl Enqueued { - pub fn new(meta: RegisterUpdate, update_id: u64) -> Self { + pub fn new(meta: Update, update_id: u64) -> Self { Self { enqueued_at: Utc::now(), meta, @@ -61,7 +61,7 @@ impl Enqueued { } } - pub fn meta(&self) -> &RegisterUpdate { + pub fn meta(&self) -> &Update { &self.meta } @@ -84,7 +84,7 @@ impl Processed { self.from.id() } - pub fn meta(&self) -> &RegisterUpdate { + pub fn meta(&self) -> &Update { self.from.meta() } } @@ -102,7 +102,7 @@ impl Processing { self.from.id() } - pub fn meta(&self) -> &RegisterUpdate { + pub fn meta(&self) -> &Update { self.from.meta() } @@ -139,7 +139,7 @@ impl Aborted { self.from.id() } - pub fn meta(&self) -> &RegisterUpdate { + pub fn meta(&self) -> &Update { self.from.meta() } } @@ -173,7 +173,7 @@ impl Failed { self.from.id() } - pub fn meta(&self) -> &RegisterUpdate { + pub fn meta(&self) -> &Update { self.from.meta() } } @@ -199,7 +199,7 @@ impl UpdateStatus { } } - pub fn meta(&self) -> &RegisterUpdate { + pub fn meta(&self) -> &Update { match self { UpdateStatus::Processing(u) => u.meta(), UpdateStatus::Enqueued(u) => u.meta(), diff --git a/meilisearch-lib/src/index_controller/updates/store/dump.rs b/meilisearch-lib/src/index_controller/updates/store/dump.rs index 68380a9d4..3356a54b9 100644 --- a/meilisearch-lib/src/index_controller/updates/store/dump.rs +++ b/meilisearch-lib/src/index_controller/updates/store/dump.rs @@ -11,7 +11,7 @@ use tempfile::{NamedTempFile, TempDir}; use uuid::Uuid; use super::{Result, State, UpdateStore}; -use crate::{RegisterUpdate, index::Index, index_controller::{update_file_store::UpdateFileStore, updates::status::{Enqueued, UpdateStatus}}}; +use crate::{Update, index::Index, index_controller::{update_file_store::UpdateFileStore, updates::status::{Enqueued, UpdateStatus}}}; #[derive(Serialize, Deserialize)] struct UpdateEntry { @@ -74,7 +74,7 @@ impl UpdateStore { let update = data.decode()?; if let Enqueued { - meta: RegisterUpdate::DocumentAddition { + meta: Update::DocumentAddition { content_uuid, .. }, .. } = update { diff --git a/meilisearch-lib/src/index_controller/updates/store/mod.rs b/meilisearch-lib/src/index_controller/updates/store/mod.rs index 21bfad61e..06577985c 100644 --- a/meilisearch-lib/src/index_controller/updates/store/mod.rs +++ b/meilisearch-lib/src/index_controller/updates/store/mod.rs @@ -26,7 +26,6 @@ use rayon::prelude::*; use codec::*; -use super::RegisterUpdate; use super::error::Result; use super::status::{Enqueued, Processing}; use crate::EnvSizer; @@ -37,6 +36,18 @@ use crate::index::Index; #[allow(clippy::upper_case_acronyms)] type BEU64 = U64; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Update { + DeleteDocuments(Vec), + DocumentAddition { + primary_key: Option, + method: IndexDocumentsMethod, + content_uuid: Uuid, + }, + Settings(Settings), + ClearDocuments, +} + #[derive(Debug)] pub struct UpdateStoreInfo { /// Size of the update store in bytes. @@ -242,7 +253,7 @@ impl UpdateStore { pub fn register_update( &self, index_uuid: Uuid, - update: RegisterUpdate, + update: Update, ) -> heed::Result { let mut txn = self.env.write_txn()?; let (global_id, update_id) = self.next_update_id(&mut txn, index_uuid)?; @@ -512,7 +523,7 @@ impl UpdateStore { let ((_, uuid, _), pending) = entry?; if uuids.contains(&uuid) { if let Enqueued { - meta: RegisterUpdate::DocumentAddition { + meta: Update::DocumentAddition { content_uuid, .. }, .. diff --git a/meilisearch-lib/src/lib.rs b/meilisearch-lib/src/lib.rs index 93fd2f094..776a17f0d 100644 --- a/meilisearch-lib/src/lib.rs +++ b/meilisearch-lib/src/lib.rs @@ -5,7 +5,7 @@ pub mod options; pub mod index; pub mod index_controller; -pub use index_controller::{IndexController as MeiliSearch, updates::RegisterUpdate}; +pub use index_controller::{IndexController as MeiliSearch, updates::store::Update}; mod compression; mod document_formats;