use options to schedule snapshot

This commit is contained in:
mpostma 2021-03-17 12:01:56 +01:00
parent ee838be41b
commit c966b1dd94
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
3 changed files with 21 additions and 14 deletions

View File

@ -60,9 +60,7 @@ impl Data {
let path = options.db_path.clone(); let path = options.db_path.clone();
create_dir_all(&path)?; create_dir_all(&path)?;
let index_size = options.max_mdb_size.get_bytes() as usize; let index_controller = IndexController::new(&path, &options)?;
let update_store_size = options.max_udb_size.get_bytes() as usize;
let index_controller = IndexController::new(&path, index_size, update_store_size)?;
let mut api_keys = ApiKeys { let mut api_keys = ApiKeys {
master: options.clone().master_key, master: options.clone().master_key,

View File

@ -20,6 +20,7 @@ use tokio::time::sleep;
use crate::index::{Document, SearchQuery, SearchResult}; use crate::index::{Document, SearchQuery, SearchResult};
use crate::index::{Facets, Settings, UpdateResult}; use crate::index::{Facets, Settings, UpdateResult};
use crate::option::Opt;
pub use updates::{Failed, Processed, Processing}; pub use updates::{Failed, Processed, Processing};
use snapshot::SnapshotService; use snapshot::SnapshotService;
@ -64,20 +65,28 @@ pub struct IndexController {
impl IndexController { impl IndexController {
pub fn new( pub fn new(
path: impl AsRef<Path>, path: impl AsRef<Path>,
index_size: usize, options: &Opt,
update_store_size: usize,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
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 uuid_resolver = uuid_resolver::UuidResolverHandle::new(&path)?;
let index_handle = index_actor::IndexActorHandle::new(&path, index_size)?; let index_handle = index_actor::IndexActorHandle::new(&path, index_size)?;
let update_handle = let update_handle =
update_actor::UpdateActorHandle::new(index_handle.clone(), &path, update_store_size)?; update_actor::UpdateActorHandle::new(index_handle.clone(), &path, update_store_size)?;
if options.schedule_snapshot {
let snapshot_service = SnapshotService::new( let snapshot_service = SnapshotService::new(
index_handle.clone(), index_handle.clone(),
uuid_resolver.clone(), uuid_resolver.clone(),
update_handle.clone(), update_handle.clone(),
Duration::from_millis(10000), Duration::from_secs(options.snapshot_interval_sec),
"/dev/toto".into()); options.snapshot_dir.clone()
);
tokio::task::spawn(snapshot_service.run()); tokio::task::spawn(snapshot_service.run());
}
Ok(Self { Ok(Self {
uuid_resolver, uuid_resolver,
index_handle, index_handle,

View File

@ -191,8 +191,8 @@ pub struct Opt {
pub schedule_snapshot: bool, pub schedule_snapshot: bool,
/// Defines time interval, in seconds, between each snapshot creation. /// Defines time interval, in seconds, between each snapshot creation.
#[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC")] #[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC", default_value = "86400")] // 24h
pub snapshot_interval_sec: Option<u64>, pub snapshot_interval_sec: u64,
/// Folder where dumps are created when the dump route is called. /// Folder where dumps are created when the dump route is called.
#[structopt(long, env = "MEILI_DUMPS_DIR", default_value = "dumps/")] #[structopt(long, env = "MEILI_DUMPS_DIR", default_value = "dumps/")]