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(standalone): write risedev-env file in standalone mode #17870

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions ci/scripts/single-node-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

PREFIX_CONFIG is not set


# You can fill up this section by consulting
# .risingwave/log/risedev.log, after calling `risedev d full`.
Expand All @@ -13,11 +14,6 @@ start_single_node() {
mkdir -p "$HOME/.risingwave/state_store"
mkdir -p "$HOME/.risingwave/meta_store"
mkdir -p .risingwave/config
cat <<EOF > .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
}

Expand Down
7 changes: 0 additions & 7 deletions src/cmd_all/scripts/e2e-full-standalone-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/cmd_all/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#![feature(lazy_cell)]
#![feature(let_chains)]

mod common;
mod standalone;
Expand Down
33 changes: 31 additions & 2 deletions src/cmd_all/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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!(
Expand All @@ -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())
Expand Down
Loading