diff --git a/crates/core/src/database_instance_context.rs b/crates/core/src/database_instance_context.rs index 8b0b7028d4c..f9f34d2e4ed 100644 --- a/crates/core/src/database_instance_context.rs +++ b/crates/core/src/database_instance_context.rs @@ -12,6 +12,8 @@ use crate::messages::control_db::Database; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; +pub type Result = anyhow::Result; + #[derive(Clone)] pub struct DatabaseInstanceContext { pub database_instance_id: u64, @@ -24,7 +26,12 @@ pub struct DatabaseInstanceContext { } impl DatabaseInstanceContext { - pub fn from_database(config: Config, database: &Database, instance_id: u64, root_db_path: PathBuf) -> Arc { + pub fn from_database( + config: Config, + database: &Database, + instance_id: u64, + root_db_path: PathBuf, + ) -> Result> { let mut db_path = root_db_path; db_path.extend([&*database.address.to_hex(), &*instance_id.to_string()]); db_path.push("database"); @@ -60,12 +67,12 @@ impl DatabaseInstanceContext { db_path: PathBuf, log_path: &Path, publisher_address: Option
, - ) -> Arc { + ) -> Result> { let message_log = match config.storage { Storage::Memory => None, Storage::Disk => { let mlog_path = db_path.join("mlog"); - Some(Arc::new(Mutex::new(MessageLog::open(mlog_path).unwrap()))) + Some(Arc::new(Mutex::new(MessageLog::open(mlog_path)?))) } }; @@ -73,30 +80,29 @@ impl DatabaseInstanceContext { Storage::Memory => Box::::default(), Storage::Disk => { let odb_path = db_path.join("odb"); - DatabaseInstanceContext::make_default_ostorage(odb_path) + Self::make_default_ostorage(odb_path)? } }; let odb = Arc::new(Mutex::new(odb)); + let relational_db = RelationalDB::open(db_path, message_log, odb, address, config.fsync != FsyncPolicy::Never)?; - Arc::new(Self { + Ok(Arc::new(Self { database_instance_id, database_id, identity, address, logger: Arc::new(DatabaseLogger::open(log_path)), - relational_db: Arc::new( - RelationalDB::open(db_path, message_log, odb, address, config.fsync != FsyncPolicy::Never).unwrap(), - ), + relational_db: Arc::new(relational_db), publisher_address, - }) + })) } - pub(crate) fn make_default_ostorage(path: impl AsRef) -> Box { - Box::new(SledObjectDB::open(path).unwrap()) + pub(crate) fn make_default_ostorage(path: impl AsRef) -> Result> { + Ok(SledObjectDB::open(path).map(Box::new)?) } /// The number of bytes on disk occupied by the [MessageLog]. - pub fn message_log_size_on_disk(&self) -> Result { + pub fn message_log_size_on_disk(&self) -> std::result::Result { let size = self .relational_db .commit_log() @@ -107,7 +113,7 @@ impl DatabaseInstanceContext { } /// The number of bytes on disk occupied by the [ObjectDB]. - pub fn object_db_size_on_disk(&self) -> Result { + pub fn object_db_size_on_disk(&self) -> std::result::Result { let size = self .relational_db .commit_log() @@ -118,7 +124,7 @@ impl DatabaseInstanceContext { } /// The size of the log file. - pub fn log_file_size(&self) -> Result { + pub fn log_file_size(&self) -> std::result::Result { self.logger.size() } } diff --git a/crates/standalone/src/lib.rs b/crates/standalone/src/lib.rs index eeea6673801..9ae7a29b127 100644 --- a/crates/standalone/src/lib.rs +++ b/crates/standalone/src/lib.rs @@ -665,7 +665,7 @@ impl StandaloneEnv { let path = root_db_path.clone(); let config = self.config; move || -> anyhow::Result<_> { - let dbic = DatabaseInstanceContext::from_database(config, &database, instance_id, path); + let dbic = DatabaseInstanceContext::from_database(config, &database, instance_id, path)?; let sched = Scheduler::open(dbic.scheduler_db_path(root_db_path))?; Ok((dbic, sched)) }