diff --git a/DEPLOY.md b/DEPLOY.md index 60650f6..ba7a030 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -112,7 +112,7 @@ trusted_servers = ["matrix.org"] address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy # The total amount of memory that the database will use. -#db_cache_capacity_mb = 10 +#db_cache_capacity_mb = 200 ``` ## Setting the correct file permissions diff --git a/conduit-example.toml b/conduit-example.toml index 6fb4d5f..d184991 100644 --- a/conduit-example.toml +++ b/conduit-example.toml @@ -44,4 +44,4 @@ address = "127.0.0.1" # This makes sure Conduit can only be reached using the re proxy = "none" # more examples can be found at src/database/proxy.rs:6 # The total amount of memory that the database will use. -#db_cache_capacity_mb = 10 \ No newline at end of file +#db_cache_capacity_mb = 200 \ No newline at end of file diff --git a/debian/postinst b/debian/postinst index 79b7e73..824fd64 100644 --- a/debian/postinst +++ b/debian/postinst @@ -78,7 +78,7 @@ max_request_size = 20_000_000 # in bytes #workers = 4 # default: cpu core count * 2 # The total amount of memory that the database will use. -#db_cache_capacity_mb = 10 +#db_cache_capacity_mb = 200 EOF fi ;; diff --git a/src/database.rs b/src/database.rs index c498841..ac17372 100644 --- a/src/database.rs +++ b/src/database.rs @@ -47,7 +47,7 @@ pub struct Config { db_cache_capacity_mb: f64, #[serde(default = "default_sqlite_read_pool_size")] sqlite_read_pool_size: usize, - #[serde(default = "false_fn")] + #[serde(default = "true_fn")] sqlite_wal_clean_timer: bool, #[serde(default = "default_sqlite_wal_clean_second_interval")] sqlite_wal_clean_second_interval: u32, @@ -106,7 +106,7 @@ fn true_fn() -> bool { } fn default_db_cache_capacity_mb() -> f64 { - 10.0 + 200.0 } fn default_sqlite_read_pool_size() -> usize { @@ -114,7 +114,7 @@ fn default_sqlite_read_pool_size() -> usize { } fn default_sqlite_wal_clean_second_interval() -> u32 { - 60 + 60 * 60 } fn default_sqlite_wal_clean_second_timeout() -> u32 { @@ -171,30 +171,36 @@ impl Database { Ok(()) } - fn check_sled_or_sqlite_db(config: &Config) { + fn check_sled_or_sqlite_db(config: &Config) -> Result<()> { let path = Path::new(&config.database_path); - let sled_exists = path.join("db").exists(); - let sqlite_exists = path.join("conduit.db").exists(); - - if sled_exists { - if sqlite_exists { - // most likely an in-place directory, only warn - log::warn!("both sled and sqlite databases are detected in database directory"); - log::warn!("currently running from the sqlite database, but consider removing sled database files to free up space") - } else { - log::error!( - "sled database detected, conduit now uses sqlite for database operations" - ); - log::error!("this database must be converted to sqlite, go to https://github.com/ShadowJonathan/conduit_toolbox#conduit_sled_to_sqlite"); - std::process::exit(1); + #[cfg(feature = "backend_sqlite")] + { + let sled_exists = path.join("db").exists(); + let sqlite_exists = path.join("conduit.db").exists(); + if sled_exists { + if sqlite_exists { + // most likely an in-place directory, only warn + log::warn!("Both sled and sqlite databases are detected in database directory"); + log::warn!("Currently running from the sqlite database, but consider removing sled database files to free up space") + } else { + log::error!( + "Sled database detected, conduit now uses sqlite for database operations" + ); + log::error!("This database must be converted to sqlite, go to https://github.com/ShadowJonathan/conduit_toolbox#conduit_sled_to_sqlite"); + return Err(Error::bad_config( + "sled database detected, migrate to sqlite", + )); + } } } + + Ok(()) } /// Load an existing database or create a new one. pub async fn load_or_create(config: Config) -> Result>> { - Self::check_sled_or_sqlite_db(&config); + Self::check_sled_or_sqlite_db(&config)?; let builder = Engine::open(&config)?; diff --git a/src/database/globals.rs b/src/database/globals.rs index 7c53072..4242cf5 100644 --- a/src/database/globals.rs +++ b/src/database/globals.rs @@ -84,6 +84,9 @@ impl ServerCertVerifier for MatrixServerVerifier { } } +/// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like. +/// +/// This is utilized to have sync workers return early and release read locks on the database. pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>); impl RotationHandler {