From 7c0d8f073bd1575952078b10d670cd4d143eb4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 23 Jan 2020 15:33:36 +0100 Subject: [PATCH] Support compaction with multi database --- meilisearch-core/src/database.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 14242f890..43a61b187 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -319,8 +319,26 @@ impl Database { self.update_env.typed_write_txn::() } - pub fn copy_and_compact_to_path>(&self, path: P) -> ZResult { - self.env.copy_to_path(path, CompactionOption::Enabled) + pub fn copy_and_compact_to_path>(&self, path: P) -> ZResult<(File, File)> { + let path = path.as_ref(); + + let env_path = path.join("main"); + let env_update_path = path.join("update"); + + fs::create_dir(&env_path)?; + fs::create_dir(&env_update_path)?; + + let env_path = env_path.join("data.mdb"); + let env_file = self.env.copy_to_path(&env_path, CompactionOption::Enabled)?; + + let env_update_path = env_update_path.join("data.mdb"); + match self.update_env.copy_to_path(env_update_path, CompactionOption::Enabled) { + Ok(update_env_file) => Ok((env_file, update_env_file)), + Err(e) => { + fs::remove_file(env_path)?; + Err(e) + }, + } } pub fn indexes_uids(&self) -> Vec {