mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
implement snapshot scheduler
This commit is contained in:
parent
2f418ee767
commit
ee838be41b
@ -4,6 +4,7 @@ mod update_handler;
|
||||
mod update_store;
|
||||
mod updates;
|
||||
mod uuid_resolver;
|
||||
mod snapshot;
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
@ -19,7 +20,9 @@ use tokio::time::sleep;
|
||||
|
||||
use crate::index::{Document, SearchQuery, SearchResult};
|
||||
use crate::index::{Facets, Settings, UpdateResult};
|
||||
|
||||
pub use updates::{Failed, Processed, Processing};
|
||||
use snapshot::SnapshotService;
|
||||
|
||||
pub type UpdateStatus = updates::UpdateStatus<UpdateMeta, UpdateResult, String>;
|
||||
|
||||
@ -65,12 +68,19 @@ impl IndexController {
|
||||
update_store_size: usize,
|
||||
) -> anyhow::Result<Self> {
|
||||
let uuid_resolver = uuid_resolver::UuidResolverHandle::new(&path)?;
|
||||
let index_actor = index_actor::IndexActorHandle::new(&path, index_size)?;
|
||||
let index_handle = index_actor::IndexActorHandle::new(&path, index_size)?;
|
||||
let update_handle =
|
||||
update_actor::UpdateActorHandle::new(index_actor.clone(), &path, update_store_size)?;
|
||||
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());
|
||||
Ok(Self {
|
||||
uuid_resolver,
|
||||
index_handle: index_actor,
|
||||
index_handle,
|
||||
update_handle,
|
||||
})
|
||||
}
|
||||
|
48
meilisearch-http/src/index_controller/snapshot.rs
Normal file
48
meilisearch-http/src/index_controller/snapshot.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
|
||||
use tokio::time::interval;
|
||||
|
||||
use super::index_actor::IndexActorHandle;
|
||||
use super::update_actor::UpdateActorHandle;
|
||||
use super::uuid_resolver::UuidResolverHandle;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct SnapshotService<B> {
|
||||
index_handle: IndexActorHandle,
|
||||
uuid_resolver_handle: UuidResolverHandle,
|
||||
update_handle: UpdateActorHandle<B>,
|
||||
snapshot_period: Duration,
|
||||
snapshot_path: PathBuf,
|
||||
}
|
||||
|
||||
impl<B> SnapshotService<B> {
|
||||
pub fn new(
|
||||
index_handle: IndexActorHandle,
|
||||
uuid_resolver_handle: UuidResolverHandle,
|
||||
update_handle: UpdateActorHandle<B>,
|
||||
snapshot_period: Duration,
|
||||
snapshot_path: PathBuf,
|
||||
) -> Self {
|
||||
Self {
|
||||
index_handle,
|
||||
uuid_resolver_handle,
|
||||
update_handle,
|
||||
snapshot_period,
|
||||
snapshot_path,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(self) {
|
||||
let mut interval = interval(self.snapshot_period);
|
||||
|
||||
loop {
|
||||
interval.tick().await;
|
||||
self.perform_snapshot().await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn perform_snapshot(&self) {
|
||||
println!("performing snapshot in {:?}", self.snapshot_path);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user