Merge pull request #454 from meilisearch/fix-db-compaction

Support compaction with the new split database
This commit is contained in:
Clément Renault 2020-01-24 17:45:34 +01:00 committed by GitHub
commit cde8845143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -319,8 +319,26 @@ impl Database {
self.update_env.typed_write_txn::<UpdateT>() self.update_env.typed_write_txn::<UpdateT>()
} }
pub fn copy_and_compact_to_path<P: AsRef<Path>>(&self, path: P) -> ZResult<File> { pub fn copy_and_compact_to_path<P: AsRef<Path>>(&self, path: P) -> ZResult<(File, File)> {
self.env.copy_to_path(path, CompactionOption::Enabled) 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<String> { pub fn indexes_uids(&self) -> Vec<String> {