Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a random name for in-memory database and set cache to shared by default #595

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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