write and load the user-id in the dumps

This commit is contained in:
Tamo 2021-10-26 12:34:00 +02:00 committed by marin postma
parent ba14ea1243
commit 87a8bf5e96
No known key found for this signature in database
GPG key ID: 6088B7721C3E39F9
9 changed files with 51 additions and 13 deletions

View file

@ -0,0 +1,17 @@
use std::{fs, path::Path};
/// To load a dump we get the user id from the source directory;
/// If there was a user-id, write it to the new destination if not ignore the error
pub fn load_dump(src: &Path, dst: &Path) {
if let Ok(user_id) = fs::read_to_string(src.join("user-id")) {
let _ = fs::write(dst.join("user-id"), &user_id);
}
}
/// To load a dump we get the user id either from the source directory;
/// If there was a user-id, write it to the new destination if not ignore the error
pub fn write_dump(src: &Path, dst: &Path) {
if let Ok(user_id) = fs::read_to_string(src) {
let _ = fs::write(dst, &user_id);
}
}

View file

@ -22,6 +22,7 @@ pub struct DumpActor<U, I> {
index_resolver: Arc<IndexResolver<U, I>>,
update: UpdateSender,
dump_path: PathBuf,
analytics_path: PathBuf,
lock: Arc<Mutex<()>>,
dump_infos: Arc<RwLock<HashMap<String, DumpInfo>>>,
update_db_size: usize,
@ -43,6 +44,7 @@ where
index_resolver: Arc<IndexResolver<U, I>>,
update: UpdateSender,
dump_path: impl AsRef<Path>,
analytics_path: impl AsRef<Path>,
index_db_size: usize,
update_db_size: usize,
) -> Self {
@ -53,6 +55,7 @@ where
index_resolver,
update,
dump_path: dump_path.as_ref().into(),
analytics_path: analytics_path.as_ref().into(),
dump_infos,
lock,
index_db_size,
@ -119,6 +122,7 @@ where
let task = DumpTask {
path: self.dump_path.clone(),
analytics_path: self.analytics_path.clone(),
index_resolver: self.index_resolver.clone(),
update_sender: self.update.clone(),
uid: uid.clone(),

View file

@ -33,6 +33,7 @@ impl DumpActorHandle for DumpActorHandleImpl {
impl DumpActorHandleImpl {
pub fn new(
path: impl AsRef<Path>,
analytics_path: impl AsRef<Path>,
index_resolver: Arc<HardStateIndexResolver>,
update: crate::index_controller::updates::UpdateSender,
index_db_size: usize,
@ -44,6 +45,7 @@ impl DumpActorHandleImpl {
index_resolver,
update,
path,
analytics_path,
index_db_size,
update_db_size,
);

View file

@ -2,6 +2,7 @@ use std::path::Path;
use log::info;
use crate::analytics;
use crate::index_controller::dump_actor::Metadata;
use crate::index_controller::index_resolver::IndexResolver;
use crate::index_controller::update_file_store::UpdateFileStore;
@ -24,6 +25,7 @@ pub fn load_dump(
IndexResolver::load_dump(src.as_ref(), &dst, index_db_size, indexing_options)?;
UpdateFileStore::load_dump(src.as_ref(), &dst)?;
UpdateStore::load_dump(&src, &dst, update_db_size)?;
analytics::load_dump(src.as_ref(), dst.as_ref());
info!("Loading indexes.");

View file

@ -17,6 +17,7 @@ use super::index_resolver::index_store::IndexStore;
use super::index_resolver::uuid_store::UuidStore;
use super::index_resolver::IndexResolver;
use super::updates::UpdateSender;
use crate::analytics;
use crate::compression::{from_tar_gz, to_tar_gz};
use crate::index_controller::dump_actor::error::DumpActorError;
use crate::index_controller::dump_actor::loaders::{v2, v3};
@ -223,6 +224,7 @@ pub fn load_dump(
struct DumpTask<U, I> {
path: PathBuf,
analytics_path: PathBuf,
index_resolver: Arc<IndexResolver<U, I>>,
update_sender: UpdateSender,
uid: String,
@ -247,6 +249,7 @@ where
let meta_path = temp_dump_path.join(META_FILE_NAME);
let mut meta_file = File::create(&meta_path)?;
serde_json::to_writer(&mut meta_file, &meta)?;
analytics::write_dump(&self.analytics_path, &temp_dump_path.join("user-id"));
create_dir_all(&temp_dump_path.join("indexes")).await?;
let uuids = self.index_resolver.dump(temp_dump_path.clone()).await?;
@ -339,6 +342,8 @@ mod test {
let task = DumpTask {
path: tmp.path().to_owned(),
// this should do nothing
analytics_path: tmp.path().join("user-id"),
index_resolver,
update_sender,
uid: String::from("test"),
@ -367,6 +372,8 @@ mod test {
let task = DumpTask {
path: tmp.path().to_owned(),
// this should do nothing
analytics_path: tmp.path().join("user-id"),
index_resolver,
update_sender,
uid: String::from("test"),

View file

@ -169,8 +169,10 @@ impl IndexControllerBuilder {
let dump_path = self
.dump_dst
.ok_or_else(|| anyhow::anyhow!("Missing dump directory path"))?;
let analytics_path = db_path.as_ref().join("user-id");
let dump_handle = dump_actor::DumpActorHandleImpl::new(
dump_path,
analytics_path,
index_resolver.clone(),
update_sender.clone(),
index_size,

View file

@ -5,6 +5,8 @@ pub mod options;
pub mod index;
pub mod index_controller;
mod analytics;
pub use index_controller::updates::store::Update;
pub use index_controller::MeiliSearch;