mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 10:07:40 +08:00
dump indexes
This commit is contained in:
parent
414d0907ce
commit
56eb2907c9
@ -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<Path>, tmp_dst: TempDir) -> anyhow::Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct DumpJob {
|
||||
pub struct DumpJob<U, I> {
|
||||
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<IndexResolver<U, I>>,
|
||||
}
|
||||
|
||||
impl DumpJob {
|
||||
impl<U, I> DumpJob<U, I>
|
||||
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
|
||||
|
@ -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)?;
|
||||
|
||||
|
@ -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<U, I> {
|
||||
update_file_store: UpdateFileStore,
|
||||
index_resolver: Arc<IndexResolver<U, I>>,
|
||||
dump_path: PathBuf,
|
||||
db_path: PathBuf,
|
||||
update_db_size: usize,
|
||||
@ -25,13 +30,18 @@ fn generate_uid() -> String {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
impl DumpHandler {
|
||||
impl<U, I> DumpHandler<U, I>
|
||||
where
|
||||
U: IndexMetaStore + Send + Sync + 'static,
|
||||
I: IndexStore + Send + Sync + 'static,
|
||||
{
|
||||
pub fn new(
|
||||
update_file_store: UpdateFileStore,
|
||||
dump_path: impl AsRef<Path>,
|
||||
db_path: impl AsRef<Path>,
|
||||
index_db_size: usize,
|
||||
update_db_size: usize,
|
||||
index_resolver: Arc<IndexResolver<U, I>>,
|
||||
) -> 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<U, I> BatchHandler for DumpHandler<U, I>
|
||||
where
|
||||
U: IndexMetaStore + Send + Sync + 'static,
|
||||
I: IndexStore + Send + Sync + 'static,
|
||||
{
|
||||
fn accept(&self, batch: &Batch) -> bool {
|
||||
matches!(batch.content, BatchContent::Dump { .. })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user