Skip to content

Commit

Permalink
flatten opts into string args
Browse files Browse the repository at this point in the history
  • Loading branch information
kwannoel committed Mar 8, 2024
1 parent f183eca commit 0d0bb84
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/cmd_all/src/bin/risingwave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn standalone(opts: StandaloneOpts) {
/// We will start a standalone instance, with all nodes in the same process.
fn single_node(opts: SingleNodeOpts) {
opts.create_store_directories().unwrap();
let opts = risingwave_cmd_all::map_single_node_opts_to_standalone_opts(&opts);
let opts = risingwave_cmd_all::normalized_single_node_opts(&opts);
let settings = risingwave_rt::LoggerSettings::from_opts(&opts)
.with_target("risingwave_storage", Level::WARN)
.with_thread_name(true);
Expand Down
4 changes: 0 additions & 4 deletions src/cmd_all/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

use std::ffi::OsString;

pub fn osstrs_from_iter<T: Into<OsString>>(s: impl IntoIterator<Item = T>) -> Vec<OsString> {
s.into_iter().map(Into::into).collect()
}

pub fn osstrs<T: Into<OsString> + AsRef<std::ffi::OsStr>>(s: impl AsRef<[T]>) -> Vec<OsString> {
s.as_ref().iter().map(OsString::from).collect()
}
Expand Down
35 changes: 27 additions & 8 deletions src/cmd_all/src/single_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use risingwave_frontend::FrontendOpts;
use risingwave_meta_node::MetaNodeOpts;
use shell_words::split;

use crate::common::osstrs;
use crate::ParsedStandaloneOpts;

pub static DEFAULT_STORE_DIRECTORY: LazyLock<String> = LazyLock::new(|| {
Expand Down Expand Up @@ -120,10 +121,10 @@ pub struct SingleNodeOpts {
}

struct NormalizedSingleNodeOpts {
frontend_opts: Option<RawOpts>,
meta_opts: Option<RawOpts>,
compute_opts: Option<RawOpts>,
compactor_opts: Option<RawOpts>,
frontend_opts: Option<FrontendOpts>,
meta_opts: Option<MetaNodeOpts>,
compute_opts: Option<ComputeNodeOpts>,
compactor_opts: Option<CompactorOpts>,
}

pub fn make_single_node_sql_endpoint(store_directory: &String) -> String {
Expand All @@ -141,7 +142,7 @@ pub fn map_single_node_opts_to_standalone_opts(opts: &SingleNodeOpts) -> ParsedS
todo!()
}

pub fn normalized_single_node_opts(opts: &SingleNodeOpts) -> NormalizedSingleNodeOpts {
pub fn normalized_single_node_opts(opts: &SingleNodeOpts) -> ParsedStandaloneOpts {
let mut meta_opts = RawOpts::default_meta_opts();
let mut compute_opts = RawOpts::default_compute_opts();
let mut frontend_opts = RawOpts::default_frontend_opts();
Expand Down Expand Up @@ -242,26 +243,32 @@ pub fn normalized_single_node_opts(opts: &SingleNodeOpts) -> NormalizedSingleNod
let frontend_opts = if opts.disable_frontend {
None
} else {
let args = frontend_opts.raw_opts_to_args();
let frontend_opts = FrontendOpts::parse_from(osstrs(args));
Some(frontend_opts)
};
let meta_opts = if opts.disable_meta {
None
} else {
// let mut meta_opts = meta_opts.map(|o| MetaNodeOpts::parse_from(osstrs(o)));

let args = meta_opts.raw_opts_to_args();
let meta_opts = MetaNodeOpts::parse_from(osstrs(args));
Some(meta_opts)
};
let compute_opts = if opts.disable_compute {
None
} else {
let args = compute_opts.raw_opts_to_args();
let compute_opts = ComputeNodeOpts::parse_from(osstrs(args));
Some(compute_opts)
};
let compactor_opts = if opts.disable_compactor {
None
} else {
let args = compactor_opts.raw_opts_to_args();
let compactor_opts = CompactorOpts::parse_from(osstrs(args));
Some(compactor_opts)
};
NormalizedSingleNodeOpts {
ParsedStandaloneOpts {
frontend_opts,
meta_opts,
compute_opts,
Expand Down Expand Up @@ -397,6 +404,18 @@ impl RawOpts {
opts: inner,
}
}

fn raw_opts_to_args(self) -> Vec<String> {
let mut args = vec![];
for (k, v) in self.opts {
args.push(k.clone());
args.push(v.clone());
}
for f in self.flags {
args.push(f.clone());
}
args
}
}

// Defaults
Expand Down

0 comments on commit 0d0bb84

Please sign in to comment.