From 03af99650df17b354b295b271099d8f2c6a7aec6 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 29 Sep 2021 12:34:39 +0200 Subject: [PATCH] fix dumpv1 --- meilisearch-lib/src/compression.rs | 5 +++-- .../src/index_controller/dump_actor/loaders/v1.rs | 6 +++--- .../src/index_controller/dump_actor/mod.rs | 11 +++++++++++ .../src/index_controller/update_file_store.rs | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/meilisearch-lib/src/compression.rs b/meilisearch-lib/src/compression.rs index c4747cb21..9bbe9ae00 100644 --- a/meilisearch-lib/src/compression.rs +++ b/meilisearch-lib/src/compression.rs @@ -1,8 +1,9 @@ -use std::fs::{create_dir_all, File}; +use std::fs::{File, create_dir_all}; use std::io::Write; use std::path::Path; -use flate2::{read::GzDecoder, write::GzEncoder, Compression}; +use flate2::read::GzDecoder; +use flate2::{Compression, write::GzEncoder}; use tar::{Archive, Builder}; pub fn to_tar_gz(src: impl AsRef, dest: impl AsRef) -> anyhow::Result<()> { diff --git a/meilisearch-lib/src/index_controller/dump_actor/loaders/v1.rs b/meilisearch-lib/src/index_controller/dump_actor/loaders/v1.rs index a41e18683..303bdd081 100644 --- a/meilisearch-lib/src/index_controller/dump_actor/loaders/v1.rs +++ b/meilisearch-lib/src/index_controller/dump_actor/loaders/v1.rs @@ -39,9 +39,9 @@ impl MetadataV1 { ); let uuid_store = HeedUuidStore::new(&dst)?; - for index in self.indexes { + for index in dbg!(self.indexes) { let uuid = Uuid::new_v4(); - uuid_store.insert(index.uid.clone(), uuid)?; + uuid_store.insert(dbg!(index.uid.clone()), dbg!(uuid))?; let src = src.as_ref().join(index.uid); load_index( &src, @@ -93,7 +93,7 @@ fn load_index( size: usize, indexer_options: &IndexerOpts, ) -> anyhow::Result<()> { - let index_path = dst.as_ref().join(&format!("indexes/index-{}", uuid)); + let index_path = dst.as_ref().join(&format!("indexes/{}", uuid)); create_dir_all(&index_path)?; let mut options = EnvOpenOptions::new(); diff --git a/meilisearch-lib/src/index_controller/dump_actor/mod.rs b/meilisearch-lib/src/index_controller/dump_actor/mod.rs index 3f9d33223..4f32ade4d 100644 --- a/meilisearch-lib/src/index_controller/dump_actor/mod.rs +++ b/meilisearch-lib/src/index_controller/dump_actor/mod.rs @@ -109,6 +109,15 @@ pub fn load_dump( update_db_size: usize, indexer_opts: &IndexerOpts, ) -> anyhow::Result<()> { + // Setup a temp directory path in the same path as the database, to prevent cross devices + // references. + let temp_path = dst_path.as_ref().parent().map(ToOwned::to_owned).unwrap_or_else(|| ".".into()); + if cfg!(windows) { + std::env::set_var("TMP", temp_path); + } else { + std::env::set_var("TMPDIR", temp_path); + } + let tmp_src = tempfile::tempdir()?; let tmp_src_path = tmp_src.path(); @@ -120,6 +129,8 @@ pub fn load_dump( let tmp_dst = tempfile::tempdir()?; + println!("temp path: {}", tmp_dst.path().display()); + match meta { Metadata::V1(meta) => { meta.load_dump(&tmp_src_path, tmp_dst.path(), index_db_size, indexer_opts)? diff --git a/meilisearch-lib/src/index_controller/update_file_store.rs b/meilisearch-lib/src/index_controller/update_file_store.rs index 09ddc1d89..2a178d908 100644 --- a/meilisearch-lib/src/index_controller/update_file_store.rs +++ b/meilisearch-lib/src/index_controller/update_file_store.rs @@ -75,6 +75,7 @@ impl UpdateFileStore { create_dir_all(&dst_update_files_path)?; + println!("src_update file: {}", src_update_files_path.display()); let entries = std::fs::read_dir(src_update_files_path)?; for entry in entries {