Skip to content

Commit fcebf3d

Browse files
committed
refactor: move region_mover to builder
1 parent 3817a5f commit fcebf3d

3 files changed

Lines changed: 73 additions & 63 deletions

File tree

rust/operator-binary/src/controller/build/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ pub mod jvm;
66
pub mod kerberos;
77
pub mod opa;
88
pub mod properties;
9+
pub mod region_mover;
910
pub mod resource;
1011
pub mod role;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//! Build-side region-mover logic for [`AnyServiceConfig`]: derives the `bin/hbase` region-mover
2+
//! CLI arguments from the merged config. Kept out of the `crd` module so it stays a pure API
3+
//! definition.
4+
5+
use shell_escape::escape;
6+
use stackable_operator::shared::time::Duration;
7+
8+
use crate::crd::AnyServiceConfig;
9+
10+
const DEFAULT_REGION_MOVER_TIMEOUT: Duration = Duration::from_minutes_unchecked(59);
11+
const DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN: Duration = Duration::from_minutes_unchecked(1);
12+
13+
impl AnyServiceConfig {
14+
/// Returns command line arguments to pass on to the region mover tool.
15+
/// The following arguments are excluded because they are already part of the
16+
/// hbase-entrypoint.sh script.
17+
/// The most important argument, '--regionserverhost' can only be computed on the Pod
18+
/// because it contains the pod's hostname.
19+
///
20+
/// Returns an empty string if the region mover is disabled or any other role is "self".
21+
pub fn region_mover_args(&self) -> String {
22+
match self {
23+
AnyServiceConfig::RegionServer(config) => {
24+
if config.region_mover.run_before_shutdown {
25+
let timeout = config
26+
.graceful_shutdown_timeout
27+
.map(|d| {
28+
if d.as_secs() <= DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN.as_secs() {
29+
d.as_secs()
30+
} else {
31+
d.as_secs() - DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN.as_secs()
32+
}
33+
})
34+
.unwrap_or(DEFAULT_REGION_MOVER_TIMEOUT.as_secs());
35+
let mut command = vec![
36+
"--maxthreads".to_string(),
37+
config.region_mover.max_threads.to_string(),
38+
"--timeout".to_string(),
39+
timeout.to_string(),
40+
];
41+
if !config.region_mover.ack {
42+
command.push("--noack".to_string());
43+
}
44+
45+
command.extend(
46+
config
47+
.region_mover
48+
.cli_opts
49+
.iter()
50+
.flat_map(|o| o.additional_mover_options.clone())
51+
.map(|s| escape(std::borrow::Cow::Borrowed(&s)).to_string()),
52+
);
53+
command.join(" ")
54+
} else {
55+
"".to_string()
56+
}
57+
}
58+
_ => "".to_string(),
59+
}
60+
}
61+
62+
pub fn run_region_mover(&self) -> bool {
63+
match self {
64+
AnyServiceConfig::RegionServer(config) => config.region_mover.run_before_shutdown,
65+
_ => false,
66+
}
67+
}
68+
}

rust/operator-binary/src/crd/mod.rs

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use security::AuthenticationConfig;
22
use serde::{Deserialize, Serialize};
3-
use shell_escape::escape;
43
use stackable_operator::{
54
commons::{
65
affinity::StackableAffinity,
@@ -66,9 +65,6 @@ pub const HBASE_REST_METRICS_PORT: u16 = 8085;
6665
pub const LISTENER_VOLUME_NAME: &str = "listener";
6766
pub const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
6867

69-
const DEFAULT_REGION_MOVER_TIMEOUT: Duration = Duration::from_minutes_unchecked(59);
70-
const DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN: Duration = Duration::from_minutes_unchecked(1);
71-
7268
const DEFAULT_LISTENER_CLASS: &str = "cluster-internal";
7369

7470
fn default_hbase_rootdir() -> String {
@@ -462,17 +458,17 @@ pub struct HbaseConfig {
462458
)]
463459
pub struct RegionMover {
464460
/// Move local regions to other servers before terminating a region server's pod.
465-
run_before_shutdown: bool,
461+
pub run_before_shutdown: bool,
466462

467463
/// Maximum number of threads to use for moving regions.
468-
max_threads: u16,
464+
pub max_threads: u16,
469465

470466
/// If enabled (default), the region mover will confirm that regions are available on the
471467
/// source as well as the target pods before and after the move.
472-
ack: bool,
468+
pub ack: bool,
473469

474470
#[fragment_attrs(serde(flatten))]
475-
cli_opts: Option<RegionMoverExtraCliOpts>,
471+
pub cli_opts: Option<RegionMoverExtraCliOpts>,
476472
}
477473

478474
#[derive(Clone, Debug, Eq, Deserialize, JsonSchema, PartialEq, Serialize)]
@@ -602,61 +598,6 @@ impl AnyServiceConfig {
602598
AnyServiceConfig::RestServer(config) => config.hbase_rootdir.clone(),
603599
}
604600
}
605-
606-
/// Returns command line arguments to pass on to the region mover tool.
607-
/// The following arguments are excluded because they are already part of the
608-
/// hbase-entrypoint.sh script.
609-
/// The most important argument, '--regionserverhost' can only be computed on the Pod
610-
/// because it contains the pod's hostname.
611-
///
612-
/// Returns an empty string if the region mover is disabled or any other role is "self".
613-
pub fn region_mover_args(&self) -> String {
614-
match self {
615-
AnyServiceConfig::RegionServer(config) => {
616-
if config.region_mover.run_before_shutdown {
617-
let timeout = config
618-
.graceful_shutdown_timeout
619-
.map(|d| {
620-
if d.as_secs() <= DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN.as_secs() {
621-
d.as_secs()
622-
} else {
623-
d.as_secs() - DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN.as_secs()
624-
}
625-
})
626-
.unwrap_or(DEFAULT_REGION_MOVER_TIMEOUT.as_secs());
627-
let mut command = vec![
628-
"--maxthreads".to_string(),
629-
config.region_mover.max_threads.to_string(),
630-
"--timeout".to_string(),
631-
timeout.to_string(),
632-
];
633-
if !config.region_mover.ack {
634-
command.push("--noack".to_string());
635-
}
636-
637-
command.extend(
638-
config
639-
.region_mover
640-
.cli_opts
641-
.iter()
642-
.flat_map(|o| o.additional_mover_options.clone())
643-
.map(|s| escape(std::borrow::Cow::Borrowed(&s)).to_string()),
644-
);
645-
command.join(" ")
646-
} else {
647-
"".to_string()
648-
}
649-
}
650-
_ => "".to_string(),
651-
}
652-
}
653-
654-
pub fn run_region_mover(&self) -> bool {
655-
match self {
656-
AnyServiceConfig::RegionServer(config) => config.region_mover.run_before_shutdown,
657-
_ => false,
658-
}
659-
}
660601
}
661602

662603
#[cfg(test)]

0 commit comments

Comments
 (0)