diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 27b66cdf3..e01a8a95f 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -11,7 +11,7 @@ use heed::{CompactionOption, Result as ZResult}; use log::{debug, error}; use meilisearch_schema::Schema; -use crate::{store, update, Index, MResult, Error, UpdateReader, MainWriter}; +use crate::{store, update, Index, MResult, Error, UpdateReader, UpdateWriter, MainReader, MainWriter}; pub type BoxUpdateFn = Box; type ArcSwapFn = arc_swap::ArcSwapOption; @@ -332,11 +332,11 @@ impl Database { self.update_fn.swap(None); } - pub fn main_read_txn(&self) -> MResult> { + pub fn main_read_txn(&self) -> MResult { Ok(self.env.typed_read_txn::()?) } - pub(crate) fn main_write_txn(&self) -> MResult> { + pub(crate) fn main_write_txn(&self) -> MResult { Ok(self.env.typed_write_txn::()?) } @@ -344,7 +344,7 @@ impl Database { /// transaction is commited. Returns whatever result f returns. pub fn main_write(&self, f: F) -> Result where - F: FnOnce(&mut heed::RwTxn) -> Result, + F: FnOnce(&mut MainWriter) -> Result, E: From, { let mut writer = self.main_write_txn()?; @@ -356,22 +356,26 @@ impl Database { /// provides a context with a reader to the main database. experimental. pub fn main_read(&self, f: F) -> Result where - F: Fn(&heed::RoTxn) -> Result, + F: Fn(&MainReader) -> Result, E: From, { let reader = self.main_read_txn()?; f(&reader) } - pub fn update_read_txn(&self) -> MResult> { + pub fn update_read_txn(&self) -> MResult { Ok(self.update_env.typed_read_txn::()?) } + pub(crate) fn update_write_txn(&self) -> MResult> { + Ok(self.update_env.typed_write_txn::()?) + } + /// Calls f providing it with a writer to the main database. After f is called, makes sure the /// transaction is commited. Returns whatever result f returns. pub fn update_write(&self, f: F) -> Result where - F: FnOnce(&mut heed::RwTxn) -> Result, + F: FnOnce(&mut UpdateWriter) -> Result, E: From, { let mut writer = self.update_write_txn()?; @@ -383,18 +387,14 @@ impl Database { /// provides a context with a reader to the update database. experimental. pub fn update_read(&self, f: F) -> Result where - F: Fn(&heed::RoTxn) -> Result, + F: Fn(&UpdateReader) -> Result, E: From, { let reader = self.update_read_txn()?; f(&reader) } - pub(crate) fn update_write_txn(&self) -> MResult> { - Ok(self.update_env.typed_write_txn::()?) - } - - pub fn copy_and_compact_to_path>(&self, path: P) -> ZResult<(File, File)> { + pub fn copy_and_compact_to_path>(&self, path: P) -> MResult<(File, File)> { let path = path.as_ref(); let env_path = path.join("main"); @@ -411,7 +411,7 @@ impl Database { Ok(update_env_file) => Ok((env_file, update_env_file)), Err(e) => { fs::remove_file(env_path)?; - Err(e) + Err(e.into()) }, } }