From 56eb2907c9b8809b663111f3bb38492a9d7660b1 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Thu, 19 May 2022 14:59:59 +0200 Subject: [PATCH] dump indexes --- meilisearch-lib/src/dump/mod.rs | 16 +++++++++++--- meilisearch-lib/src/index_controller/mod.rs | 1 + .../src/tasks/batch_handlers/dump_handler.rs | 22 ++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/meilisearch-lib/src/dump/mod.rs b/meilisearch-lib/src/dump/mod.rs index 59b51a601..05deb8a40 100644 --- a/meilisearch-lib/src/dump/mod.rs +++ b/meilisearch-lib/src/dump/mod.rs @@ -1,5 +1,6 @@ use std::fs::File; use std::path::{Path, PathBuf}; +use std::sync::Arc; use anyhow::bail; use log::{info, trace}; @@ -13,6 +14,9 @@ use tokio::fs::create_dir_all; use crate::analytics; use crate::compression::{from_tar_gz, to_tar_gz}; use crate::dump::error::DumpError; +use crate::index_resolver::index_store::IndexStore; +use crate::index_resolver::meta_store::IndexMetaStore; +use crate::index_resolver::IndexResolver; use crate::options::IndexerOpts; use crate::update_file_store::UpdateFileStore; use error::Result; @@ -255,16 +259,21 @@ fn persist_dump(dst_path: impl AsRef, tmp_dst: TempDir) -> anyhow::Result< Ok(()) } -pub struct DumpJob { +pub struct DumpJob { pub dump_path: PathBuf, pub db_path: PathBuf, pub update_file_store: UpdateFileStore, pub uid: String, pub update_db_size: usize, pub index_db_size: usize, + pub index_resolver: Arc>, } -impl DumpJob { +impl DumpJob +where + U: IndexMetaStore, + I: IndexStore, +{ pub async fn run(self) -> Result<()> { trace!("Performing dump."); @@ -281,8 +290,9 @@ impl DumpJob { create_dir_all(&temp_dump_path.join("indexes")).await?; + // TODO: this is blocking!! AuthController::dump(&self.db_path, &temp_dump_path)?; - // TODO: Dump indexes and updates + self.index_resolver.dump(&self.dump_path).await?; //TODO(marin): this is not right, the scheduler should dump itself, not do it here... // self.scheduler diff --git a/meilisearch-lib/src/index_controller/mod.rs b/meilisearch-lib/src/index_controller/mod.rs index de4426f81..f89ebec4e 100644 --- a/meilisearch-lib/src/index_controller/mod.rs +++ b/meilisearch-lib/src/index_controller/mod.rs @@ -228,6 +228,7 @@ impl IndexControllerBuilder { db_path.as_ref().clone(), index_size, task_store_size, + index_resolver.clone(), )); let task_store = TaskStore::new(meta_env)?; diff --git a/meilisearch-lib/src/tasks/batch_handlers/dump_handler.rs b/meilisearch-lib/src/tasks/batch_handlers/dump_handler.rs index c0ef70ba8..057cf274f 100644 --- a/meilisearch-lib/src/tasks/batch_handlers/dump_handler.rs +++ b/meilisearch-lib/src/tasks/batch_handlers/dump_handler.rs @@ -1,15 +1,20 @@ use std::path::{Path, PathBuf}; +use std::sync::Arc; use log::{error, trace}; use time::{macros::format_description, OffsetDateTime}; use crate::dump::DumpJob; +use crate::index_resolver::index_store::IndexStore; +use crate::index_resolver::meta_store::IndexMetaStore; +use crate::index_resolver::IndexResolver; use crate::tasks::batch::{Batch, BatchContent}; use crate::tasks::BatchHandler; use crate::update_file_store::UpdateFileStore; -pub struct DumpHandler { +pub struct DumpHandler { update_file_store: UpdateFileStore, + index_resolver: Arc>, dump_path: PathBuf, db_path: PathBuf, update_db_size: usize, @@ -25,13 +30,18 @@ fn generate_uid() -> String { .unwrap() } -impl DumpHandler { +impl DumpHandler +where + U: IndexMetaStore + Send + Sync + 'static, + I: IndexStore + Send + Sync + 'static, +{ pub fn new( update_file_store: UpdateFileStore, dump_path: impl AsRef, db_path: impl AsRef, index_db_size: usize, update_db_size: usize, + index_resolver: Arc>, ) -> Self { Self { update_file_store, @@ -39,6 +49,7 @@ impl DumpHandler { db_path: db_path.as_ref().into(), index_db_size, update_db_size, + index_resolver, } } @@ -52,6 +63,7 @@ impl DumpHandler { uid: uid.clone(), update_db_size: self.update_db_size, index_db_size: self.index_db_size, + index_resolver: self.index_resolver.clone(), }; let task_result = tokio::task::spawn_local(task.run()).await; @@ -71,7 +83,11 @@ impl DumpHandler { } #[async_trait::async_trait] -impl BatchHandler for DumpHandler { +impl BatchHandler for DumpHandler +where + U: IndexMetaStore + Send + Sync + 'static, + I: IndexStore + Send + Sync + 'static, +{ fn accept(&self, batch: &Batch) -> bool { matches!(batch.content, BatchContent::Dump { .. }) }