diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index 5f6e6000b2c1696b2edf27184458f6f08fb55e2f..0fabb3ce6ed8c2f84a79d3425ff88f517c7ebf26 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -18,6 +18,7 @@ fn open(config: &Config) -> Result<Self> Self: Sized; fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>>; fn flush(&self) -> Result<()>; + #[allow(dead_code)] fn sync(&self) -> Result<()> { Ok(()) } fn cleanup(&self) -> Result<()> { Ok(()) } fn memory_usage(&self) -> Result<String> { @@ -27,13 +28,9 @@ fn memory_usage(&self) -> Result<String> { #[allow(dead_code)] fn clear_caches(&self) {} - fn backup(&self) -> Result<(), Box<dyn Error>> { - unimplemented!() - } + fn backup(&self) -> Result<(), Box<dyn Error>> { unimplemented!() } - fn backup_list(&self) -> Result<String> { - Ok(String::new()) - } + fn backup_list(&self) -> Result<String> { Ok(String::new()) } } pub(crate) trait KvTree: Send + Sync { @@ -57,6 +54,8 @@ fn insert_batch(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Re } fn remove(&self, key: &[u8]) -> Result<()>; + + #[allow(dead_code)] fn remove_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()> { for key in iter { self.remove(&key)?; diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 5487cc4224ca1f3dd6e3b2cac2e683f2d1664b5c..22f422fb270849a027b2d6e6b3be4a28d531605d 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -3,11 +3,8 @@ pin::Pin, sync::{Arc, RwLock}, }; -use chrono::{ - DateTime, - Utc, -}; +use chrono::{DateTime, Utc}; use rust_rocksdb::{ backup::{BackupEngine, BackupEngineOptions}, LogLevel::{Debug, Error, Fatal, Info, Warn}, @@ -80,8 +77,8 @@ fn db_options( block_based_options.set_optimize_filters_for_memory(true); block_based_options.set_cache_index_and_filter_blocks(true); block_based_options.set_pin_top_level_index_and_filter(true); - block_based_options.set_block_cache(&col_cache); - db_opts.set_row_cache(&row_cache); + block_based_options.set_block_cache(col_cache); + db_opts.set_row_cache(row_cache); // Buffers db_opts.set_write_buffer_size(2 * 1024 * 1024); @@ -232,7 +229,7 @@ fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { return Ok(()); } - let options = BackupEngineOptions::new(&path.unwrap())?; + let options = BackupEngineOptions::new(path.unwrap())?; let mut engine = BackupEngine::open(&options, &self.env)?; let ret = if self.config.database_backups_to_keep > 0 { match engine.create_new_backup_flush(&self.rocks, true) { @@ -242,9 +239,7 @@ fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { let info = &_info.last().unwrap(); info!( "Created database backup #{} using {} bytes in {} files", - info.backup_id, - info.size, - info.num_files, + info.backup_id, info.size, info.num_files, ); Ok(()) }, @@ -255,7 +250,7 @@ fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { if self.config.database_backups_to_keep >= 0 { let keep = u32::try_from(self.config.database_backups_to_keep)?; - if let Err(e) = engine.purge_old_backups(keep.try_into()?) { + if let Err(e) = engine.purge_old_backups(keep.try_into()?) { error!("Failed to purge old backup: {:?}", e.to_string()) } } @@ -270,18 +265,19 @@ fn backup_list(&self) -> Result<String> { } let mut res = String::new(); - let options = BackupEngineOptions::new(&path.unwrap())?; + let options = BackupEngineOptions::new(path.unwrap())?; let engine = BackupEngine::open(&options, &self.env)?; for info in engine.get_backup_info() { - std::fmt::write(&mut res, format_args!( - "#{} {}: {} bytes, {} files\n", - info.backup_id, - DateTime::<Utc>::from_timestamp(info.timestamp, 0) - .unwrap() - .to_rfc2822(), - info.size, - info.num_files, - )) + std::fmt::write( + &mut res, + format_args!( + "#{} {}: {} bytes, {} files\n", + info.backup_id, + DateTime::<Utc>::from_timestamp(info.timestamp, 0).unwrap().to_rfc2822(), + info.size, + info.num_files, + ), + ) .unwrap(); } diff --git a/src/database/key_value/globals.rs b/src/database/key_value/globals.rs index 273442facc6115b0846d88c5d05675ed6fcf8421..55ebed4a23699e27dee18de7d2bdac8adff824d6 100644 --- a/src/database/key_value/globals.rs +++ b/src/database/key_value/globals.rs @@ -273,11 +273,7 @@ fn bump_database_version(&self, new_version: u64) -> Result<()> { Ok(()) } - fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { - self.db.backup() - } + fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { self.db.backup() } - fn backup_list(&self) -> Result<String> { - self.db.backup_list() - } + fn backup_list(&self) -> Result<String> { self.db.backup_list() } } diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 11fc58c1551940290f62ef67a55ca0c2ce5e8032..2250ddb68c0cd53abc4e1994e8b4cc4281028933 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -1878,11 +1878,9 @@ async fn process_admin_command(&self, command: AdminCommand, body: Vec<&str>) -> RoomMessageEventContent::text_plain(result) }, ServerCommand::BackupDatabase => { - let mut result = tokio::task::spawn_blocking(move || { - match services().globals.db.backup() { - Ok(_) => String::new(), - Err(e) => (*e).to_string(), - } + let mut result = tokio::task::spawn_blocking(move || match services().globals.db.backup() { + Ok(_) => String::new(), + Err(e) => (*e).to_string(), }) .await .unwrap(); diff --git a/src/service/globals/data.rs b/src/service/globals/data.rs index a9cda9e12d188da61ed4b542c00cde29b2118408..8322c1aa845fd343f57c30af4e77fd3277f2f52e 100644 --- a/src/service/globals/data.rs +++ b/src/service/globals/data.rs @@ -1,5 +1,4 @@ -use std::collections::BTreeMap; -use std::error::Error; +use std::{collections::BTreeMap, error::Error}; use async_trait::async_trait; use ruma::{