fix lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
fa942aedd7
commit
f7e8054a00
5 changed files with 28 additions and 40 deletions
|
@ -18,6 +18,7 @@ pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>>;
|
fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>>;
|
||||||
fn flush(&self) -> Result<()>;
|
fn flush(&self) -> Result<()>;
|
||||||
|
#[allow(dead_code)]
|
||||||
fn sync(&self) -> Result<()> { Ok(()) }
|
fn sync(&self) -> Result<()> { Ok(()) }
|
||||||
fn cleanup(&self) -> Result<()> { Ok(()) }
|
fn cleanup(&self) -> Result<()> { Ok(()) }
|
||||||
fn memory_usage(&self) -> Result<String> {
|
fn memory_usage(&self) -> Result<String> {
|
||||||
|
@ -27,13 +28,9 @@ pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn clear_caches(&self) {}
|
fn clear_caches(&self) {}
|
||||||
|
|
||||||
fn backup(&self) -> Result<(), Box<dyn Error>> {
|
fn backup(&self) -> Result<(), Box<dyn Error>> { unimplemented!() }
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn backup_list(&self) -> Result<String> {
|
fn backup_list(&self) -> Result<String> { Ok(String::new()) }
|
||||||
Ok(String::new())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait KvTree: Send + Sync {
|
pub(crate) trait KvTree: Send + Sync {
|
||||||
|
@ -57,6 +54,8 @@ pub(crate) trait KvTree: Send + Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove(&self, key: &[u8]) -> Result<()>;
|
fn remove(&self, key: &[u8]) -> Result<()>;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn remove_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()> {
|
fn remove_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()> {
|
||||||
for key in iter {
|
for key in iter {
|
||||||
self.remove(&key)?;
|
self.remove(&key)?;
|
||||||
|
|
|
@ -3,11 +3,8 @@ use std::{
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
use chrono::{
|
|
||||||
DateTime,
|
|
||||||
Utc,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use rust_rocksdb::{
|
use rust_rocksdb::{
|
||||||
backup::{BackupEngine, BackupEngineOptions},
|
backup::{BackupEngine, BackupEngineOptions},
|
||||||
LogLevel::{Debug, Error, Fatal, Info, Warn},
|
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_optimize_filters_for_memory(true);
|
||||||
block_based_options.set_cache_index_and_filter_blocks(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_pin_top_level_index_and_filter(true);
|
||||||
block_based_options.set_block_cache(&col_cache);
|
block_based_options.set_block_cache(col_cache);
|
||||||
db_opts.set_row_cache(&row_cache);
|
db_opts.set_row_cache(row_cache);
|
||||||
|
|
||||||
// Buffers
|
// Buffers
|
||||||
db_opts.set_write_buffer_size(2 * 1024 * 1024);
|
db_opts.set_write_buffer_size(2 * 1024 * 1024);
|
||||||
|
@ -232,7 +229,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = BackupEngineOptions::new(&path.unwrap())?;
|
let options = BackupEngineOptions::new(path.unwrap())?;
|
||||||
let mut engine = BackupEngine::open(&options, &self.env)?;
|
let mut engine = BackupEngine::open(&options, &self.env)?;
|
||||||
let ret = if self.config.database_backups_to_keep > 0 {
|
let ret = if self.config.database_backups_to_keep > 0 {
|
||||||
match engine.create_new_backup_flush(&self.rocks, true) {
|
match engine.create_new_backup_flush(&self.rocks, true) {
|
||||||
|
@ -242,9 +239,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
|
||||||
let info = &_info.last().unwrap();
|
let info = &_info.last().unwrap();
|
||||||
info!(
|
info!(
|
||||||
"Created database backup #{} using {} bytes in {} files",
|
"Created database backup #{} using {} bytes in {} files",
|
||||||
info.backup_id,
|
info.backup_id, info.size, info.num_files,
|
||||||
info.size,
|
|
||||||
info.num_files,
|
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
@ -255,7 +250,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
|
||||||
|
|
||||||
if self.config.database_backups_to_keep >= 0 {
|
if self.config.database_backups_to_keep >= 0 {
|
||||||
let keep = u32::try_from(self.config.database_backups_to_keep)?;
|
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())
|
error!("Failed to purge old backup: {:?}", e.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,18 +265,19 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
let options = BackupEngineOptions::new(&path.unwrap())?;
|
let options = BackupEngineOptions::new(path.unwrap())?;
|
||||||
let engine = BackupEngine::open(&options, &self.env)?;
|
let engine = BackupEngine::open(&options, &self.env)?;
|
||||||
for info in engine.get_backup_info() {
|
for info in engine.get_backup_info() {
|
||||||
std::fmt::write(&mut res, format_args!(
|
std::fmt::write(
|
||||||
"#{} {}: {} bytes, {} files\n",
|
&mut res,
|
||||||
info.backup_id,
|
format_args!(
|
||||||
DateTime::<Utc>::from_timestamp(info.timestamp, 0)
|
"#{} {}: {} bytes, {} files\n",
|
||||||
.unwrap()
|
info.backup_id,
|
||||||
.to_rfc2822(),
|
DateTime::<Utc>::from_timestamp(info.timestamp, 0).unwrap().to_rfc2822(),
|
||||||
info.size,
|
info.size,
|
||||||
info.num_files,
|
info.num_files,
|
||||||
))
|
),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,11 +273,7 @@ lasttimelinecount_cache: {lasttimelinecount_cache}\n"
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup(&self) -> Result<(), Box<dyn std::error::Error>> {
|
fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { self.db.backup() }
|
||||||
self.db.backup()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn backup_list(&self) -> Result<String> {
|
fn backup_list(&self) -> Result<String> { self.db.backup_list() }
|
||||||
self.db.backup_list()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1878,11 +1878,9 @@ impl Service {
|
||||||
RoomMessageEventContent::text_plain(result)
|
RoomMessageEventContent::text_plain(result)
|
||||||
},
|
},
|
||||||
ServerCommand::BackupDatabase => {
|
ServerCommand::BackupDatabase => {
|
||||||
let mut result = tokio::task::spawn_blocking(move || {
|
let mut result = tokio::task::spawn_blocking(move || match services().globals.db.backup() {
|
||||||
match services().globals.db.backup() {
|
Ok(_) => String::new(),
|
||||||
Ok(_) => String::new(),
|
Err(e) => (*e).to_string(),
|
||||||
Err(e) => (*e).to_string(),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::BTreeMap;
|
use std::{collections::BTreeMap, error::Error};
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue