Browse Source

incorperate feedback

merge-requests/114/head
Jonathan de Jong 5 years ago
parent
commit
6ad3108af2
  1. 2
      DEPLOY.md
  2. 2
      conduit-example.toml
  3. 2
      debian/postinst
  4. 28
      src/database.rs
  5. 3
      src/database/globals.rs

2
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 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. # 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 ## Setting the correct file permissions

2
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 proxy = "none" # more examples can be found at src/database/proxy.rs:6
# The total amount of memory that the database will use. # The total amount of memory that the database will use.
#db_cache_capacity_mb = 10 #db_cache_capacity_mb = 200

2
debian/postinst vendored

@ -78,7 +78,7 @@ max_request_size = 20_000_000 # in bytes
#workers = 4 # default: cpu core count * 2 #workers = 4 # default: cpu core count * 2
# The total amount of memory that the database will use. # The total amount of memory that the database will use.
#db_cache_capacity_mb = 10 #db_cache_capacity_mb = 200
EOF EOF
fi fi
;; ;;

28
src/database.rs

@ -47,7 +47,7 @@ pub struct Config {
db_cache_capacity_mb: f64, db_cache_capacity_mb: f64,
#[serde(default = "default_sqlite_read_pool_size")] #[serde(default = "default_sqlite_read_pool_size")]
sqlite_read_pool_size: usize, sqlite_read_pool_size: usize,
#[serde(default = "false_fn")] #[serde(default = "true_fn")]
sqlite_wal_clean_timer: bool, sqlite_wal_clean_timer: bool,
#[serde(default = "default_sqlite_wal_clean_second_interval")] #[serde(default = "default_sqlite_wal_clean_second_interval")]
sqlite_wal_clean_second_interval: u32, sqlite_wal_clean_second_interval: u32,
@ -106,7 +106,7 @@ fn true_fn() -> bool {
} }
fn default_db_cache_capacity_mb() -> f64 { fn default_db_cache_capacity_mb() -> f64 {
10.0 200.0
} }
fn default_sqlite_read_pool_size() -> usize { 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 { fn default_sqlite_wal_clean_second_interval() -> u32 {
60 60 * 60
} }
fn default_sqlite_wal_clean_second_timeout() -> u32 { fn default_sqlite_wal_clean_second_timeout() -> u32 {
@ -171,30 +171,36 @@ impl Database {
Ok(()) 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 path = Path::new(&config.database_path);
#[cfg(feature = "backend_sqlite")]
{
let sled_exists = path.join("db").exists(); let sled_exists = path.join("db").exists();
let sqlite_exists = path.join("conduit.db").exists(); let sqlite_exists = path.join("conduit.db").exists();
if sled_exists { if sled_exists {
if sqlite_exists { if sqlite_exists {
// most likely an in-place directory, only warn // most likely an in-place directory, only warn
log::warn!("both sled and sqlite databases are detected in database directory"); 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") log::warn!("Currently running from the sqlite database, but consider removing sled database files to free up space")
} else { } else {
log::error!( log::error!(
"sled database detected, conduit now uses sqlite for database operations" "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"); 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); return Err(Error::bad_config(
"sled database detected, migrate to sqlite",
));
} }
} }
} }
Ok(())
}
/// Load an existing database or create a new one. /// Load an existing database or create a new one.
pub async fn load_or_create(config: Config) -> Result<Arc<TokioRwLock<Self>>> { pub async fn load_or_create(config: Config) -> Result<Arc<TokioRwLock<Self>>> {
Self::check_sled_or_sqlite_db(&config); Self::check_sled_or_sqlite_db(&config)?;
let builder = Engine::open(&config)?; let builder = Engine::open(&config)?;

3
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<()>); pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>);
impl RotationHandler { impl RotationHandler {

Loading…
Cancel
Save