more useful database logging (compaction, time taken to load)

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-02-19 19:24:08 -05:00 committed by June
parent ce1aae7abc
commit 3d26210eac
3 changed files with 11 additions and 2 deletions

View file

@ -7,6 +7,7 @@ use std::{
}; };
use rocksdb::LogLevel::{Debug, Error, Fatal, Info, Warn}; use rocksdb::LogLevel::{Debug, Error, Fatal, Info, Warn};
use tracing::debug;
pub(crate) struct Engine { pub(crate) struct Engine {
rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>, rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>,
@ -98,12 +99,15 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
let db_opts = db_options(&rocksdb_cache, config); let db_opts = db_options(&rocksdb_cache, config);
debug!("Listing column families in database");
let cfs = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::list_cf( let cfs = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::list_cf(
&db_opts, &db_opts,
&config.database_path, &config.database_path,
) )
.unwrap_or_default(); .unwrap_or_default();
debug!("Opening column family descriptors in database");
info!("RocksDB database compaction will take place now, a delay in startup is expected");
let db = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::open_cf_descriptors( let db = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::open_cf_descriptors(
&db_opts, &db_opts,
&config.database_path, &config.database_path,
@ -123,6 +127,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>> { fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>> {
if !self.old_cfs.contains(&name.to_owned()) { if !self.old_cfs.contains(&name.to_owned()) {
// Create if it didn't exist // Create if it didn't exist
debug!("Creating new column family in database: {}", name);
let _ = self let _ = self
.rocks .rocks
.create_cf(name, &db_options(&self.cache, &self.config)); .create_cf(name, &db_options(&self.cache, &self.config));

View file

@ -222,20 +222,23 @@ impl KeyValueDatabase {
Self::check_db_setup(&config)?; Self::check_db_setup(&config)?;
if !Path::new(&config.database_path).exists() { if !Path::new(&config.database_path).exists() {
debug!("Database path does not exist, assuming this is a new setup and creating it");
std::fs::create_dir_all(&config.database_path) std::fs::create_dir_all(&config.database_path)
.map_err(|e| { .map_err(|e| {
error!("Failed to create database path: {e}"); error!("Failed to create database path: {e}");
Error::BadConfig("Database folder doesn't exists and couldn't be created (e.g. due to missing permissions). Please create the database folder yourself.")})?; Error::BadConfig("Database folder doesn't exists and couldn't be created (e.g. due to missing permissions). Please create the database folder yourself or allow conduwuit the permissions to create directories and files.")})?;
} }
let builder: Arc<dyn KeyValueDatabaseEngine> = match &*config.database_backend { let builder: Arc<dyn KeyValueDatabaseEngine> = match &*config.database_backend {
"sqlite" => { "sqlite" => {
debug!("Got sqlite database backend");
#[cfg(not(feature = "sqlite"))] #[cfg(not(feature = "sqlite"))]
return Err(Error::BadConfig("Database backend not found.")); return Err(Error::BadConfig("Database backend not found."));
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
Arc::new(Arc::<abstraction::sqlite::Engine>::open(&config)?) Arc::new(Arc::<abstraction::sqlite::Engine>::open(&config)?)
} }
"rocksdb" => { "rocksdb" => {
debug!("Got rocksdb database backend");
#[cfg(not(feature = "rocksdb"))] #[cfg(not(feature = "rocksdb"))]
return Err(Error::BadConfig("Database backend not found.")); return Err(Error::BadConfig("Database backend not found."));
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]
@ -1053,7 +1056,6 @@ impl KeyValueDatabase {
Ok(()) Ok(())
} }
#[tracing::instrument(skip(self))]
pub fn flush(&self) -> Result<()> { pub fn flush(&self) -> Result<()> {
let start = std::time::Instant::now(); let start = std::time::Instant::now();

View file

@ -144,10 +144,12 @@ async fn main() {
}; };
info!("Loading database"); info!("Loading database");
let db_load_time = std::time::Instant::now();
if let Err(error) = KeyValueDatabase::load_or_create(config).await { if let Err(error) = KeyValueDatabase::load_or_create(config).await {
error!(?error, "The database couldn't be loaded or created"); error!(?error, "The database couldn't be loaded or created");
return; return;
}; };
info!("Database took {:?} to load", db_load_time.elapsed());
let config = &services().globals.config; let config = &services().globals.config;