From 5f5328bdd1d60b4a7c4f5ba35695c35da7e4e427 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 8 Dec 2023 08:43:41 -0600 Subject: [PATCH] Do not crash main process if acquiring KV backup engine fails --- src/store/kv.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/store/kv.rs b/src/store/kv.rs index 3533ac2..3378227 100644 --- a/src/store/kv.rs +++ b/src/store/kv.rs @@ -298,9 +298,13 @@ impl StoreKVPool { .map_err(|_| io_error!("database open failure"))?; // Initialize KV database backup engine - let backup_opts = DBBackupEngineOptions::new(&kv_backup_path).unwrap(); + let kv_backup_options = DBBackupEngineOptions::new(&kv_backup_path) + .map_err(|_| io_error!("backup engine options acquire failure"))?; + let kv_backup_environment = DBEnv::new() + .map_err(|_| io_error!("backup engine environment acquire failure"))?; + let mut kv_backup_engine = - DBBackupEngine::open(&backup_opts, &DBEnv::new().unwrap()) + DBBackupEngine::open(&kv_backup_options, &kv_backup_environment) .map_err(|_| io_error!("backup engine failure"))?; // Proceed actual KV database backup @@ -351,9 +355,13 @@ impl StoreKVPool { fs::create_dir_all(&kv_path)?; // Initialize KV database backup engine - let backup_opts = DBBackupEngineOptions::new(&origin_path).unwrap(); + let kv_backup_options = DBBackupEngineOptions::new(&origin_path) + .map_err(|_| io_error!("backup engine options acquire failure"))?; + let kv_backup_environment = DBEnv::new() + .map_err(|_| io_error!("backup engine environment acquire failure"))?; + let mut kv_backup_engine = - DBBackupEngine::open(&backup_opts, &DBEnv::new().unwrap()) + DBBackupEngine::open(&kv_backup_options, &kv_backup_environment) .map_err(|_| io_error!("backup engine failure"))?; kv_backup_engine