From 8e6c87d39fd27c6b1b752448bacae81b74dda704 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 11 Oct 2024 14:29:40 +0800 Subject: [PATCH] refactor(meta): use in-memory sqlite for `Mem` meta backend Signed-off-by: Bugen Zhao --- src/cmd_all/src/single_node.rs | 4 +++- src/meta/node/src/lib.rs | 14 +++++++++++++- src/meta/src/backup_restore/utils.rs | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cmd_all/src/single_node.rs b/src/cmd_all/src/single_node.rs index 5495be878202b..a84fd0470a5be 100644 --- a/src/cmd_all/src/single_node.rs +++ b/src/cmd_all/src/single_node.rs @@ -182,7 +182,9 @@ pub fn map_single_node_opts_to_standalone_opts(opts: SingleNodeOpts) -> ParsedSt }; if !meta_backend_is_set { if opts.in_memory { - meta_opts.backend = Some(MetaBackend::Mem); + meta_opts.backend = Some(MetaBackend::Sqlite); + meta_opts.sql_endpoint = + Some("meta_backend?mode=memory&cache=shared".to_owned().into()); } else { meta_opts.backend = Some(MetaBackend::Sqlite); let meta_store_dir = format!("{}/meta_store", &store_directory); diff --git a/src/meta/node/src/lib.rs b/src/meta/node/src/lib.rs index 633093b2c7024..e26ffd915ac80 100644 --- a/src/meta/node/src/lib.rs +++ b/src/meta/node/src/lib.rs @@ -271,10 +271,22 @@ pub fn start( }, MetaBackend::Sqlite => MetaStoreBackend::Sql { endpoint: format!( - "sqlite://{}?mode=rwc", + "sqlite://{}{}", opts.sql_endpoint + .as_ref() .expect("sql endpoint is required") + .expose_secret(), + if opts + .sql_endpoint + .as_ref() + .unwrap() .expose_secret() + .contains("mode=memory") + { + "" + } else { + "?mode=rwc" + } ), }, MetaBackend::Postgres => MetaStoreBackend::Sql { diff --git a/src/meta/src/backup_restore/utils.rs b/src/meta/src/backup_restore/utils.rs index 4c4c9a336b449..1c588f3a9fcd8 100644 --- a/src/meta/src/backup_restore/utils.rs +++ b/src/meta/src/backup_restore/utils.rs @@ -66,7 +66,7 @@ pub async fn get_meta_store(opts: RestoreOpts) -> BackupResult MetaStoreBackend::Sql { - endpoint: format!("sqlite://{}?mode=rwc", opts.sql_endpoint), + endpoint: format!("sqlite://{}", opts.sql_endpoint), }, MetaBackend::Postgres => MetaStoreBackend::Sql { endpoint: format!(