From edd8344dc9f2fafbd7a275ea8a8d92e4914936c5 Mon Sep 17 00:00:00 2001 From: Tamo Date: Sun, 18 Sep 2022 22:04:36 +0200 Subject: [PATCH] wip --- index-scheduler/src/batch.rs | 42 ++++++++++++++++++++++++++++++------ index-scheduler/src/task.rs | 4 ++-- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index 209b9adbc..b9ee10a76 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -1,12 +1,12 @@ use crate::{ autobatcher::BatchKind, - task::{Kind, KindWithContent, Status, Task}, + task::{Details, Kind, KindWithContent, Status, Task}, Error, IndexScheduler, Result, TaskId, }; use index::{Settings, Unchecked}; use milli::{ heed::{RoTxn, RwTxn}, - update::IndexDocumentsMethod, + update::{DocumentAdditionResult, IndexDocumentsMethod}, DocumentId, }; use uuid::Uuid; @@ -434,11 +434,39 @@ impl IndexScheduler { Batch::Dump(_) => todo!(), Batch::DocumentClear { tasks, .. } => todo!(), Batch::DocumentAddition { - index_uid: _, - primary_key: _, - content_files: _, - tasks: _, - } => todo!(), + index_uid, + primary_key, + content_files, + mut tasks, + } => { + let index = self.index_mapper.create_index(wtxn, &index_uid)?; + let ret = index.update_documents( + IndexDocumentsMethod::ReplaceDocuments, + primary_key, + self.file_store.clone(), + content_files, + )?; + + for (task, ret) in tasks.iter_mut().zip(ret) { + match ret { + Ok(DocumentAdditionResult { + indexed_documents, + number_of_documents, + }) => { + task.details = Some(Details::DocumentAddition { + received_documents: number_of_documents, + indexed_documents, + }); + } + Err(error) => { + // TODO: TAMO: find a way to convert all errors to the `Task::Error` type + // task.error = Some(error); + } + } + } + + todo!() + } Batch::SettingsAndDocumentAddition { index_uid, primary_key, diff --git a/index-scheduler/src/task.rs b/index-scheduler/src/task.rs index 200a2f58b..6c999dd8a 100644 --- a/index-scheduler/src/task.rs +++ b/index-scheduler/src/task.rs @@ -276,8 +276,8 @@ pub enum Kind { pub enum Details { #[serde(rename_all = "camelCase")] DocumentAddition { - received_documents: usize, - indexed_documents: Option, + received_documents: u64, + indexed_documents: u64, }, #[serde(rename_all = "camelCase")] Settings {