flush=false for database-backup in read-only/secondary modes; improve error

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-14 22:44:18 +00:00
parent 59834a4b05
commit 20836cc3db
3 changed files with 10 additions and 8 deletions

View File

@ -107,7 +107,7 @@ pub(super) async fn backup_database(&self) -> Result<RoomMessageEventContent> {
.runtime() .runtime()
.spawn_blocking(move || match globals.db.backup() { .spawn_blocking(move || match globals.db.backup() {
Ok(()) => String::new(), Ok(()) => String::new(),
Err(e) => (*e).to_string(), Err(e) => e.to_string(),
}) })
.await?; .await?;

View File

@ -17,6 +17,7 @@ use rocksdb::{
use crate::{ use crate::{
opts::{cf_options, db_options}, opts::{cf_options, db_options},
or_else, result, or_else, result,
util::map_err,
}; };
pub struct Engine { pub struct Engine {
@ -183,19 +184,20 @@ impl Engine {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { pub fn backup(&self) -> Result {
let config = &self.server.config; let config = &self.server.config;
let path = config.database_backup_path.as_ref(); let path = config.database_backup_path.as_ref();
if path.is_none() || path.is_some_and(|path| path.as_os_str().is_empty()) { if path.is_none() || path.is_some_and(|path| path.as_os_str().is_empty()) {
return Ok(()); return Ok(());
} }
let options = BackupEngineOptions::new(path.expect("valid database backup path"))?; let options = BackupEngineOptions::new(path.expect("valid database backup path")).map_err(map_err)?;
let mut engine = BackupEngine::open(&options, &self.env)?; let mut engine = BackupEngine::open(&options, &self.env).map_err(map_err)?;
if config.database_backups_to_keep > 0 { if config.database_backups_to_keep > 0 {
if let Err(e) = engine.create_new_backup_flush(&self.db, true) { let flush = !self.is_read_only();
return Err(Box::new(e)); engine
} .create_new_backup_flush(&self.db, flush)
.map_err(map_err)?;
let engine_info = engine.get_backup_info(); let engine_info = engine.get_backup_info();
let info = &engine_info.last().expect("backup engine info is not empty"); let info = &engine_info.last().expect("backup engine info is not empty");

View File

@ -73,7 +73,7 @@ impl Data {
} }
#[inline] #[inline]
pub fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { self.db.db.backup() } pub fn backup(&self) -> Result { self.db.db.backup() }
#[inline] #[inline]
pub fn backup_list(&self) -> Result<String> { self.db.db.backup_list() } pub fn backup_list(&self) -> Result<String> { self.db.db.backup_list() }