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. 44
      src/database.rs
  5. 3
      src/database/globals.rs

2
DEPLOY.md

@ -112,7 +112,7 @@ trusted_servers = ["matrix.org"] @@ -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

2
conduit-example.toml

@ -44,4 +44,4 @@ address = "127.0.0.1" # This makes sure Conduit can only be reached using the re @@ -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
#db_cache_capacity_mb = 200

2
debian/postinst vendored

@ -78,7 +78,7 @@ max_request_size = 20_000_000 # in bytes @@ -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
;;

44
src/database.rs

@ -47,7 +47,7 @@ pub struct Config { @@ -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 { @@ -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 { @@ -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 { @@ -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<Arc<TokioRwLock<Self>>> {
Self::check_sled_or_sqlite_db(&config);
Self::check_sled_or_sqlite_db(&config)?;
let builder = Engine::open(&config)?;

3
src/database/globals.rs

@ -84,6 +84,9 @@ impl ServerCertVerifier for MatrixServerVerifier { @@ -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 {

Loading…
Cancel
Save