Skip to content

Commit

Permalink
refactor(cmd_all): refactor playground to use `single_node --in-memor…
Browse files Browse the repository at this point in the history
…y` internally (#15897)
  • Loading branch information
kwannoel authored Mar 26, 2024
1 parent f292e7b commit 1e84852
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 294 deletions.
20 changes: 9 additions & 11 deletions src/cmd_all/src/bin/risingwave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use anyhow::Result;
use clap::error::ErrorKind;
use clap::{command, ArgMatches, Args, Command, FromArgMatches};
use risingwave_cmd::{compactor, compute, ctl, frontend, meta};
use risingwave_cmd_all::{PlaygroundOpts, SingleNodeOpts, StandaloneOpts};
use risingwave_cmd_all::{SingleNodeOpts, StandaloneOpts};
use risingwave_common::git_sha;
use risingwave_compactor::CompactorOpts;
use risingwave_compute::ComputeNodeOpts;
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Component {
Self::Frontend => frontend(parse_opts(matches)),
Self::Compactor => compactor(parse_opts(matches)),
Self::Ctl => ctl(parse_opts(matches)),
Self::Playground => playground(parse_opts(matches)),
Self::Playground => single_node(SingleNodeOpts::new_for_playground()),
Self::Standalone => standalone(parse_opts(matches)),
Self::SingleNode => single_node(parse_opts(matches)),
}
Expand Down Expand Up @@ -151,7 +151,7 @@ impl Component {
Component::Frontend => FrontendOpts::augment_args(cmd),
Component::Compactor => CompactorOpts::augment_args(cmd),
Component::Ctl => CtlOpts::augment_args(cmd),
Component::Playground => PlaygroundOpts::augment_args(cmd),
Component::Playground => cmd,
Component::Standalone => StandaloneOpts::augment_args(cmd),
Component::SingleNode => SingleNodeOpts::augment_args(cmd),
}
Expand All @@ -161,8 +161,14 @@ impl Component {
fn commands() -> Vec<Command> {
Self::iter()
.map(|c| {
let is_playground = matches!(c, Component::Playground);
let name: &'static str = c.into();
let command = Command::new(name).visible_aliases(c.aliases());
let command = if is_playground {
command.hide(true)
} else {
command
};
c.augment_args(command)
})
.collect()
Expand Down Expand Up @@ -221,14 +227,6 @@ fn main() -> Result<()> {
Ok(())
}

fn playground(opts: PlaygroundOpts) {
let settings = risingwave_rt::LoggerSettings::from_opts(&opts)
.with_target("risingwave_storage", Level::WARN)
.with_thread_name(true);
risingwave_rt::init_risingwave_logger(settings);
risingwave_rt::main_okk(risingwave_cmd_all::playground(opts)).unwrap();
}

fn standalone(opts: StandaloneOpts) {
let opts = risingwave_cmd_all::parse_standalone_opt_args(&opts);
let settings = risingwave_rt::LoggerSettings::from_opts(&opts)
Expand Down
20 changes: 0 additions & 20 deletions src/cmd_all/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,3 @@ use std::ffi::OsString;
pub fn osstrs<T: Into<OsString> + AsRef<std::ffi::OsStr>>(s: impl AsRef<[T]>) -> Vec<OsString> {
s.as_ref().iter().map(OsString::from).collect()
}

pub enum RisingWaveService {
Compute(Vec<OsString>),
Meta(Vec<OsString>),
Frontend(Vec<OsString>),
#[allow(dead_code)]
Compactor(Vec<OsString>),
}

impl RisingWaveService {
/// Extend additional arguments to the service.
pub fn extend_args(&mut self, args: &[&str]) {
match self {
RisingWaveService::Compute(args0)
| RisingWaveService::Meta(args0)
| RisingWaveService::Frontend(args0)
| RisingWaveService::Compactor(args0) => args0.extend(args.iter().map(|s| s.into())),
}
}
}
2 changes: 0 additions & 2 deletions src/cmd_all/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
#![feature(lazy_cell)]

mod common;
pub mod playground;
mod standalone;

pub mod single_node;

pub use playground::*;
pub use single_node::*;
pub use standalone::*;

Expand Down
260 changes: 0 additions & 260 deletions src/cmd_all/src/playground.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/cmd_all/src/single_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ pub struct SingleNodeOpts {
node_opts: NodeSpecificOpts,
}

impl SingleNodeOpts {
pub fn new_for_playground() -> Self {
let empty_args = vec![] as Vec<String>;
let mut opts = SingleNodeOpts::parse_from(empty_args);
opts.in_memory = true;
opts
}
}

/// # Node-Specific Options
///
/// ## Which node-specific options should be here?
Expand Down
Loading

0 comments on commit 1e84852

Please sign in to comment.