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

fix(meta): do not release connection to in-memory SQLite for meta store #19605

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
18 changes: 15 additions & 3 deletions src/meta/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,26 @@ pub struct SqlMetaStore {
pub endpoint: String,
}

pub const IN_MEMORY_STORE: &str = "sqlite::memory:";

impl SqlMetaStore {
/// Connect to the SQL meta store based on the given configuration.
pub async fn connect(backend: MetaStoreBackend) -> Result<Self, sea_orm::DbErr> {
Ok(match backend {
MetaStoreBackend::Mem => {
let conn = sea_orm::Database::connect(IN_MEMORY_STORE).await?;
const IN_MEMORY_STORE: &str = "sqlite::memory:";

let mut options = sea_orm::ConnectOptions::new(IN_MEMORY_STORE);
Copy link
Member

@fuyufjh fuyufjh Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more elegant solution might be "Temporary Databases"? No additional options are needed.

https://www.sqlite.org/inmemorydb.html (Scroll down to the "Temporary Databases" section)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary databases are automatically deleted when the connection that created them closes.

Seems that this still holds.

No additional options are needed.

Actually those options are for the connection pool by sqlx, not SQLite.


options
.max_connections(1)
.min_connections(1)
// Releasing the connection to in-memory SQLite database is unacceptable
// because it will clear the database. Set a large enough timeout to prevent it.
// `sqlx` actually supports disabling these timeouts by passing a `None`, but
// `sea-orm` does not expose this option.
.idle_timeout(Duration::MAX / 4)
.max_lifetime(Duration::MAX / 4);

let conn = sea_orm::Database::connect(options).await?;
Self {
conn,
endpoint: IN_MEMORY_STORE.to_owned(),
Expand Down
Loading