-
Notifications
You must be signed in to change notification settings - Fork 526
/
risingwave.rs
171 lines (133 loc) · 5.46 KB
/
risingwave.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2022 Singularity Data
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![cfg_attr(coverage, feature(no_coverage))]
#![feature(let_chains)]
use tikv_jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
use std::collections::HashMap;
use std::env;
use anyhow::{bail, Result};
use clap::StructOpt;
use risingwave_cmd_all::playground;
type RwFns = HashMap<&'static str, Box<dyn Fn(Vec<String>) -> Result<()>>>;
#[cfg_attr(coverage, no_coverage)]
fn main() -> Result<()> {
let mut fns: RwFns = HashMap::new();
// compute node configuration
for fn_name in ["compute", "compute-node", "compute_node"] {
fns.insert(
fn_name,
Box::new(|args: Vec<String>| {
eprintln!("launching compute node");
let opts = risingwave_compute::ComputeNodeOpts::parse_from(args);
risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new(
opts.enable_jaeger_tracing,
false,
));
risingwave_rt::main_okk(risingwave_compute::start(opts));
Ok(())
}),
);
}
// meta node configuration
for fn_name in ["meta", "meta-node", "meta_node"] {
fns.insert(
fn_name,
Box::new(move |args: Vec<String>| {
eprintln!("launching meta node");
let opts = risingwave_meta::MetaNodeOpts::parse_from(args);
risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new_default());
risingwave_rt::main_okk(risingwave_meta::start(opts));
Ok(())
}),
);
}
// frontend node configuration
for fn_name in ["frontend", "frontend-node", "frontend_node"] {
fns.insert(
fn_name,
Box::new(move |args: Vec<String>| {
eprintln!("launching frontend node");
let opts = risingwave_frontend::FrontendOpts::parse_from(args);
risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new_default());
risingwave_rt::main_okk(risingwave_frontend::start(opts));
Ok(())
}),
);
}
// frontend node configuration
for fn_name in ["compactor", "compactor-node", "compactor_node"] {
fns.insert(
fn_name,
Box::new(move |args: Vec<String>| {
eprintln!("launching compactor node");
let opts = risingwave_compactor::CompactorOpts::parse_from(args);
risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new_default());
risingwave_rt::main_okk(risingwave_compactor::start(opts));
Ok(())
}),
);
}
// risectl
fns.insert(
"risectl",
Box::new(move |args: Vec<String>| {
eprintln!("launching risectl");
let opts = risingwave_ctl::CliOpts::parse_from(args);
risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new_default());
risingwave_rt::main_okk(risingwave_ctl::start(opts))
}),
);
// playground
for fn_name in ["play", "playground"] {
fns.insert(
fn_name,
Box::new(move |_: Vec<String>| {
risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new_default());
// Enable tokio console for `./risedev p` by replacing the above statement to:
// risingwave_rt::init_risingwave_logger(risingwave_rt::LoggerSettings::new(false,
// true));
risingwave_rt::main_okk(playground())
}),
);
}
/// Get the launch target of this all-in-one binary
fn get_target(cmds: Vec<&str>) -> (String, Vec<String>) {
if let Some(cmd) = env::args().nth(1) && cmds.contains(&cmd.as_str()) {
// ./risingwave meta <args>
return (cmd, env::args().skip(1).collect());
}
if let Ok(target) = env::var("RW_NODE") {
// RW_NODE=meta ./risingwave <args>
(target, env::args().collect())
} else {
// ./meta-node <args>
let x = env::args().next().expect("cannot find argv[0]");
let x = x.rsplit('/').next().expect("cannot find binary name");
let target = x.to_string();
(target, env::args().collect())
}
}
let (target, args) = get_target(fns.keys().copied().collect());
match fns.remove(target.as_str()) {
Some(func) => {
func(args)?;
}
None => {
bail!("unknown target: {}\nPlease either:\n* set `RW_NODE` env variable (`RW_NODE=<component>`)\n* create a symbol link to `risingwave` binary (ln -s risingwave <component>)\n* start with subcommand `risingwave <component>``\nwith one of the following: {:?}", target, fns.keys().collect::<Vec<_>>());
}
}
Ok(())
}