Skip to content

Commit

Permalink
Generate a random name for in-memory database and set cache to shared…
Browse files Browse the repository at this point in the history
… by default (#595)

* Generate a random name for in-memory database

* Add entry to CHANGELOG.md

* Set cache to shared as we crash otherwise

* Actually, we know what the issue is now
  • Loading branch information
adzialocha committed Nov 16, 2023
1 parent efe445c commit 1d32831
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix `schema` tasks being triggered too often [#581](https://github.com/p2panda/aquadoggo/pull/581)
- Fix blobs getting corrupted when written to the file system [#587](https://github.com/p2panda/aquadoggo/pull/587)
- Fix pagination bug when only one field is selected and sorted at the same time [#593](https://github.com/p2panda/aquadoggo/pull/593)
- Fix SQLite in-memory database overwrite by giving them each a random name [#595](https://github.com/p2panda/aquadoggo/pull/595)

## [0.5.0]

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aquadoggo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ libp2p = "0.52.0"
log = "0.4.20"
p2panda-rs = "0.8.0"
path-clean = "1.0.1"
rand = "0.8.5"
serde = { version = "1.0.185", features = ["serde_derive"] }
tempfile = "3.7.0"
tokio = { version = "1.28.2", features = ["full"] }
Expand Down
21 changes: 19 additions & 2 deletions aquadoggo_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,25 @@ pub struct Configuration {

impl Default for Configuration {
fn default() -> Self {
let database_url = {
// Give each in-memory SQLite database an unique name as we're observing funny issues with
// SQLite sharing data between processes (!) and breaking each others databases
// potentially.
//
// See related issue: https://github.com/p2panda/aquadoggo/issues/568
let db_name = format!("dbmem{}", rand::random::<u32>());

// Set "mode=memory" to enable SQLite running in-memory and set "cache=shared", as
// setting it to "private" would break sqlx / SQLite.
//
// See related issue: https://github.com/launchbadge/sqlx/issues/2510
format!("sqlite://file:{db_name}?mode=memory&cache=shared")
};

Self {
log_level: "off".into(),
allow_schema_ids: UncheckedAllowList::Wildcard,
database_url: "sqlite::memory:".into(),
database_url,
database_max_connections: 32,
http_port: 2020,
quic_port: 2022,
Expand Down Expand Up @@ -471,7 +486,9 @@ pub fn print_config(
AllowList::Wildcard => format!("{WILDCARD} (any schema id)"),
};

let database_url = if config.database_url == "sqlite::memory:" {
let database_url = if config.database_url == "sqlite::memory:"
|| config.database_url.contains("mode=memory")
{
"memory (data is not persisted)".into()
} else if config.database_url.contains("sqlite:") {
format!("SQLite: {}", config.database_url)
Expand Down

0 comments on commit 1d32831

Please sign in to comment.