From ca86588aa45c3f3a131215d60e60288a27929dfe Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Wed, 27 Nov 2024 16:39:56 +0800 Subject: [PATCH] determinsitic fallback sqlite Signed-off-by: Bugen Zhao --- src/risedevtool/src/task/meta_node_service.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/risedevtool/src/task/meta_node_service.rs b/src/risedevtool/src/task/meta_node_service.rs index 721f33573fa7d..53b8bb85ab974 100644 --- a/src/risedevtool/src/task/meta_node_service.rs +++ b/src/risedevtool/src/task/meta_node_service.rs @@ -20,7 +20,6 @@ use std::sync::LazyLock; use anyhow::{anyhow, bail, Context, Result}; use itertools::Itertools; use sqlx::{ConnectOptions, Database}; -use tempfile::NamedTempFile; use url::Url; use super::{risingwave_cmd, ExecuteContext, Task}; @@ -48,13 +47,19 @@ fn sql_endpoint_from_env() -> String { ); endpoint } else { - let temp_path = NamedTempFile::with_suffix(".db").unwrap().into_temp_path(); - let temp_sqlite_endpoint = format!("sqlite://{}?mode=rwc", temp_path.to_string_lossy()); + // `meta-backend: env` is specified, but env var is not set. + // Act as if `meta-backend: sqlite` is specified. + // Not using a temporary file because we want to persist the data across restarts. + let prefix_data = env::var("PREFIX_DATA").unwrap(); + let path = PathBuf::from(&prefix_data) + .join("meta-backend-env-fallback-sqlite") + .join("metadata.db"); + let sqlite_endpoint = format!("sqlite://{}?mode=rwc", path.to_string_lossy()); tracing::warn!( - "env RISEDEV_SQL_ENDPOINT not set, use temporary sqlite `{}`", - temp_sqlite_endpoint + "env RISEDEV_SQL_ENDPOINT not set, use fallback sqlite `{}`", + sqlite_endpoint ); - temp_sqlite_endpoint + sqlite_endpoint } });