Skip to content

Commit 4865ed6

Browse files
feat: modify the scale command to support both horizontal and vertical scaling. (#12087) (#12091)
1 parent 616edbd commit 4865ed6

File tree

2 files changed

+113
-22
lines changed

2 files changed

+113
-22
lines changed

src/ctl/src/cmd_impl/scale/resize.rs

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use serde_yaml;
2727

2828
use crate::cmd_impl::meta::ReschedulePayload;
2929
use crate::common::CtlContext;
30-
use crate::ScaleResizeCommands;
30+
use crate::{ScaleCommon, ScaleHorizonCommands, ScaleVerticalCommands};
3131

3232
macro_rules! fail {
3333
($($arg:tt)*) => {{
@@ -36,8 +36,74 @@ macro_rules! fail {
3636
}};
3737
}
3838

39-
pub async fn resize(context: &CtlContext, resize: ScaleResizeCommands) -> anyhow::Result<()> {
40-
let meta_client = context.meta_client().await?;
39+
impl From<ScaleHorizonCommands> for ScaleCommandContext {
40+
fn from(value: ScaleHorizonCommands) -> Self {
41+
let ScaleHorizonCommands {
42+
exclude_workers,
43+
include_workers,
44+
target_parallelism,
45+
common:
46+
ScaleCommon {
47+
generate,
48+
output,
49+
yes,
50+
fragments,
51+
},
52+
} = value;
53+
54+
Self {
55+
exclude_workers,
56+
include_workers,
57+
target_parallelism,
58+
generate,
59+
output,
60+
yes,
61+
fragments,
62+
target_parallelism_per_worker: None,
63+
}
64+
}
65+
}
66+
67+
impl From<ScaleVerticalCommands> for ScaleCommandContext {
68+
fn from(value: ScaleVerticalCommands) -> Self {
69+
let ScaleVerticalCommands {
70+
workers,
71+
target_parallelism_per_worker,
72+
common:
73+
ScaleCommon {
74+
generate,
75+
output,
76+
yes,
77+
fragments,
78+
},
79+
} = value;
80+
81+
Self {
82+
exclude_workers: None,
83+
include_workers: workers,
84+
target_parallelism: None,
85+
generate,
86+
output,
87+
yes,
88+
fragments,
89+
target_parallelism_per_worker,
90+
}
91+
}
92+
}
93+
94+
pub struct ScaleCommandContext {
95+
exclude_workers: Option<Vec<String>>,
96+
include_workers: Option<Vec<String>>,
97+
target_parallelism: Option<u32>,
98+
generate: bool,
99+
output: Option<String>,
100+
yes: bool,
101+
fragments: Option<Vec<u32>>,
102+
target_parallelism_per_worker: Option<u32>,
103+
}
104+
105+
pub async fn resize(ctl_ctx: &CtlContext, scale_ctx: ScaleCommandContext) -> anyhow::Result<()> {
106+
let meta_client = ctl_ctx.meta_client().await?;
41107

42108
let GetClusterInfoResponse {
43109
worker_nodes,
@@ -116,7 +182,7 @@ pub async fn resize(context: &CtlContext, resize: ScaleResizeCommands) -> anyhow
116182
streaming_workers_index_by_id.len()
117183
);
118184

119-
let ScaleResizeCommands {
185+
let ScaleCommandContext {
120186
exclude_workers,
121187
include_workers,
122188
target_parallelism,
@@ -125,7 +191,7 @@ pub async fn resize(context: &CtlContext, resize: ScaleResizeCommands) -> anyhow
125191
output,
126192
yes,
127193
fragments,
128-
} = resize;
194+
} = scale_ctx;
129195

130196
let worker_changes = {
131197
let exclude_worker_ids =

src/ctl/src/lib.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ enum TableCommands {
261261
List,
262262
}
263263

264-
#[derive(clap::Args, Debug)]
265-
#[clap(group(clap::ArgGroup::new("workers_group").required(true).multiple(true).args(&["include_workers", "exclude_workers", "target_parallelism"])))]
266-
pub struct ScaleResizeCommands {
264+
#[derive(clap::Args, Debug, Clone)]
265+
pub struct ScaleHorizonCommands {
267266
/// The worker that needs to be excluded during scheduling, worker_id and worker_host are both
268267
/// supported
269268
#[clap(
@@ -288,15 +287,12 @@ pub struct ScaleResizeCommands {
288287
#[clap(long)]
289288
target_parallelism: Option<u32>,
290289

291-
/// The target parallelism per worker, conflicts with `target_parallelism`, requires
292-
/// `include_workers` to be set.
293-
#[clap(
294-
long,
295-
requires = "include_workers",
296-
conflicts_with = "target_parallelism"
297-
)]
298-
target_parallelism_per_worker: Option<u32>,
290+
#[command(flatten)]
291+
common: ScaleCommon,
292+
}
299293

294+
#[derive(clap::Args, Debug, Clone)]
295+
pub struct ScaleCommon {
300296
/// Will generate a plan supported by the `reschedule` command and save it to the provided path
301297
/// by the `--output`.
302298
#[clap(long, default_value_t = false)]
@@ -316,12 +312,37 @@ pub struct ScaleResizeCommands {
316312
fragments: Option<Vec<u32>>,
317313
}
318314

315+
#[derive(clap::Args, Debug, Clone)]
316+
pub struct ScaleVerticalCommands {
317+
#[command(flatten)]
318+
common: ScaleCommon,
319+
320+
/// The worker that needs to be scheduled, worker_id and worker_host are both
321+
/// supported
322+
#[clap(
323+
long,
324+
value_delimiter = ',',
325+
value_name = "all or worker_id or worker_host, ..."
326+
)]
327+
workers: Option<Vec<String>>,
328+
329+
/// The target parallelism per worker, requires `workers` to be set.
330+
#[clap(long, requires = "workers")]
331+
target_parallelism_per_worker: Option<u32>,
332+
}
333+
319334
#[derive(Subcommand, Debug)]
320335
enum ScaleCommands {
321-
/// The resize command scales the cluster by specifying the workers to be included and
322-
/// excluded.
323-
Resize(ScaleResizeCommands),
324-
/// mark a compute node as unschedulable
336+
/// Scale the compute nodes horizontally, alias of `horizon`
337+
Resize(ScaleHorizonCommands),
338+
339+
/// Scale the compute nodes horizontally
340+
Horizon(ScaleHorizonCommands),
341+
342+
/// Scale the compute nodes vertically
343+
Vertical(ScaleVerticalCommands),
344+
345+
/// Mark a compute node as unschedulable
325346
#[clap(verbatim_doc_comment)]
326347
Cordon {
327348
/// Workers that need to be cordoned, both id and host are supported.
@@ -616,8 +637,12 @@ pub async fn start_impl(opts: CliOpts, context: &CtlContext) -> Result<()> {
616637
Commands::Profile(ProfileCommands::Heap { dir }) => {
617638
cmd_impl::profile::heap_profile(context, dir).await?
618639
}
619-
Commands::Scale(ScaleCommands::Resize(resize)) => {
620-
cmd_impl::scale::resize(context, resize).await?
640+
Commands::Scale(ScaleCommands::Horizon(resize))
641+
| Commands::Scale(ScaleCommands::Resize(resize)) => {
642+
cmd_impl::scale::resize(context, resize.into()).await?
643+
}
644+
Commands::Scale(ScaleCommands::Vertical(resize)) => {
645+
cmd_impl::scale::resize(context, resize.into()).await?
621646
}
622647
Commands::Scale(ScaleCommands::Cordon { workers }) => {
623648
cmd_impl::scale::update_schedulability(context, workers, Schedulability::Unschedulable)

0 commit comments

Comments
 (0)