mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
split the DocumentAdditionOrUpdate in two tasks; DocumentAddition and DocumentUpdate
This commit is contained in:
parent
b7c5b71a53
commit
803f2157af
@ -9,6 +9,9 @@ pub enum BatchKind {
|
|||||||
DocumentAddition {
|
DocumentAddition {
|
||||||
addition_ids: Vec<TaskId>,
|
addition_ids: Vec<TaskId>,
|
||||||
},
|
},
|
||||||
|
DocumentUpdate {
|
||||||
|
update_ids: Vec<TaskId>,
|
||||||
|
},
|
||||||
DocumentDeletion {
|
DocumentDeletion {
|
||||||
deletion_ids: Vec<TaskId>,
|
deletion_ids: Vec<TaskId>,
|
||||||
},
|
},
|
||||||
@ -20,6 +23,10 @@ pub enum BatchKind {
|
|||||||
settings_ids: Vec<TaskId>,
|
settings_ids: Vec<TaskId>,
|
||||||
addition_ids: Vec<TaskId>,
|
addition_ids: Vec<TaskId>,
|
||||||
},
|
},
|
||||||
|
SettingsAndDocumentUpdate {
|
||||||
|
settings_ids: Vec<TaskId>,
|
||||||
|
update_ids: Vec<TaskId>,
|
||||||
|
},
|
||||||
Settings {
|
Settings {
|
||||||
settings_ids: Vec<TaskId>,
|
settings_ids: Vec<TaskId>,
|
||||||
},
|
},
|
||||||
@ -50,12 +57,18 @@ impl BatchKind {
|
|||||||
Kind::IndexRename => (BatchKind::IndexRename { id: task_id }, true),
|
Kind::IndexRename => (BatchKind::IndexRename { id: task_id }, true),
|
||||||
Kind::IndexSwap => (BatchKind::IndexSwap { id: task_id }, true),
|
Kind::IndexSwap => (BatchKind::IndexSwap { id: task_id }, true),
|
||||||
Kind::DocumentClear => (BatchKind::DocumentClear { ids: vec![task_id] }, false),
|
Kind::DocumentClear => (BatchKind::DocumentClear { ids: vec![task_id] }, false),
|
||||||
Kind::DocumentAdditionOrUpdate => (
|
Kind::DocumentAddition => (
|
||||||
BatchKind::DocumentAddition {
|
BatchKind::DocumentAddition {
|
||||||
addition_ids: vec![task_id],
|
addition_ids: vec![task_id],
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
Kind::DocumentUpdate => (
|
||||||
|
BatchKind::DocumentUpdate {
|
||||||
|
update_ids: vec![task_id],
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
),
|
||||||
Kind::DocumentDeletion => (
|
Kind::DocumentDeletion => (
|
||||||
BatchKind::DocumentDeletion {
|
BatchKind::DocumentDeletion {
|
||||||
deletion_ids: vec![task_id],
|
deletion_ids: vec![task_id],
|
||||||
@ -87,6 +100,9 @@ impl BatchKind {
|
|||||||
| BatchKind::DocumentAddition {
|
| BatchKind::DocumentAddition {
|
||||||
addition_ids: mut ids,
|
addition_ids: mut ids,
|
||||||
}
|
}
|
||||||
|
| BatchKind::DocumentUpdate {
|
||||||
|
update_ids: mut ids,
|
||||||
|
}
|
||||||
| BatchKind::DocumentDeletion {
|
| BatchKind::DocumentDeletion {
|
||||||
deletion_ids: mut ids,
|
deletion_ids: mut ids,
|
||||||
}
|
}
|
||||||
@ -106,6 +122,10 @@ impl BatchKind {
|
|||||||
| BatchKind::SettingsAndDocumentAddition {
|
| BatchKind::SettingsAndDocumentAddition {
|
||||||
addition_ids: mut ids,
|
addition_ids: mut ids,
|
||||||
settings_ids: mut other,
|
settings_ids: mut other,
|
||||||
|
}
|
||||||
|
| BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
update_ids: mut ids,
|
||||||
|
settings_ids: mut other,
|
||||||
},
|
},
|
||||||
Kind::IndexDeletion,
|
Kind::IndexDeletion,
|
||||||
) => {
|
) => {
|
||||||
@ -123,34 +143,57 @@ impl BatchKind {
|
|||||||
}
|
}
|
||||||
(
|
(
|
||||||
this @ BatchKind::DocumentClear { .. },
|
this @ BatchKind::DocumentClear { .. },
|
||||||
Kind::DocumentAdditionOrUpdate | Kind::Settings,
|
Kind::DocumentAddition | Kind::DocumentUpdate | Kind::Settings,
|
||||||
) => ControlFlow::Break(this),
|
) => ControlFlow::Break(this),
|
||||||
(BatchKind::DocumentAddition { mut addition_ids }, Kind::DocumentClear) => {
|
(
|
||||||
addition_ids.push(id);
|
BatchKind::DocumentAddition {
|
||||||
ControlFlow::Continue(BatchKind::DocumentClear { ids: addition_ids })
|
addition_ids: mut ids,
|
||||||
|
}
|
||||||
|
| BatchKind::DocumentUpdate {
|
||||||
|
update_ids: mut ids,
|
||||||
|
},
|
||||||
|
Kind::DocumentClear,
|
||||||
|
) => {
|
||||||
|
ids.push(id);
|
||||||
|
ControlFlow::Continue(BatchKind::DocumentClear { ids })
|
||||||
}
|
}
|
||||||
|
|
||||||
(BatchKind::DocumentAddition { mut addition_ids }, Kind::DocumentAdditionOrUpdate) => {
|
// we can autobatch the same kind of document additions / updates
|
||||||
|
(BatchKind::DocumentAddition { mut addition_ids }, Kind::DocumentAddition) => {
|
||||||
addition_ids.push(id);
|
addition_ids.push(id);
|
||||||
ControlFlow::Continue(BatchKind::DocumentAddition { addition_ids })
|
ControlFlow::Continue(BatchKind::DocumentAddition { addition_ids })
|
||||||
}
|
}
|
||||||
(this @ BatchKind::DocumentAddition { .. }, Kind::DocumentDeletion) => {
|
(BatchKind::DocumentUpdate { mut update_ids }, Kind::DocumentUpdate) => {
|
||||||
ControlFlow::Break(this)
|
update_ids.push(id);
|
||||||
|
ControlFlow::Continue(BatchKind::DocumentUpdate { update_ids })
|
||||||
}
|
}
|
||||||
|
// but we can't autobatch documents if it's not the same kind
|
||||||
|
// this match branch MUST be AFTER the previous one
|
||||||
|
(
|
||||||
|
this @ BatchKind::DocumentAddition { .. } | this @ BatchKind::DocumentUpdate { .. },
|
||||||
|
Kind::DocumentDeletion | Kind::DocumentAddition | Kind::DocumentUpdate,
|
||||||
|
) => ControlFlow::Break(this),
|
||||||
(BatchKind::DocumentAddition { addition_ids }, Kind::Settings) => {
|
(BatchKind::DocumentAddition { addition_ids }, Kind::Settings) => {
|
||||||
ControlFlow::Continue(BatchKind::SettingsAndDocumentAddition {
|
ControlFlow::Continue(BatchKind::SettingsAndDocumentAddition {
|
||||||
settings_ids: vec![id],
|
settings_ids: vec![id],
|
||||||
addition_ids,
|
addition_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
(BatchKind::DocumentUpdate { update_ids }, Kind::Settings) => {
|
||||||
|
ControlFlow::Continue(BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
settings_ids: vec![id],
|
||||||
|
update_ids,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
(BatchKind::DocumentDeletion { mut deletion_ids }, Kind::DocumentClear) => {
|
(BatchKind::DocumentDeletion { mut deletion_ids }, Kind::DocumentClear) => {
|
||||||
deletion_ids.push(id);
|
deletion_ids.push(id);
|
||||||
ControlFlow::Continue(BatchKind::DocumentClear { ids: deletion_ids })
|
ControlFlow::Continue(BatchKind::DocumentClear { ids: deletion_ids })
|
||||||
}
|
}
|
||||||
(this @ BatchKind::DocumentDeletion { .. }, Kind::DocumentAdditionOrUpdate) => {
|
(
|
||||||
ControlFlow::Break(this)
|
this @ BatchKind::DocumentDeletion { .. },
|
||||||
}
|
Kind::DocumentAddition | Kind::DocumentUpdate,
|
||||||
|
) => ControlFlow::Break(this),
|
||||||
(BatchKind::DocumentDeletion { mut deletion_ids }, Kind::DocumentDeletion) => {
|
(BatchKind::DocumentDeletion { mut deletion_ids }, Kind::DocumentDeletion) => {
|
||||||
deletion_ids.push(id);
|
deletion_ids.push(id);
|
||||||
ControlFlow::Continue(BatchKind::DocumentDeletion { deletion_ids })
|
ControlFlow::Continue(BatchKind::DocumentDeletion { deletion_ids })
|
||||||
@ -163,10 +206,10 @@ impl BatchKind {
|
|||||||
other: vec![id],
|
other: vec![id],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(this @ BatchKind::Settings { .. }, Kind::DocumentAdditionOrUpdate) => {
|
(
|
||||||
ControlFlow::Break(this)
|
this @ BatchKind::Settings { .. },
|
||||||
}
|
Kind::DocumentAddition | Kind::DocumentUpdate | Kind::DocumentDeletion,
|
||||||
(this @ BatchKind::Settings { .. }, Kind::DocumentDeletion) => ControlFlow::Break(this),
|
) => ControlFlow::Break(this),
|
||||||
(BatchKind::Settings { mut settings_ids }, Kind::Settings) => {
|
(BatchKind::Settings { mut settings_ids }, Kind::Settings) => {
|
||||||
settings_ids.push(id);
|
settings_ids.push(id);
|
||||||
ControlFlow::Continue(BatchKind::Settings { settings_ids })
|
ControlFlow::Continue(BatchKind::Settings { settings_ids })
|
||||||
@ -185,9 +228,10 @@ impl BatchKind {
|
|||||||
settings_ids,
|
settings_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(this @ BatchKind::ClearAndSettings { .. }, Kind::DocumentAdditionOrUpdate) => {
|
(
|
||||||
ControlFlow::Break(this)
|
this @ BatchKind::ClearAndSettings { .. },
|
||||||
}
|
Kind::DocumentAddition | Kind::DocumentUpdate,
|
||||||
|
) => ControlFlow::Break(this),
|
||||||
(
|
(
|
||||||
BatchKind::ClearAndSettings {
|
BatchKind::ClearAndSettings {
|
||||||
mut other,
|
mut other,
|
||||||
@ -217,23 +261,29 @@ impl BatchKind {
|
|||||||
(
|
(
|
||||||
BatchKind::SettingsAndDocumentAddition {
|
BatchKind::SettingsAndDocumentAddition {
|
||||||
settings_ids,
|
settings_ids,
|
||||||
mut addition_ids,
|
addition_ids: mut other,
|
||||||
|
}
|
||||||
|
| BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
settings_ids,
|
||||||
|
update_ids: mut other,
|
||||||
},
|
},
|
||||||
Kind::DocumentClear,
|
Kind::DocumentClear,
|
||||||
) => {
|
) => {
|
||||||
addition_ids.push(id);
|
other.push(id);
|
||||||
|
|
||||||
ControlFlow::Continue(BatchKind::ClearAndSettings {
|
ControlFlow::Continue(BatchKind::ClearAndSettings {
|
||||||
settings_ids,
|
settings_ids,
|
||||||
other: addition_ids,
|
other,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we can batch the settings with a kind of document operation with the same kind of document operation
|
||||||
(
|
(
|
||||||
BatchKind::SettingsAndDocumentAddition {
|
BatchKind::SettingsAndDocumentAddition {
|
||||||
mut addition_ids,
|
mut addition_ids,
|
||||||
settings_ids,
|
settings_ids,
|
||||||
},
|
},
|
||||||
Kind::DocumentAdditionOrUpdate,
|
Kind::DocumentAddition,
|
||||||
) => {
|
) => {
|
||||||
addition_ids.push(id);
|
addition_ids.push(id);
|
||||||
ControlFlow::Continue(BatchKind::SettingsAndDocumentAddition {
|
ControlFlow::Continue(BatchKind::SettingsAndDocumentAddition {
|
||||||
@ -241,9 +291,26 @@ impl BatchKind {
|
|||||||
settings_ids,
|
settings_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(this @ BatchKind::SettingsAndDocumentAddition { .. }, Kind::DocumentDeletion) => {
|
(
|
||||||
ControlFlow::Break(this)
|
BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
mut update_ids,
|
||||||
|
settings_ids,
|
||||||
|
},
|
||||||
|
Kind::DocumentUpdate,
|
||||||
|
) => {
|
||||||
|
update_ids.push(id);
|
||||||
|
ControlFlow::Continue(BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
update_ids,
|
||||||
|
settings_ids,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
// But we can't batch a settings and a doc op with another doc op
|
||||||
|
// this MUST be AFTER the two previous branch
|
||||||
|
(
|
||||||
|
this @ BatchKind::SettingsAndDocumentAddition { .. }
|
||||||
|
| this @ BatchKind::SettingsAndDocumentUpdate { .. },
|
||||||
|
Kind::DocumentDeletion | Kind::DocumentAddition | Kind::DocumentUpdate,
|
||||||
|
) => ControlFlow::Break(this),
|
||||||
(
|
(
|
||||||
BatchKind::SettingsAndDocumentAddition {
|
BatchKind::SettingsAndDocumentAddition {
|
||||||
mut settings_ids,
|
mut settings_ids,
|
||||||
@ -257,6 +324,19 @@ impl BatchKind {
|
|||||||
addition_ids,
|
addition_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
(
|
||||||
|
BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
mut settings_ids,
|
||||||
|
update_ids,
|
||||||
|
},
|
||||||
|
Kind::Settings,
|
||||||
|
) => {
|
||||||
|
settings_ids.push(id);
|
||||||
|
ControlFlow::Continue(BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
settings_ids,
|
||||||
|
update_ids,
|
||||||
|
})
|
||||||
|
}
|
||||||
(_, Kind::CancelTask | Kind::DumpExport | Kind::Snapshot) => unreachable!(),
|
(_, Kind::CancelTask | Kind::DumpExport | Kind::Snapshot) => unreachable!(),
|
||||||
(
|
(
|
||||||
BatchKind::IndexCreation { .. }
|
BatchKind::IndexCreation { .. }
|
||||||
|
@ -45,6 +45,7 @@ impl IndexScheduler {
|
|||||||
match batch {
|
match batch {
|
||||||
BatchKind::DocumentClear { ids } => todo!(),
|
BatchKind::DocumentClear { ids } => todo!(),
|
||||||
BatchKind::DocumentAddition { addition_ids } => todo!(),
|
BatchKind::DocumentAddition { addition_ids } => todo!(),
|
||||||
|
BatchKind::DocumentUpdate { update_ids } => todo!(),
|
||||||
BatchKind::DocumentDeletion { deletion_ids } => todo!(),
|
BatchKind::DocumentDeletion { deletion_ids } => todo!(),
|
||||||
BatchKind::ClearAndSettings {
|
BatchKind::ClearAndSettings {
|
||||||
other,
|
other,
|
||||||
@ -74,17 +75,13 @@ impl IndexScheduler {
|
|||||||
.collect::<Result<Vec<_>>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
let primary_key = match &document_addition_tasks[0].kind {
|
let primary_key = match &document_addition_tasks[0].kind {
|
||||||
KindWithContent::DocumentAdditionOrUpdate { primary_key, .. } => {
|
KindWithContent::DocumentAddition { primary_key, .. } => primary_key.clone(),
|
||||||
primary_key.clone()
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let content_files = document_addition_tasks
|
let content_files = document_addition_tasks
|
||||||
.iter()
|
.iter()
|
||||||
.map(|task| match task.kind {
|
.map(|task| match task.kind {
|
||||||
KindWithContent::DocumentAdditionOrUpdate { content_file, .. } => {
|
KindWithContent::DocumentAddition { content_file, .. } => content_file,
|
||||||
content_file
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -106,6 +103,10 @@ impl IndexScheduler {
|
|||||||
settings_tasks,
|
settings_tasks,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
BatchKind::SettingsAndDocumentUpdate {
|
||||||
|
update_ids,
|
||||||
|
settings_ids,
|
||||||
|
} => todo!(),
|
||||||
BatchKind::Settings { settings_ids } => todo!(),
|
BatchKind::Settings { settings_ids } => todo!(),
|
||||||
BatchKind::IndexCreation { id } => todo!(),
|
BatchKind::IndexCreation { id } => todo!(),
|
||||||
BatchKind::IndexDeletion { ids } => todo!(),
|
BatchKind::IndexDeletion { ids } => todo!(),
|
||||||
|
@ -56,9 +56,15 @@ impl Task {
|
|||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum KindWithContent {
|
pub enum KindWithContent {
|
||||||
DocumentAdditionOrUpdate {
|
DocumentAddition {
|
||||||
|
index_uid: String,
|
||||||
|
primary_key: Option<String>,
|
||||||
|
content_file: Uuid,
|
||||||
|
documents_count: usize,
|
||||||
|
allow_index_creation: bool,
|
||||||
|
},
|
||||||
|
DocumentUpdate {
|
||||||
index_uid: String,
|
index_uid: String,
|
||||||
merge_strategy: IndexDocumentsMethod,
|
|
||||||
primary_key: Option<String>,
|
primary_key: Option<String>,
|
||||||
content_file: Uuid,
|
content_file: Uuid,
|
||||||
documents_count: usize,
|
documents_count: usize,
|
||||||
@ -108,7 +114,8 @@ pub enum KindWithContent {
|
|||||||
impl KindWithContent {
|
impl KindWithContent {
|
||||||
pub fn as_kind(&self) -> Kind {
|
pub fn as_kind(&self) -> Kind {
|
||||||
match self {
|
match self {
|
||||||
KindWithContent::DocumentAdditionOrUpdate { .. } => Kind::DocumentAdditionOrUpdate,
|
KindWithContent::DocumentAddition { .. } => Kind::DocumentAddition,
|
||||||
|
KindWithContent::DocumentUpdate { .. } => Kind::DocumentUpdate,
|
||||||
KindWithContent::DocumentDeletion { .. } => Kind::DocumentDeletion,
|
KindWithContent::DocumentDeletion { .. } => Kind::DocumentDeletion,
|
||||||
KindWithContent::DocumentClear { .. } => Kind::DocumentClear,
|
KindWithContent::DocumentClear { .. } => Kind::DocumentClear,
|
||||||
KindWithContent::Settings { .. } => Kind::Settings,
|
KindWithContent::Settings { .. } => Kind::Settings,
|
||||||
@ -127,7 +134,7 @@ impl KindWithContent {
|
|||||||
use KindWithContent::*;
|
use KindWithContent::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
DocumentAdditionOrUpdate { .. } => {
|
DocumentAddition { .. } | DocumentUpdate { .. } => {
|
||||||
// TODO: TAMO: persist the file
|
// TODO: TAMO: persist the file
|
||||||
// content_file.persist();
|
// content_file.persist();
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -150,13 +157,12 @@ impl KindWithContent {
|
|||||||
use KindWithContent::*;
|
use KindWithContent::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
DocumentAdditionOrUpdate { .. } => {
|
DocumentAddition { .. } | DocumentUpdate { .. } => {
|
||||||
// TODO: TAMO: delete the file
|
// TODO: TAMO: delete the file
|
||||||
// content_file.delete();
|
// content_file.delete();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
DocumentAdditionOrUpdate { .. }
|
IndexCreation { .. }
|
||||||
| IndexCreation { .. }
|
|
||||||
| DocumentDeletion { .. }
|
| DocumentDeletion { .. }
|
||||||
| DocumentClear { .. }
|
| DocumentClear { .. }
|
||||||
| Settings { .. }
|
| Settings { .. }
|
||||||
@ -175,7 +181,8 @@ impl KindWithContent {
|
|||||||
|
|
||||||
match self {
|
match self {
|
||||||
DumpExport { .. } | Snapshot | CancelTask { .. } => None,
|
DumpExport { .. } | Snapshot | CancelTask { .. } => None,
|
||||||
DocumentAdditionOrUpdate { index_uid, .. }
|
DocumentAddition { index_uid, .. }
|
||||||
|
| DocumentUpdate { index_uid, .. }
|
||||||
| DocumentDeletion { index_uid, .. }
|
| DocumentDeletion { index_uid, .. }
|
||||||
| DocumentClear { index_uid }
|
| DocumentClear { index_uid }
|
||||||
| Settings { index_uid, .. }
|
| Settings { index_uid, .. }
|
||||||
@ -194,7 +201,8 @@ impl KindWithContent {
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum Kind {
|
pub enum Kind {
|
||||||
DocumentAdditionOrUpdate,
|
DocumentAddition,
|
||||||
|
DocumentUpdate,
|
||||||
DocumentDeletion,
|
DocumentDeletion,
|
||||||
DocumentClear,
|
DocumentClear,
|
||||||
Settings,
|
Settings,
|
||||||
|
Loading…
Reference in New Issue
Block a user