2022-09-13 17:46:07 +08:00
|
|
|
use crate::{
|
|
|
|
autobatcher::BatchKind,
|
2022-09-14 22:16:53 +08:00
|
|
|
task::{Kind, KindWithContent, Status, Task},
|
2022-09-16 07:58:08 +08:00
|
|
|
Error, IndexScheduler, Result, TaskId,
|
2022-09-13 17:46:07 +08:00
|
|
|
};
|
2022-09-14 04:38:43 +08:00
|
|
|
use index::{Settings, Unchecked};
|
2022-09-13 17:46:07 +08:00
|
|
|
use milli::{
|
|
|
|
heed::{RoTxn, RwTxn},
|
|
|
|
update::IndexDocumentsMethod,
|
2022-09-16 22:31:16 +08:00
|
|
|
DocumentId,
|
2022-09-13 17:46:07 +08:00
|
|
|
};
|
2022-09-09 07:09:50 +08:00
|
|
|
use uuid::Uuid;
|
2022-09-07 06:10:14 +08:00
|
|
|
|
2022-09-08 02:08:07 +08:00
|
|
|
pub(crate) enum Batch {
|
2022-09-07 06:10:14 +08:00
|
|
|
Cancel(Task),
|
|
|
|
Snapshot(Vec<Task>),
|
|
|
|
Dump(Vec<Task>),
|
2022-09-13 17:46:07 +08:00
|
|
|
// IndexSpecific { index_uid: String, kind: BatchKind },
|
|
|
|
DocumentAddition {
|
|
|
|
index_uid: String,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
content_files: Vec<Uuid>,
|
|
|
|
tasks: Vec<Task>,
|
|
|
|
},
|
2022-09-16 22:31:16 +08:00
|
|
|
DocumentUpdate {
|
|
|
|
index_uid: String,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
content_files: Vec<Uuid>,
|
|
|
|
tasks: Vec<Task>,
|
|
|
|
},
|
|
|
|
DocumentDeletion {
|
|
|
|
index_uid: String,
|
|
|
|
documents: Vec<DocumentId>,
|
|
|
|
tasks: Vec<Task>,
|
|
|
|
},
|
|
|
|
DocumentClear {
|
|
|
|
index_uid: String,
|
|
|
|
tasks: Vec<Task>,
|
|
|
|
},
|
|
|
|
Settings {
|
|
|
|
index_uid: String,
|
|
|
|
settings: Vec<(bool, Settings<Unchecked>)>,
|
|
|
|
tasks: Vec<Task>,
|
|
|
|
},
|
|
|
|
DocumentClearAndSetting {
|
|
|
|
index_uid: String,
|
|
|
|
cleared_tasks: Vec<Task>,
|
|
|
|
|
|
|
|
settings: Vec<(bool, Settings<Unchecked>)>,
|
|
|
|
settings_tasks: Vec<Task>,
|
|
|
|
},
|
2022-09-13 17:46:07 +08:00
|
|
|
SettingsAndDocumentAddition {
|
|
|
|
index_uid: String,
|
|
|
|
|
|
|
|
primary_key: Option<String>,
|
|
|
|
content_files: Vec<Uuid>,
|
|
|
|
document_addition_tasks: Vec<Task>,
|
|
|
|
|
2022-09-16 22:31:16 +08:00
|
|
|
settings: Vec<(bool, Settings<Unchecked>)>,
|
|
|
|
settings_tasks: Vec<Task>,
|
|
|
|
},
|
|
|
|
SettingsAndDocumentUpdate {
|
|
|
|
index_uid: String,
|
|
|
|
|
|
|
|
primary_key: Option<String>,
|
|
|
|
content_files: Vec<Uuid>,
|
|
|
|
document_update_tasks: Vec<Task>,
|
|
|
|
|
|
|
|
settings: Vec<(bool, Settings<Unchecked>)>,
|
2022-09-13 17:46:07 +08:00
|
|
|
settings_tasks: Vec<Task>,
|
|
|
|
},
|
2022-09-17 03:24:49 +08:00
|
|
|
IndexCreation {
|
|
|
|
index_uid: String,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
task: Task,
|
|
|
|
},
|
|
|
|
IndexUpdate {
|
|
|
|
index_uid: String,
|
|
|
|
primary_key: Option<String>,
|
|
|
|
task: Task,
|
|
|
|
},
|
|
|
|
IndexDeletion {
|
|
|
|
index_uid: String,
|
|
|
|
tasks: Vec<Task>,
|
|
|
|
},
|
2022-09-09 07:09:50 +08:00
|
|
|
}
|
|
|
|
|
2022-09-16 07:58:08 +08:00
|
|
|
impl Batch {
|
|
|
|
pub fn ids(&self) -> Vec<TaskId> {
|
|
|
|
match self {
|
2022-09-17 03:24:49 +08:00
|
|
|
Batch::Cancel(task)
|
|
|
|
| Batch::IndexCreation { task, .. }
|
|
|
|
| Batch::IndexUpdate { task, .. } => vec![task.uid],
|
2022-09-16 22:31:16 +08:00
|
|
|
Batch::Snapshot(tasks)
|
|
|
|
| Batch::Dump(tasks)
|
|
|
|
| Batch::DocumentAddition { tasks, .. }
|
|
|
|
| Batch::DocumentUpdate { tasks, .. }
|
|
|
|
| Batch::DocumentDeletion { tasks, .. }
|
|
|
|
| Batch::Settings { tasks, .. }
|
2022-09-17 03:24:49 +08:00
|
|
|
| Batch::DocumentClear { tasks, .. }
|
|
|
|
| Batch::IndexDeletion { tasks, .. } => tasks.iter().map(|task| task.uid).collect(),
|
2022-09-16 07:58:08 +08:00
|
|
|
Batch::SettingsAndDocumentAddition {
|
2022-09-16 22:31:16 +08:00
|
|
|
document_addition_tasks: tasks,
|
|
|
|
settings_tasks: other,
|
|
|
|
..
|
|
|
|
}
|
|
|
|
| Batch::DocumentClearAndSetting {
|
|
|
|
cleared_tasks: tasks,
|
|
|
|
settings_tasks: other,
|
|
|
|
..
|
|
|
|
}
|
|
|
|
| Batch::SettingsAndDocumentUpdate {
|
|
|
|
document_update_tasks: tasks,
|
|
|
|
settings_tasks: other,
|
2022-09-16 07:58:08 +08:00
|
|
|
..
|
2022-09-16 22:31:16 +08:00
|
|
|
} => tasks.iter().chain(other).map(|task| task.uid).collect(),
|
2022-09-16 07:58:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-07 06:10:14 +08:00
|
|
|
impl IndexScheduler {
|
2022-09-13 17:46:07 +08:00
|
|
|
pub(crate) fn create_next_batch_index(
|
|
|
|
&self,
|
|
|
|
rtxn: &RoTxn,
|
|
|
|
index_uid: String,
|
|
|
|
batch: BatchKind,
|
|
|
|
) -> Result<Option<Batch>> {
|
|
|
|
match batch {
|
2022-09-16 22:31:16 +08:00
|
|
|
BatchKind::DocumentClear { ids } => Ok(Some(Batch::DocumentClear {
|
|
|
|
tasks: self.get_existing_tasks(rtxn, ids)?,
|
|
|
|
index_uid,
|
|
|
|
})),
|
|
|
|
BatchKind::DocumentAddition { addition_ids } => {
|
|
|
|
let tasks = self.get_existing_tasks(rtxn, addition_ids)?;
|
|
|
|
let primary_key = match &tasks[0].kind {
|
2022-09-14 06:34:02 +08:00
|
|
|
KindWithContent::DocumentAddition { primary_key, .. } => primary_key.clone(),
|
2022-09-13 17:46:07 +08:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2022-09-16 22:31:16 +08:00
|
|
|
let content_files = tasks
|
2022-09-13 17:46:07 +08:00
|
|
|
.iter()
|
|
|
|
.map(|task| match task.kind {
|
2022-09-14 06:34:02 +08:00
|
|
|
KindWithContent::DocumentAddition { content_file, .. } => content_file,
|
2022-09-13 17:46:07 +08:00
|
|
|
_ => unreachable!(),
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
2022-09-16 22:31:16 +08:00
|
|
|
Ok(Some(Batch::DocumentAddition {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
tasks,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::DocumentUpdate { update_ids } => {
|
|
|
|
let tasks = self.get_existing_tasks(rtxn, update_ids)?;
|
|
|
|
let primary_key = match &tasks[0].kind {
|
|
|
|
KindWithContent::DocumentUpdate { primary_key, .. } => primary_key.clone(),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
let content_files = tasks
|
2022-09-13 17:46:07 +08:00
|
|
|
.iter()
|
2022-09-16 22:31:16 +08:00
|
|
|
.map(|task| match task.kind {
|
|
|
|
KindWithContent::DocumentUpdate { content_file, .. } => content_file,
|
2022-09-13 17:46:07 +08:00
|
|
|
_ => unreachable!(),
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
2022-09-16 22:31:16 +08:00
|
|
|
Ok(Some(Batch::DocumentUpdate {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
tasks,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::DocumentDeletion { deletion_ids } => {
|
|
|
|
let tasks = self.get_existing_tasks(rtxn, deletion_ids)?;
|
|
|
|
|
|
|
|
let mut documents = Vec::new();
|
|
|
|
for task in &tasks {
|
|
|
|
match task.kind {
|
|
|
|
KindWithContent::DocumentDeletion {
|
|
|
|
ref documents_ids, ..
|
|
|
|
} => documents.extend_from_slice(documents_ids),
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Some(Batch::DocumentDeletion {
|
|
|
|
index_uid,
|
|
|
|
documents,
|
|
|
|
tasks,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::Settings { settings_ids } => {
|
|
|
|
let tasks = self.get_existing_tasks(rtxn, settings_ids)?;
|
|
|
|
|
|
|
|
let mut settings = Vec::new();
|
|
|
|
for task in &tasks {
|
|
|
|
match task.kind {
|
|
|
|
KindWithContent::Settings {
|
|
|
|
ref new_settings,
|
|
|
|
is_deletion,
|
|
|
|
..
|
|
|
|
} => settings.push((is_deletion, new_settings.clone())),
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Some(Batch::Settings {
|
|
|
|
index_uid,
|
|
|
|
settings,
|
|
|
|
tasks,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::ClearAndSettings {
|
|
|
|
other,
|
|
|
|
settings_ids,
|
|
|
|
} => {
|
|
|
|
let (index_uid, settings, settings_tasks) = match self
|
|
|
|
.create_next_batch_index(rtxn, index_uid, BatchKind::Settings { settings_ids })?
|
|
|
|
.unwrap()
|
|
|
|
{
|
|
|
|
Batch::Settings {
|
|
|
|
index_uid,
|
|
|
|
settings,
|
|
|
|
tasks,
|
|
|
|
} => (index_uid, settings, tasks),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
let (index_uid, cleared_tasks) = match self
|
|
|
|
.create_next_batch_index(
|
|
|
|
rtxn,
|
|
|
|
index_uid,
|
|
|
|
BatchKind::DocumentClear { ids: other },
|
|
|
|
)?
|
|
|
|
.unwrap()
|
|
|
|
{
|
|
|
|
Batch::DocumentClear { index_uid, tasks } => (index_uid, tasks),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Some(Batch::DocumentClearAndSetting {
|
|
|
|
index_uid,
|
|
|
|
cleared_tasks,
|
|
|
|
settings,
|
|
|
|
settings_tasks,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::SettingsAndDocumentAddition {
|
|
|
|
addition_ids,
|
|
|
|
settings_ids,
|
|
|
|
} => {
|
|
|
|
let (index_uid, settings, settings_tasks) = match self
|
|
|
|
.create_next_batch_index(rtxn, index_uid, BatchKind::Settings { settings_ids })?
|
|
|
|
.unwrap()
|
|
|
|
{
|
|
|
|
Batch::Settings {
|
|
|
|
index_uid,
|
|
|
|
settings,
|
|
|
|
tasks,
|
|
|
|
} => (index_uid, settings, tasks),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let (index_uid, primary_key, content_files, document_addition_tasks) = match self
|
|
|
|
.create_next_batch_index(
|
|
|
|
rtxn,
|
|
|
|
index_uid,
|
|
|
|
BatchKind::DocumentAddition { addition_ids },
|
|
|
|
)?
|
|
|
|
.unwrap()
|
|
|
|
{
|
|
|
|
Batch::DocumentAddition {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
tasks,
|
|
|
|
} => (index_uid, primary_key, content_files, tasks),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2022-09-13 17:46:07 +08:00
|
|
|
Ok(Some(Batch::SettingsAndDocumentAddition {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
document_addition_tasks,
|
|
|
|
settings,
|
|
|
|
settings_tasks,
|
|
|
|
}))
|
|
|
|
}
|
2022-09-14 06:34:02 +08:00
|
|
|
BatchKind::SettingsAndDocumentUpdate {
|
2022-09-16 22:31:16 +08:00
|
|
|
update_ids,
|
|
|
|
settings_ids,
|
|
|
|
} => {
|
|
|
|
let settings = self.create_next_batch_index(
|
|
|
|
rtxn,
|
|
|
|
index_uid.clone(),
|
|
|
|
BatchKind::Settings { settings_ids },
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let document_update = self.create_next_batch_index(
|
|
|
|
rtxn,
|
|
|
|
index_uid.clone(),
|
|
|
|
BatchKind::DocumentUpdate { update_ids },
|
|
|
|
)?;
|
|
|
|
|
|
|
|
match (document_update, settings) {
|
|
|
|
(
|
|
|
|
Some(Batch::DocumentUpdate {
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
tasks: document_update_tasks,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
Some(Batch::Settings {
|
|
|
|
settings,
|
|
|
|
tasks: settings_tasks,
|
|
|
|
..
|
|
|
|
}),
|
|
|
|
) => Ok(Some(Batch::SettingsAndDocumentUpdate {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
document_update_tasks,
|
|
|
|
settings,
|
|
|
|
settings_tasks,
|
|
|
|
})),
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
2022-09-17 03:24:49 +08:00
|
|
|
BatchKind::IndexCreation { id } => {
|
|
|
|
let task = self.get_task(rtxn, id)?.ok_or(Error::CorruptedTaskQueue)?;
|
|
|
|
let (index_uid, primary_key) = match &task.kind {
|
|
|
|
KindWithContent::IndexCreation {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
} => (index_uid.clone(), primary_key.clone()),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
Ok(Some(Batch::IndexCreation {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
task,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::IndexUpdate { id } => {
|
|
|
|
let task = self.get_task(rtxn, id)?.ok_or(Error::CorruptedTaskQueue)?;
|
|
|
|
let primary_key = match &task.kind {
|
|
|
|
KindWithContent::IndexUpdate { primary_key, .. } => primary_key.clone(),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
Ok(Some(Batch::IndexUpdate {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
task,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
BatchKind::IndexDeletion { ids } => Ok(Some(Batch::IndexDeletion {
|
|
|
|
index_uid,
|
|
|
|
tasks: self.get_existing_tasks(rtxn, ids)?,
|
|
|
|
})),
|
2022-09-14 19:13:44 +08:00
|
|
|
BatchKind::IndexSwap { id: _ } => todo!(),
|
|
|
|
BatchKind::IndexRename { id: _ } => todo!(),
|
2022-09-13 17:46:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-07 06:10:14 +08:00
|
|
|
/// Create the next batch to be processed;
|
|
|
|
/// 1. We get the *last* task to cancel.
|
|
|
|
/// 2. We get the *next* snapshot to process.
|
|
|
|
/// 3. We get the *next* dump to process.
|
|
|
|
/// 4. We get the *next* tasks to process for a specific index.
|
2022-09-09 07:40:28 +08:00
|
|
|
pub(crate) fn create_next_batch(&self, rtxn: &RoTxn) -> Result<Option<Batch>> {
|
2022-09-07 06:10:14 +08:00
|
|
|
let enqueued = &self.get_status(rtxn, Status::Enqueued)?;
|
|
|
|
let to_cancel = self.get_kind(rtxn, Kind::CancelTask)? & enqueued;
|
|
|
|
|
|
|
|
// 1. we get the last task to cancel.
|
|
|
|
if let Some(task_id) = to_cancel.max() {
|
2022-09-09 07:40:28 +08:00
|
|
|
return Ok(Some(Batch::Cancel(
|
2022-09-07 06:10:14 +08:00
|
|
|
self.get_task(rtxn, task_id)?
|
|
|
|
.ok_or(Error::CorruptedTaskQueue)?,
|
2022-09-09 07:40:28 +08:00
|
|
|
)));
|
2022-09-07 06:10:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2. we batch the snapshot.
|
|
|
|
let to_snapshot = self.get_kind(rtxn, Kind::Snapshot)? & enqueued;
|
|
|
|
if !to_snapshot.is_empty() {
|
2022-09-09 07:40:28 +08:00
|
|
|
return Ok(Some(Batch::Snapshot(
|
|
|
|
self.get_existing_tasks(rtxn, to_snapshot)?,
|
|
|
|
)));
|
2022-09-07 06:10:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 3. we batch the dumps.
|
|
|
|
let to_dump = self.get_kind(rtxn, Kind::DumpExport)? & enqueued;
|
|
|
|
if !to_dump.is_empty() {
|
2022-09-09 07:40:28 +08:00
|
|
|
return Ok(Some(Batch::Dump(self.get_existing_tasks(rtxn, to_dump)?)));
|
2022-09-07 06:10:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 4. We take the next task and try to batch all the tasks associated with this index.
|
|
|
|
if let Some(task_id) = enqueued.min() {
|
|
|
|
let task = self
|
|
|
|
.get_task(rtxn, task_id)?
|
|
|
|
.ok_or(Error::CorruptedTaskQueue)?;
|
2022-09-09 07:40:28 +08:00
|
|
|
|
|
|
|
// This is safe because all the remaining task are associated with
|
|
|
|
// AT LEAST one index. We can use the right or left one it doesn't
|
|
|
|
// matter.
|
|
|
|
let index_name = task.indexes().unwrap()[0];
|
|
|
|
|
2022-09-14 19:13:44 +08:00
|
|
|
let _index = self.get_index(rtxn, &index_name)? & enqueued;
|
2022-09-09 07:40:28 +08:00
|
|
|
|
|
|
|
let enqueued = enqueued
|
|
|
|
.into_iter()
|
|
|
|
.map(|task_id| {
|
|
|
|
self.get_task(rtxn, task_id)
|
|
|
|
.and_then(|task| task.ok_or(Error::CorruptedTaskQueue))
|
|
|
|
.map(|task| (task.uid, task.kind.as_kind()))
|
|
|
|
})
|
|
|
|
.collect::<Result<Vec<_>>>()?;
|
|
|
|
|
2022-09-13 17:46:07 +08:00
|
|
|
if let Some(batchkind) = crate::autobatcher::autobatch(enqueued) {
|
|
|
|
return self.create_next_batch_index(rtxn, index_name.to_string(), batchkind);
|
|
|
|
}
|
2022-09-07 06:10:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we found no tasks then we were notified for something that got autobatched
|
|
|
|
// somehow and there is nothing to do.
|
2022-09-09 07:40:28 +08:00
|
|
|
Ok(None)
|
2022-09-07 06:10:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-09 18:16:19 +08:00
|
|
|
pub(crate) fn process_batch(&self, wtxn: &mut RwTxn, batch: Batch) -> Result<Vec<Task>> {
|
|
|
|
match batch {
|
2022-09-13 17:46:07 +08:00
|
|
|
Batch::Cancel(_) => todo!(),
|
|
|
|
Batch::Snapshot(_) => todo!(),
|
|
|
|
Batch::Dump(_) => todo!(),
|
2022-09-16 22:31:16 +08:00
|
|
|
Batch::DocumentClear { tasks, .. } => todo!(),
|
2022-09-13 17:46:07 +08:00
|
|
|
Batch::DocumentAddition {
|
2022-09-14 19:13:44 +08:00
|
|
|
index_uid: _,
|
|
|
|
primary_key: _,
|
|
|
|
content_files: _,
|
|
|
|
tasks: _,
|
2022-09-13 17:46:07 +08:00
|
|
|
} => todo!(),
|
|
|
|
Batch::SettingsAndDocumentAddition {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
document_addition_tasks,
|
2022-09-14 19:13:44 +08:00
|
|
|
settings: _,
|
|
|
|
settings_tasks: _,
|
2022-09-13 17:46:07 +08:00
|
|
|
} => {
|
2022-09-14 19:13:07 +08:00
|
|
|
let index = self.index_mapper.create_index(wtxn, &index_uid)?;
|
2022-09-13 17:46:07 +08:00
|
|
|
let mut updated_tasks = Vec::new();
|
|
|
|
|
|
|
|
/*
|
|
|
|
let ret = index.update_settings(settings)?;
|
|
|
|
for (ret, task) in ret.iter().zip(settings_tasks) {
|
|
|
|
match ret {
|
|
|
|
Ok(ret) => task.status = Some(ret),
|
|
|
|
Err(err) => task.error = Some(err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
for (ret, task) in ret.iter().zip(settings_tasks) {
|
|
|
|
match ret {
|
|
|
|
Ok(ret) => task.status = Some(ret),
|
|
|
|
Err(err) => task.error = Some(err),
|
|
|
|
}
|
|
|
|
updated_tasks.push(task);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
let ret = index.update_documents(
|
|
|
|
IndexDocumentsMethod::ReplaceDocuments,
|
|
|
|
primary_key,
|
2022-09-13 20:59:03 +08:00
|
|
|
self.file_store.clone(),
|
2022-09-13 17:46:07 +08:00
|
|
|
content_files.into_iter(),
|
|
|
|
)?;
|
|
|
|
|
2022-09-13 20:59:03 +08:00
|
|
|
for (ret, mut task) in ret.iter().zip(document_addition_tasks.into_iter()) {
|
2022-09-13 17:46:07 +08:00
|
|
|
match ret {
|
2022-09-14 22:16:53 +08:00
|
|
|
Ok(ret) => todo!(), // task.info = Some(format!("{:?}", ret)),
|
|
|
|
Err(err) => todo!(), // task.error = Some(err.to_string()),
|
2022-09-09 18:16:19 +08:00
|
|
|
}
|
2022-09-13 17:46:07 +08:00
|
|
|
updated_tasks.push(task);
|
2022-09-09 18:16:19 +08:00
|
|
|
}
|
2022-09-13 17:46:07 +08:00
|
|
|
Ok(updated_tasks)
|
2022-09-09 18:16:19 +08:00
|
|
|
}
|
2022-09-16 22:31:16 +08:00
|
|
|
Batch::DocumentUpdate {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
tasks,
|
|
|
|
} => todo!(),
|
|
|
|
Batch::DocumentDeletion {
|
|
|
|
index_uid,
|
|
|
|
documents,
|
|
|
|
tasks,
|
|
|
|
} => todo!(),
|
|
|
|
Batch::Settings {
|
|
|
|
index_uid,
|
|
|
|
settings,
|
|
|
|
tasks,
|
|
|
|
} => todo!(),
|
|
|
|
Batch::DocumentClearAndSetting {
|
|
|
|
index_uid,
|
|
|
|
cleared_tasks,
|
|
|
|
settings,
|
|
|
|
settings_tasks,
|
|
|
|
} => todo!(),
|
|
|
|
Batch::SettingsAndDocumentUpdate {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
content_files,
|
|
|
|
document_update_tasks,
|
|
|
|
settings,
|
|
|
|
settings_tasks,
|
|
|
|
} => todo!(),
|
2022-09-17 03:24:49 +08:00
|
|
|
Batch::IndexCreation {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
task,
|
|
|
|
} => todo!(),
|
|
|
|
Batch::IndexUpdate {
|
|
|
|
index_uid,
|
|
|
|
primary_key,
|
|
|
|
task,
|
|
|
|
} => todo!(),
|
|
|
|
Batch::IndexDeletion { index_uid, tasks } => todo!(),
|
2022-09-07 06:10:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-08 02:08:07 +08:00
|
|
|
|
2022-09-09 18:16:19 +08:00
|
|
|
/*
|
2022-09-08 02:08:07 +08:00
|
|
|
impl Batch {
|
|
|
|
pub fn task_ids(&self) -> impl IntoIterator<Item = TaskId> + '_ {
|
|
|
|
match self {
|
|
|
|
Batch::Cancel(task) | Batch::One(task) => {
|
|
|
|
Box::new(std::iter::once(task.uid)) as Box<dyn Iterator<Item = TaskId>>
|
|
|
|
}
|
|
|
|
Batch::Snapshot(tasks) | Batch::Dump(tasks) | Batch::Contiguous { tasks, .. } => {
|
|
|
|
Box::new(tasks.iter().map(|task| task.uid)) as Box<dyn Iterator<Item = TaskId>>
|
|
|
|
}
|
|
|
|
Batch::Empty => Box::new(std::iter::empty()) as Box<dyn Iterator<Item = TaskId>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-09 18:16:19 +08:00
|
|
|
*/
|