Skip to content

Commit

Permalink
fix(meta): do not release connection to in-memory SQLite for meta sto…
Browse files Browse the repository at this point in the history
…re (#19605)
  • Loading branch information
BugenZhao authored Dec 11, 2024
1 parent 67491ab commit 5954c98
Showing 1 changed file with 15 additions and 3 deletions.
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);

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

0 comments on commit 5954c98

Please sign in to comment.