diff --git a/ci/scripts/single-node-utils.sh b/ci/scripts/single-node-utils.sh index 4b19b2444f840..c4b49387aafc2 100755 --- a/ci/scripts/single-node-utils.sh +++ b/ci/scripts/single-node-utils.sh @@ -5,6 +5,7 @@ set -euo pipefail export RW_PREFIX=$PWD/.risingwave export PREFIX_BIN=./target/debug export PREFIX_LOG=$RW_PREFIX/log +export RISEDEV=1 # as if we are running in RiseDev # You can fill up this section by consulting # .risingwave/log/risedev.log, after calling `risedev d full`. @@ -13,11 +14,6 @@ start_single_node() { mkdir -p "$HOME/.risingwave/state_store" mkdir -p "$HOME/.risingwave/meta_store" mkdir -p .risingwave/config - cat < .risingwave/config/risedev-env -RW_META_ADDR="http://127.0.0.1:5690" -RISEDEV_RW_FRONTEND_LISTEN_ADDRESS="127.0.0.1" -RISEDEV_RW_FRONTEND_PORT="4566" -EOF RUST_BACKTRACE=1 "$PREFIX_BIN"/risingwave >"$1" 2>&1 } diff --git a/src/cmd_all/scripts/e2e-full-standalone-demo.sh b/src/cmd_all/scripts/e2e-full-standalone-demo.sh index 409c543e03afa..d3c8e10529f4c 100755 --- a/src/cmd_all/scripts/e2e-full-standalone-demo.sh +++ b/src/cmd_all/scripts/e2e-full-standalone-demo.sh @@ -61,13 +61,6 @@ STANDALONE_PID=$! sleep 15 -# FIXME: Integrate standalone into risedev, so we can reuse risedev-env functionality here. -cat << EOF > "$RW_PREFIX"/config/risedev-env -RW_META_ADDR="http://0.0.0.0:5690" -RISEDEV_RW_FRONTEND_LISTEN_ADDRESS="0.0.0.0" -RISEDEV_RW_FRONTEND_PORT="4566" -EOF - echo "--- Setting up table" ./risedev psql -c " CREATE TABLE t (v1 int); diff --git a/src/cmd_all/src/lib.rs b/src/cmd_all/src/lib.rs index a872d7de12b39..73180c75032ca 100644 --- a/src/cmd_all/src/lib.rs +++ b/src/cmd_all/src/lib.rs @@ -13,6 +13,7 @@ // limitations under the License. #![feature(lazy_cell)] +#![feature(let_chains)] mod common; mod standalone; diff --git a/src/cmd_all/src/standalone.rs b/src/cmd_all/src/standalone.rs index aac4bdff35d47..ceb890f4cb3af 100644 --- a/src/cmd_all/src/standalone.rs +++ b/src/cmd_all/src/standalone.rs @@ -12,10 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::env; +use std::fmt::Write; use std::future::Future; +use std::path::Path; use clap::Parser; use risingwave_common::config::MetaBackend; +use risingwave_common::util::env_var::env_var_is_true; use risingwave_common::util::meta_addr::MetaAddressStrategy; use risingwave_common::util::runtime::BackgroundShutdownRuntime; use risingwave_common::util::tokio_util::sync::CancellationToken; @@ -245,7 +249,7 @@ pub async fn standalone( ) { tracing::info!("launching Risingwave in standalone mode"); - let (meta, is_in_memory) = if let Some(opts) = meta_opts { + let (meta, is_in_memory) = if let Some(opts) = meta_opts.clone() { let is_in_memory = matches!(opts.backend, Some(MetaBackend::Mem)); tracing::info!("starting meta-node thread with cli args: {:?}", opts); let service = Service::spawn("meta", |shutdown| { @@ -319,11 +323,22 @@ It SHOULD NEVER be used in benchmarks and production environment!!!" ); } - if let Some(opts) = frontend_opts { + // This is a specialization of `generate_risedev_env` in `src/risedevtool/src/risedev_env.rs`. + let mut risedev_env = String::new(); + + if let Some(opts) = &frontend_opts { let host = opts.listen_addr.split(':').next().unwrap_or("localhost"); let port = opts.listen_addr.split(':').last().unwrap_or("4566"); let database = "dev"; let user = "root"; + + writeln!( + risedev_env, + r#"RISEDEV_RW_FRONTEND_LISTEN_ADDRESS="{host}""# + ) + .unwrap(); + writeln!(risedev_env, r#"RISEDEV_RW_FRONTEND_PORT="{port}""#).unwrap(); + eprintln!(); eprintln!("Connect to the RisingWave instance via psql:"); eprintln!( @@ -335,6 +350,20 @@ It SHOULD NEVER be used in benchmarks and production environment!!!" ); } + if let Some(opts) = &meta_opts { + let meta_addr = &opts.listen_addr; + writeln!(risedev_env, r#"RW_META_ADDR="http://{meta_addr}""#).unwrap(); + } + + // Create the environment file when launched by RiseDev. + if env_var_is_true("RISEDEV") { + let env_path = Path::new( + &env::var("PREFIX_CONFIG").expect("env var `PREFIX_CONFIG` must be set by RiseDev"), + ) + .join("risedev-env"); + std::fs::write(env_path, risedev_env).unwrap(); + } + let meta_stopped = meta .as_ref() .map(|m| m.shutdown.clone())