From c966b1dd94e3699e93c4037df4a4066b7eb4f8b1 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 17 Mar 2021 12:01:56 +0100 Subject: [PATCH] use options to schedule snapshot --- meilisearch-http/src/data/mod.rs | 4 +-- meilisearch-http/src/index_controller/mod.rs | 27 +++++++++++++------- meilisearch-http/src/option.rs | 4 +-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index c312c2912..19004da70 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -60,9 +60,7 @@ impl Data { let path = options.db_path.clone(); create_dir_all(&path)?; - let index_size = options.max_mdb_size.get_bytes() as usize; - let update_store_size = options.max_udb_size.get_bytes() as usize; - let index_controller = IndexController::new(&path, index_size, update_store_size)?; + let index_controller = IndexController::new(&path, &options)?; let mut api_keys = ApiKeys { master: options.clone().master_key, diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index 0449941ce..fc0fd3d46 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -20,6 +20,7 @@ use tokio::time::sleep; use crate::index::{Document, SearchQuery, SearchResult}; use crate::index::{Facets, Settings, UpdateResult}; +use crate::option::Opt; pub use updates::{Failed, Processed, Processing}; use snapshot::SnapshotService; @@ -64,20 +65,28 @@ pub struct IndexController { impl IndexController { pub fn new( path: impl AsRef, - index_size: usize, - update_store_size: usize, + options: &Opt, ) -> anyhow::Result { + let index_size = options.max_mdb_size.get_bytes() as usize; + let update_store_size = options.max_udb_size.get_bytes() as usize; + let uuid_resolver = uuid_resolver::UuidResolverHandle::new(&path)?; let index_handle = index_actor::IndexActorHandle::new(&path, index_size)?; let update_handle = update_actor::UpdateActorHandle::new(index_handle.clone(), &path, update_store_size)?; - let snapshot_service = SnapshotService::new( - index_handle.clone(), - uuid_resolver.clone(), - update_handle.clone(), - Duration::from_millis(10000), - "/dev/toto".into()); - tokio::task::spawn(snapshot_service.run()); + + if options.schedule_snapshot { + let snapshot_service = SnapshotService::new( + index_handle.clone(), + uuid_resolver.clone(), + update_handle.clone(), + Duration::from_secs(options.snapshot_interval_sec), + options.snapshot_dir.clone() + ); + + tokio::task::spawn(snapshot_service.run()); + } + Ok(Self { uuid_resolver, index_handle, diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index 82eb75fc1..1997718cc 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -191,8 +191,8 @@ pub struct Opt { pub schedule_snapshot: bool, /// Defines time interval, in seconds, between each snapshot creation. - #[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC")] - pub snapshot_interval_sec: Option, + #[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC", default_value = "86400")] // 24h + pub snapshot_interval_sec: u64, /// Folder where dumps are created when the dump route is called. #[structopt(long, env = "MEILI_DUMPS_DIR", default_value = "dumps/")]