Line data Source code
1 : //!
2 : //! `neon_local` is an executable that can be used to create a local
3 : //! Neon environment, for testing purposes. The local environment is
4 : //! quite different from the cloud environment with Kubernetes, but it
5 : //! easier to work with locally. The python tests in `test_runner`
6 : //! rely on `neon_local` to set up the environment for each test.
7 : //!
8 : use anyhow::{anyhow, bail, Context, Result};
9 : use clap::{value_parser, Arg, ArgAction, ArgMatches, Command, ValueEnum};
10 : use compute_api::spec::ComputeMode;
11 : use control_plane::endpoint::ComputeControlPlane;
12 : use control_plane::local_env::{
13 : InitForceMode, LocalEnv, NeonBroker, NeonLocalInitConf, NeonLocalInitPageserverConf,
14 : SafekeeperConf,
15 : };
16 : use control_plane::pageserver::PageServerNode;
17 : use control_plane::safekeeper::SafekeeperNode;
18 : use control_plane::storage_controller::StorageController;
19 : use control_plane::{broker, local_env};
20 : use pageserver_api::config::{
21 : DEFAULT_HTTP_LISTEN_PORT as DEFAULT_PAGESERVER_HTTP_PORT,
22 : DEFAULT_PG_LISTEN_PORT as DEFAULT_PAGESERVER_PG_PORT,
23 : };
24 : use pageserver_api::controller_api::{PlacementPolicy, TenantCreateRequest};
25 : use pageserver_api::models::{ShardParameters, TimelineCreateRequest, TimelineInfo};
26 : use pageserver_api::shard::{ShardCount, ShardStripeSize, TenantShardId};
27 : use postgres_backend::AuthType;
28 : use postgres_connection::parse_host_port;
29 : use safekeeper_api::{
30 : DEFAULT_HTTP_LISTEN_PORT as DEFAULT_SAFEKEEPER_HTTP_PORT,
31 : DEFAULT_PG_LISTEN_PORT as DEFAULT_SAFEKEEPER_PG_PORT,
32 : };
33 : use std::collections::{BTreeSet, HashMap};
34 : use std::path::PathBuf;
35 : use std::process::exit;
36 : use std::str::FromStr;
37 : use std::time::Duration;
38 : use storage_broker::DEFAULT_LISTEN_ADDR as DEFAULT_BROKER_ADDR;
39 : use url::Host;
40 : use utils::{
41 : auth::{Claims, Scope},
42 : id::{NodeId, TenantId, TenantTimelineId, TimelineId},
43 : lsn::Lsn,
44 : project_git_version,
45 : };
46 :
47 : // Default id of a safekeeper node, if not specified on the command line.
48 : const DEFAULT_SAFEKEEPER_ID: NodeId = NodeId(1);
49 : const DEFAULT_PAGESERVER_ID: NodeId = NodeId(1);
50 : const DEFAULT_BRANCH_NAME: &str = "main";
51 : project_git_version!(GIT_VERSION);
52 :
53 : const DEFAULT_PG_VERSION: &str = "15";
54 :
55 : const DEFAULT_PAGESERVER_CONTROL_PLANE_API: &str = "http://127.0.0.1:1234/upcall/v1/";
56 :
57 : ///
58 : /// Timelines tree element used as a value in the HashMap.
59 : ///
60 : struct TimelineTreeEl {
61 : /// `TimelineInfo` received from the `pageserver` via the `timeline_list` http API call.
62 : pub info: TimelineInfo,
63 : /// Name, recovered from neon config mappings
64 : pub name: Option<String>,
65 : /// Holds all direct children of this timeline referenced using `timeline_id`.
66 : pub children: BTreeSet<TimelineId>,
67 : }
68 :
69 : // Main entry point for the 'neon_local' CLI utility
70 : //
71 : // This utility helps to manage neon installation. That includes following:
72 : // * Management of local postgres installations running on top of the
73 : // pageserver.
74 : // * Providing CLI api to the pageserver
75 : // * TODO: export/import to/from usual postgres
76 0 : fn main() -> Result<()> {
77 0 : let matches = cli().get_matches();
78 :
79 0 : let (sub_name, sub_args) = match matches.subcommand() {
80 0 : Some(subcommand_data) => subcommand_data,
81 0 : None => bail!("no subcommand provided"),
82 : };
83 :
84 : // Check for 'neon init' command first.
85 0 : let subcommand_result = if sub_name == "init" {
86 0 : handle_init(sub_args).map(Some)
87 : } else {
88 : // all other commands need an existing config
89 0 : let mut env =
90 0 : LocalEnv::load_config(&local_env::base_path()).context("Error loading config")?;
91 0 : let original_env = env.clone();
92 0 :
93 0 : let rt = tokio::runtime::Builder::new_current_thread()
94 0 : .enable_all()
95 0 : .build()
96 0 : .unwrap();
97 :
98 0 : let subcommand_result = match sub_name {
99 0 : "tenant" => rt.block_on(handle_tenant(sub_args, &mut env)),
100 0 : "timeline" => rt.block_on(handle_timeline(sub_args, &mut env)),
101 0 : "start" => rt.block_on(handle_start_all(&env, get_start_timeout(sub_args))),
102 0 : "stop" => rt.block_on(handle_stop_all(sub_args, &env)),
103 0 : "pageserver" => rt.block_on(handle_pageserver(sub_args, &env)),
104 0 : "storage_controller" => rt.block_on(handle_storage_controller(sub_args, &env)),
105 0 : "safekeeper" => rt.block_on(handle_safekeeper(sub_args, &env)),
106 0 : "endpoint" => rt.block_on(handle_endpoint(sub_args, &env)),
107 0 : "mappings" => handle_mappings(sub_args, &mut env),
108 0 : "pg" => bail!("'pg' subcommand has been renamed to 'endpoint'"),
109 0 : _ => bail!("unexpected subcommand {sub_name}"),
110 : };
111 :
112 0 : if original_env != env {
113 0 : subcommand_result.map(|()| Some(env))
114 : } else {
115 0 : subcommand_result.map(|()| None)
116 : }
117 : };
118 :
119 0 : match subcommand_result {
120 0 : Ok(Some(updated_env)) => updated_env.persist_config()?,
121 0 : Ok(None) => (),
122 0 : Err(e) => {
123 0 : eprintln!("command failed: {e:?}");
124 0 : exit(1);
125 : }
126 : }
127 0 : Ok(())
128 0 : }
129 :
130 : ///
131 : /// Prints timelines list as a tree-like structure.
132 : ///
133 0 : fn print_timelines_tree(
134 0 : timelines: Vec<TimelineInfo>,
135 0 : mut timeline_name_mappings: HashMap<TenantTimelineId, String>,
136 0 : ) -> Result<()> {
137 0 : let mut timelines_hash = timelines
138 0 : .iter()
139 0 : .map(|t| {
140 0 : (
141 0 : t.timeline_id,
142 0 : TimelineTreeEl {
143 0 : info: t.clone(),
144 0 : children: BTreeSet::new(),
145 0 : name: timeline_name_mappings
146 0 : .remove(&TenantTimelineId::new(t.tenant_id.tenant_id, t.timeline_id)),
147 0 : },
148 0 : )
149 0 : })
150 0 : .collect::<HashMap<_, _>>();
151 :
152 : // Memorize all direct children of each timeline.
153 0 : for timeline in timelines.iter() {
154 0 : if let Some(ancestor_timeline_id) = timeline.ancestor_timeline_id {
155 0 : timelines_hash
156 0 : .get_mut(&ancestor_timeline_id)
157 0 : .context("missing timeline info in the HashMap")?
158 : .children
159 0 : .insert(timeline.timeline_id);
160 0 : }
161 : }
162 :
163 0 : for timeline in timelines_hash.values() {
164 : // Start with root local timelines (no ancestors) first.
165 0 : if timeline.info.ancestor_timeline_id.is_none() {
166 0 : print_timeline(0, &Vec::from([true]), timeline, &timelines_hash)?;
167 0 : }
168 : }
169 :
170 0 : Ok(())
171 0 : }
172 :
173 : ///
174 : /// Recursively prints timeline info with all its children.
175 : ///
176 0 : fn print_timeline(
177 0 : nesting_level: usize,
178 0 : is_last: &[bool],
179 0 : timeline: &TimelineTreeEl,
180 0 : timelines: &HashMap<TimelineId, TimelineTreeEl>,
181 0 : ) -> Result<()> {
182 0 : if nesting_level > 0 {
183 0 : let ancestor_lsn = match timeline.info.ancestor_lsn {
184 0 : Some(lsn) => lsn.to_string(),
185 0 : None => "Unknown Lsn".to_string(),
186 : };
187 :
188 0 : let mut br_sym = "┣━";
189 0 :
190 0 : // Draw each nesting padding with proper style
191 0 : // depending on whether its timeline ended or not.
192 0 : if nesting_level > 1 {
193 0 : for l in &is_last[1..is_last.len() - 1] {
194 0 : if *l {
195 0 : print!(" ");
196 0 : } else {
197 0 : print!("┃ ");
198 0 : }
199 : }
200 0 : }
201 :
202 : // We are the last in this sub-timeline
203 0 : if *is_last.last().unwrap() {
204 0 : br_sym = "┗━";
205 0 : }
206 :
207 0 : print!("{} @{}: ", br_sym, ancestor_lsn);
208 0 : }
209 :
210 : // Finally print a timeline id and name with new line
211 0 : println!(
212 0 : "{} [{}]",
213 0 : timeline.name.as_deref().unwrap_or("_no_name_"),
214 0 : timeline.info.timeline_id
215 0 : );
216 0 :
217 0 : let len = timeline.children.len();
218 0 : let mut i: usize = 0;
219 0 : let mut is_last_new = Vec::from(is_last);
220 0 : is_last_new.push(false);
221 :
222 0 : for child in &timeline.children {
223 0 : i += 1;
224 0 :
225 0 : // Mark that the last padding is the end of the timeline
226 0 : if i == len {
227 0 : if let Some(last) = is_last_new.last_mut() {
228 0 : *last = true;
229 0 : }
230 0 : }
231 :
232 : print_timeline(
233 0 : nesting_level + 1,
234 0 : &is_last_new,
235 0 : timelines
236 0 : .get(child)
237 0 : .context("missing timeline info in the HashMap")?,
238 0 : timelines,
239 0 : )?;
240 : }
241 :
242 0 : Ok(())
243 0 : }
244 :
245 : /// Returns a map of timeline IDs to timeline_id@lsn strings.
246 : /// Connects to the pageserver to query this information.
247 0 : async fn get_timeline_infos(
248 0 : env: &local_env::LocalEnv,
249 0 : tenant_shard_id: &TenantShardId,
250 0 : ) -> Result<HashMap<TimelineId, TimelineInfo>> {
251 0 : Ok(get_default_pageserver(env)
252 0 : .timeline_list(tenant_shard_id)
253 0 : .await?
254 0 : .into_iter()
255 0 : .map(|timeline_info| (timeline_info.timeline_id, timeline_info))
256 0 : .collect())
257 0 : }
258 :
259 : // Helper function to parse --tenant_id option, or get the default from config file
260 0 : fn get_tenant_id(sub_match: &ArgMatches, env: &local_env::LocalEnv) -> anyhow::Result<TenantId> {
261 0 : if let Some(tenant_id_from_arguments) = parse_tenant_id(sub_match).transpose() {
262 0 : tenant_id_from_arguments
263 0 : } else if let Some(default_id) = env.default_tenant_id {
264 0 : Ok(default_id)
265 : } else {
266 0 : anyhow::bail!("No tenant id. Use --tenant-id, or set a default tenant");
267 : }
268 0 : }
269 :
270 : // Helper function to parse --tenant_id option, for commands that accept a shard suffix
271 0 : fn get_tenant_shard_id(
272 0 : sub_match: &ArgMatches,
273 0 : env: &local_env::LocalEnv,
274 0 : ) -> anyhow::Result<TenantShardId> {
275 0 : if let Some(tenant_id_from_arguments) = parse_tenant_shard_id(sub_match).transpose() {
276 0 : tenant_id_from_arguments
277 0 : } else if let Some(default_id) = env.default_tenant_id {
278 0 : Ok(TenantShardId::unsharded(default_id))
279 : } else {
280 0 : anyhow::bail!("No tenant shard id. Use --tenant-id, or set a default tenant");
281 : }
282 0 : }
283 :
284 0 : fn parse_tenant_id(sub_match: &ArgMatches) -> anyhow::Result<Option<TenantId>> {
285 0 : sub_match
286 0 : .get_one::<String>("tenant-id")
287 0 : .map(|tenant_id| TenantId::from_str(tenant_id))
288 0 : .transpose()
289 0 : .context("Failed to parse tenant id from the argument string")
290 0 : }
291 :
292 0 : fn parse_tenant_shard_id(sub_match: &ArgMatches) -> anyhow::Result<Option<TenantShardId>> {
293 0 : sub_match
294 0 : .get_one::<String>("tenant-id")
295 0 : .map(|id_str| TenantShardId::from_str(id_str))
296 0 : .transpose()
297 0 : .context("Failed to parse tenant shard id from the argument string")
298 0 : }
299 :
300 0 : fn parse_timeline_id(sub_match: &ArgMatches) -> anyhow::Result<Option<TimelineId>> {
301 0 : sub_match
302 0 : .get_one::<String>("timeline-id")
303 0 : .map(|timeline_id| TimelineId::from_str(timeline_id))
304 0 : .transpose()
305 0 : .context("Failed to parse timeline id from the argument string")
306 0 : }
307 :
308 0 : fn handle_init(init_match: &ArgMatches) -> anyhow::Result<LocalEnv> {
309 0 : let num_pageservers = init_match.get_one::<u16>("num-pageservers");
310 0 :
311 0 : let force = init_match.get_one("force").expect("we set a default value");
312 :
313 : // Create the in-memory `LocalEnv` that we'd normally load from disk in `load_config`.
314 0 : let init_conf: NeonLocalInitConf = if let Some(config_path) =
315 0 : init_match.get_one::<PathBuf>("config")
316 : {
317 : // User (likely the Python test suite) provided a description of the environment.
318 0 : if num_pageservers.is_some() {
319 0 : bail!("Cannot specify both --num-pageservers and --config, use key `pageservers` in the --config file instead");
320 0 : }
321 : // load and parse the file
322 0 : let contents = std::fs::read_to_string(config_path).with_context(|| {
323 0 : format!(
324 0 : "Could not read configuration file '{}'",
325 0 : config_path.display()
326 0 : )
327 0 : })?;
328 0 : toml_edit::de::from_str(&contents)?
329 : } else {
330 : // User (likely interactive) did not provide a description of the environment, give them the default
331 0 : NeonLocalInitConf {
332 0 : control_plane_api: Some(Some(DEFAULT_PAGESERVER_CONTROL_PLANE_API.parse().unwrap())),
333 0 : broker: NeonBroker {
334 0 : listen_addr: DEFAULT_BROKER_ADDR.parse().unwrap(),
335 0 : },
336 0 : safekeepers: vec![SafekeeperConf {
337 0 : id: DEFAULT_SAFEKEEPER_ID,
338 0 : pg_port: DEFAULT_SAFEKEEPER_PG_PORT,
339 0 : http_port: DEFAULT_SAFEKEEPER_HTTP_PORT,
340 0 : ..Default::default()
341 0 : }],
342 0 : pageservers: (0..num_pageservers.copied().unwrap_or(1))
343 0 : .map(|i| {
344 0 : let pageserver_id = NodeId(DEFAULT_PAGESERVER_ID.0 + i as u64);
345 0 : let pg_port = DEFAULT_PAGESERVER_PG_PORT + i;
346 0 : let http_port = DEFAULT_PAGESERVER_HTTP_PORT + i;
347 0 : NeonLocalInitPageserverConf {
348 0 : id: pageserver_id,
349 0 : listen_pg_addr: format!("127.0.0.1:{pg_port}"),
350 0 : listen_http_addr: format!("127.0.0.1:{http_port}"),
351 0 : pg_auth_type: AuthType::Trust,
352 0 : http_auth_type: AuthType::Trust,
353 0 : other: Default::default(),
354 0 : }
355 0 : })
356 0 : .collect(),
357 0 : pg_distrib_dir: None,
358 0 : neon_distrib_dir: None,
359 0 : default_tenant_id: TenantId::from_array(std::array::from_fn(|_| 0)),
360 0 : storage_controller: None,
361 0 : control_plane_compute_hook_api: None,
362 0 : }
363 : };
364 :
365 0 : LocalEnv::init(init_conf, force)
366 0 : .context("materialize initial neon_local environment on disk")?;
367 0 : Ok(LocalEnv::load_config(&local_env::base_path())
368 0 : .expect("freshly written config should be loadable"))
369 0 : }
370 :
371 : /// The default pageserver is the one where CLI tenant/timeline operations are sent by default.
372 : /// For typical interactive use, one would just run with a single pageserver. Scenarios with
373 : /// tenant/timeline placement across multiple pageservers are managed by python test code rather
374 : /// than this CLI.
375 0 : fn get_default_pageserver(env: &local_env::LocalEnv) -> PageServerNode {
376 0 : let ps_conf = env
377 0 : .pageservers
378 0 : .first()
379 0 : .expect("Config is validated to contain at least one pageserver");
380 0 : PageServerNode::from_env(env, ps_conf)
381 0 : }
382 :
383 0 : async fn handle_tenant(
384 0 : tenant_match: &ArgMatches,
385 0 : env: &mut local_env::LocalEnv,
386 0 : ) -> anyhow::Result<()> {
387 0 : let pageserver = get_default_pageserver(env);
388 0 : match tenant_match.subcommand() {
389 0 : Some(("list", _)) => {
390 0 : for t in pageserver.tenant_list().await? {
391 0 : println!("{} {:?}", t.id, t.state);
392 0 : }
393 : }
394 0 : Some(("import", import_match)) => {
395 0 : let tenant_id = parse_tenant_id(import_match)?.unwrap_or_else(TenantId::generate);
396 0 :
397 0 : let storage_controller = StorageController::from_env(env);
398 0 : let create_response = storage_controller.tenant_import(tenant_id).await?;
399 :
400 0 : let shard_zero = create_response
401 0 : .shards
402 0 : .first()
403 0 : .expect("Import response omitted shards");
404 0 :
405 0 : let attached_pageserver_id = shard_zero.node_id;
406 0 : let pageserver =
407 0 : PageServerNode::from_env(env, env.get_pageserver_conf(attached_pageserver_id)?);
408 :
409 0 : println!(
410 0 : "Imported tenant {tenant_id}, attached to pageserver {attached_pageserver_id}"
411 0 : );
412 :
413 0 : let timelines = pageserver
414 0 : .http_client
415 0 : .list_timelines(shard_zero.shard_id)
416 0 : .await?;
417 :
418 : // Pick a 'main' timeline that has no ancestors, the rest will get arbitrary names
419 0 : let main_timeline = timelines
420 0 : .iter()
421 0 : .find(|t| t.ancestor_timeline_id.is_none())
422 0 : .expect("No timelines found")
423 0 : .timeline_id;
424 0 :
425 0 : let mut branch_i = 0;
426 0 : for timeline in timelines.iter() {
427 0 : let branch_name = if timeline.timeline_id == main_timeline {
428 0 : "main".to_string()
429 : } else {
430 0 : branch_i += 1;
431 0 : format!("branch_{branch_i}")
432 : };
433 :
434 0 : println!(
435 0 : "Importing timeline {tenant_id}/{} as branch {branch_name}",
436 0 : timeline.timeline_id
437 0 : );
438 0 :
439 0 : env.register_branch_mapping(branch_name, tenant_id, timeline.timeline_id)?;
440 : }
441 : }
442 0 : Some(("create", create_match)) => {
443 0 : let tenant_conf: HashMap<_, _> = create_match
444 0 : .get_many::<String>("config")
445 0 : .map(|vals: clap::parser::ValuesRef<'_, String>| {
446 0 : vals.flat_map(|c| c.split_once(':')).collect()
447 0 : })
448 0 : .unwrap_or_default();
449 0 :
450 0 : let shard_count: u8 = create_match
451 0 : .get_one::<u8>("shard-count")
452 0 : .cloned()
453 0 : .unwrap_or(0);
454 0 :
455 0 : let shard_stripe_size: Option<u32> =
456 0 : create_match.get_one::<u32>("shard-stripe-size").cloned();
457 :
458 0 : let placement_policy = match create_match.get_one::<String>("placement-policy") {
459 0 : Some(s) if !s.is_empty() => serde_json::from_str::<PlacementPolicy>(s)?,
460 0 : _ => PlacementPolicy::Attached(0),
461 : };
462 :
463 0 : let tenant_conf = PageServerNode::parse_config(tenant_conf)?;
464 :
465 : // If tenant ID was not specified, generate one
466 0 : let tenant_id = parse_tenant_id(create_match)?.unwrap_or_else(TenantId::generate);
467 0 :
468 0 : // We must register the tenant with the storage controller, so
469 0 : // that when the pageserver restarts, it will be re-attached.
470 0 : let storage_controller = StorageController::from_env(env);
471 0 : storage_controller
472 0 : .tenant_create(TenantCreateRequest {
473 0 : // Note that ::unsharded here isn't actually because the tenant is unsharded, its because the
474 0 : // storage controller expecfs a shard-naive tenant_id in this attribute, and the TenantCreateRequest
475 0 : // type is used both in storage controller (for creating tenants) and in pageserver (for creating shards)
476 0 : new_tenant_id: TenantShardId::unsharded(tenant_id),
477 0 : generation: None,
478 0 : shard_parameters: ShardParameters {
479 0 : count: ShardCount::new(shard_count),
480 0 : stripe_size: shard_stripe_size
481 0 : .map(ShardStripeSize)
482 0 : .unwrap_or(ShardParameters::DEFAULT_STRIPE_SIZE),
483 0 : },
484 0 : placement_policy: Some(placement_policy),
485 0 : config: tenant_conf,
486 0 : })
487 0 : .await?;
488 0 : println!("tenant {tenant_id} successfully created on the pageserver");
489 :
490 : // Create an initial timeline for the new tenant
491 0 : let new_timeline_id =
492 0 : parse_timeline_id(create_match)?.unwrap_or(TimelineId::generate());
493 0 : let pg_version = create_match
494 0 : .get_one::<u32>("pg-version")
495 0 : .copied()
496 0 : .context("Failed to parse postgres version from the argument string")?;
497 :
498 : // FIXME: passing None for ancestor_start_lsn is not kosher in a sharded world: we can't have
499 : // different shards picking different start lsns. Maybe we have to teach storage controller
500 : // to let shard 0 branch first and then propagate the chosen LSN to other shards.
501 0 : storage_controller
502 0 : .tenant_timeline_create(
503 0 : tenant_id,
504 0 : TimelineCreateRequest {
505 0 : new_timeline_id,
506 0 : ancestor_timeline_id: None,
507 0 : ancestor_start_lsn: None,
508 0 : existing_initdb_timeline_id: None,
509 0 : pg_version: Some(pg_version),
510 0 : },
511 0 : )
512 0 : .await?;
513 :
514 0 : env.register_branch_mapping(
515 0 : DEFAULT_BRANCH_NAME.to_string(),
516 0 : tenant_id,
517 0 : new_timeline_id,
518 0 : )?;
519 :
520 0 : println!("Created an initial timeline '{new_timeline_id}' for tenant: {tenant_id}",);
521 0 :
522 0 : if create_match.get_flag("set-default") {
523 0 : println!("Setting tenant {tenant_id} as a default one");
524 0 : env.default_tenant_id = Some(tenant_id);
525 0 : }
526 : }
527 0 : Some(("set-default", set_default_match)) => {
528 0 : let tenant_id =
529 0 : parse_tenant_id(set_default_match)?.context("No tenant id specified")?;
530 0 : println!("Setting tenant {tenant_id} as a default one");
531 0 : env.default_tenant_id = Some(tenant_id);
532 : }
533 0 : Some(("config", create_match)) => {
534 0 : let tenant_id = get_tenant_id(create_match, env)?;
535 0 : let tenant_conf: HashMap<_, _> = create_match
536 0 : .get_many::<String>("config")
537 0 : .map(|vals| vals.flat_map(|c| c.split_once(':')).collect())
538 0 : .unwrap_or_default();
539 0 :
540 0 : pageserver
541 0 : .tenant_config(tenant_id, tenant_conf)
542 0 : .await
543 0 : .with_context(|| format!("Tenant config failed for tenant with id {tenant_id}"))?;
544 0 : println!("tenant {tenant_id} successfully configured on the pageserver");
545 : }
546 :
547 0 : Some((sub_name, _)) => bail!("Unexpected tenant subcommand '{}'", sub_name),
548 0 : None => bail!("no tenant subcommand provided"),
549 : }
550 0 : Ok(())
551 0 : }
552 :
553 0 : async fn handle_timeline(timeline_match: &ArgMatches, env: &mut local_env::LocalEnv) -> Result<()> {
554 0 : let pageserver = get_default_pageserver(env);
555 0 :
556 0 : match timeline_match.subcommand() {
557 0 : Some(("list", list_match)) => {
558 : // TODO(sharding): this command shouldn't have to specify a shard ID: we should ask the storage controller
559 : // where shard 0 is attached, and query there.
560 0 : let tenant_shard_id = get_tenant_shard_id(list_match, env)?;
561 0 : let timelines = pageserver.timeline_list(&tenant_shard_id).await?;
562 0 : print_timelines_tree(timelines, env.timeline_name_mappings())?;
563 : }
564 0 : Some(("create", create_match)) => {
565 0 : let tenant_id = get_tenant_id(create_match, env)?;
566 0 : let new_branch_name = create_match
567 0 : .get_one::<String>("branch-name")
568 0 : .ok_or_else(|| anyhow!("No branch name provided"))?;
569 :
570 0 : let pg_version = create_match
571 0 : .get_one::<u32>("pg-version")
572 0 : .copied()
573 0 : .context("Failed to parse postgres version from the argument string")?;
574 :
575 0 : let new_timeline_id_opt = parse_timeline_id(create_match)?;
576 0 : let new_timeline_id = new_timeline_id_opt.unwrap_or(TimelineId::generate());
577 0 :
578 0 : let storage_controller = StorageController::from_env(env);
579 0 : let create_req = TimelineCreateRequest {
580 0 : new_timeline_id,
581 0 : ancestor_timeline_id: None,
582 0 : existing_initdb_timeline_id: None,
583 0 : ancestor_start_lsn: None,
584 0 : pg_version: Some(pg_version),
585 0 : };
586 0 : let timeline_info = storage_controller
587 0 : .tenant_timeline_create(tenant_id, create_req)
588 0 : .await?;
589 :
590 0 : let last_record_lsn = timeline_info.last_record_lsn;
591 0 : env.register_branch_mapping(new_branch_name.to_string(), tenant_id, new_timeline_id)?;
592 :
593 0 : println!(
594 0 : "Created timeline '{}' at Lsn {last_record_lsn} for tenant: {tenant_id}",
595 0 : timeline_info.timeline_id
596 0 : );
597 : }
598 0 : Some(("import", import_match)) => {
599 0 : let tenant_id = get_tenant_id(import_match, env)?;
600 0 : let timeline_id = parse_timeline_id(import_match)?.expect("No timeline id provided");
601 0 : let name = import_match
602 0 : .get_one::<String>("node-name")
603 0 : .ok_or_else(|| anyhow!("No node name provided"))?;
604 0 : let update_catalog = import_match
605 0 : .get_one::<bool>("update-catalog")
606 0 : .cloned()
607 0 : .unwrap_or_default();
608 :
609 : // Parse base inputs
610 0 : let base_tarfile = import_match
611 0 : .get_one::<PathBuf>("base-tarfile")
612 0 : .ok_or_else(|| anyhow!("No base-tarfile provided"))?
613 0 : .to_owned();
614 0 : let base_lsn = Lsn::from_str(
615 0 : import_match
616 0 : .get_one::<String>("base-lsn")
617 0 : .ok_or_else(|| anyhow!("No base-lsn provided"))?,
618 0 : )?;
619 0 : let base = (base_lsn, base_tarfile);
620 0 :
621 0 : // Parse pg_wal inputs
622 0 : let wal_tarfile = import_match.get_one::<PathBuf>("wal-tarfile").cloned();
623 0 : let end_lsn = import_match
624 0 : .get_one::<String>("end-lsn")
625 0 : .map(|s| Lsn::from_str(s).unwrap());
626 0 : // TODO validate both or none are provided
627 0 : let pg_wal = end_lsn.zip(wal_tarfile);
628 :
629 0 : let pg_version = import_match
630 0 : .get_one::<u32>("pg-version")
631 0 : .copied()
632 0 : .context("Failed to parse postgres version from the argument string")?;
633 :
634 0 : let mut cplane = ComputeControlPlane::load(env.clone())?;
635 0 : println!("Importing timeline into pageserver ...");
636 0 : pageserver
637 0 : .timeline_import(tenant_id, timeline_id, base, pg_wal, pg_version)
638 0 : .await?;
639 0 : env.register_branch_mapping(name.to_string(), tenant_id, timeline_id)?;
640 :
641 0 : println!("Creating endpoint for imported timeline ...");
642 0 : cplane.new_endpoint(
643 0 : name,
644 0 : tenant_id,
645 0 : timeline_id,
646 0 : None,
647 0 : None,
648 0 : pg_version,
649 0 : ComputeMode::Primary,
650 0 : !update_catalog,
651 0 : )?;
652 0 : println!("Done");
653 : }
654 0 : Some(("branch", branch_match)) => {
655 0 : let tenant_id = get_tenant_id(branch_match, env)?;
656 0 : let new_branch_name = branch_match
657 0 : .get_one::<String>("branch-name")
658 0 : .ok_or_else(|| anyhow!("No branch name provided"))?;
659 0 : let ancestor_branch_name = branch_match
660 0 : .get_one::<String>("ancestor-branch-name")
661 0 : .map(|s| s.as_str())
662 0 : .unwrap_or(DEFAULT_BRANCH_NAME);
663 0 : let ancestor_timeline_id = env
664 0 : .get_branch_timeline_id(ancestor_branch_name, tenant_id)
665 0 : .ok_or_else(|| {
666 0 : anyhow!("Found no timeline id for branch name '{ancestor_branch_name}'")
667 0 : })?;
668 :
669 0 : let start_lsn = branch_match
670 0 : .get_one::<String>("ancestor-start-lsn")
671 0 : .map(|lsn_str| Lsn::from_str(lsn_str))
672 0 : .transpose()
673 0 : .context("Failed to parse ancestor start Lsn from the request")?;
674 0 : let new_timeline_id = TimelineId::generate();
675 0 : let storage_controller = StorageController::from_env(env);
676 0 : let create_req = TimelineCreateRequest {
677 0 : new_timeline_id,
678 0 : ancestor_timeline_id: Some(ancestor_timeline_id),
679 0 : existing_initdb_timeline_id: None,
680 0 : ancestor_start_lsn: start_lsn,
681 0 : pg_version: None,
682 0 : };
683 0 : let timeline_info = storage_controller
684 0 : .tenant_timeline_create(tenant_id, create_req)
685 0 : .await?;
686 :
687 0 : let last_record_lsn = timeline_info.last_record_lsn;
688 0 :
689 0 : env.register_branch_mapping(new_branch_name.to_string(), tenant_id, new_timeline_id)?;
690 :
691 0 : println!(
692 0 : "Created timeline '{}' at Lsn {last_record_lsn} for tenant: {tenant_id}. Ancestor timeline: '{ancestor_branch_name}'",
693 0 : timeline_info.timeline_id
694 0 : );
695 : }
696 0 : Some((sub_name, _)) => bail!("Unexpected tenant subcommand '{sub_name}'"),
697 0 : None => bail!("no tenant subcommand provided"),
698 : }
699 :
700 0 : Ok(())
701 0 : }
702 :
703 0 : async fn handle_endpoint(ep_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
704 0 : let (sub_name, sub_args) = match ep_match.subcommand() {
705 0 : Some(ep_subcommand_data) => ep_subcommand_data,
706 0 : None => bail!("no endpoint subcommand provided"),
707 : };
708 0 : let mut cplane = ComputeControlPlane::load(env.clone())?;
709 :
710 0 : match sub_name {
711 0 : "list" => {
712 : // TODO(sharding): this command shouldn't have to specify a shard ID: we should ask the storage controller
713 : // where shard 0 is attached, and query there.
714 0 : let tenant_shard_id = get_tenant_shard_id(sub_args, env)?;
715 0 : let timeline_infos = get_timeline_infos(env, &tenant_shard_id)
716 0 : .await
717 0 : .unwrap_or_else(|e| {
718 0 : eprintln!("Failed to load timeline info: {}", e);
719 0 : HashMap::new()
720 0 : });
721 0 :
722 0 : let timeline_name_mappings = env.timeline_name_mappings();
723 0 :
724 0 : let mut table = comfy_table::Table::new();
725 0 :
726 0 : table.load_preset(comfy_table::presets::NOTHING);
727 0 :
728 0 : table.set_header([
729 0 : "ENDPOINT",
730 0 : "ADDRESS",
731 0 : "TIMELINE",
732 0 : "BRANCH NAME",
733 0 : "LSN",
734 0 : "STATUS",
735 0 : ]);
736 :
737 0 : for (endpoint_id, endpoint) in cplane
738 0 : .endpoints
739 0 : .iter()
740 0 : .filter(|(_, endpoint)| endpoint.tenant_id == tenant_shard_id.tenant_id)
741 0 : {
742 0 : let lsn_str = match endpoint.mode {
743 0 : ComputeMode::Static(lsn) => {
744 0 : // -> read-only endpoint
745 0 : // Use the node's LSN.
746 0 : lsn.to_string()
747 : }
748 : _ => {
749 : // -> primary endpoint or hot replica
750 : // Use the LSN at the end of the timeline.
751 0 : timeline_infos
752 0 : .get(&endpoint.timeline_id)
753 0 : .map(|bi| bi.last_record_lsn.to_string())
754 0 : .unwrap_or_else(|| "?".to_string())
755 : }
756 : };
757 :
758 0 : let branch_name = timeline_name_mappings
759 0 : .get(&TenantTimelineId::new(
760 0 : tenant_shard_id.tenant_id,
761 0 : endpoint.timeline_id,
762 0 : ))
763 0 : .map(|name| name.as_str())
764 0 : .unwrap_or("?");
765 0 :
766 0 : table.add_row([
767 0 : endpoint_id.as_str(),
768 0 : &endpoint.pg_address.to_string(),
769 0 : &endpoint.timeline_id.to_string(),
770 0 : branch_name,
771 0 : lsn_str.as_str(),
772 0 : &format!("{}", endpoint.status()),
773 0 : ]);
774 : }
775 :
776 0 : println!("{table}");
777 : }
778 0 : "create" => {
779 0 : let tenant_id = get_tenant_id(sub_args, env)?;
780 0 : let branch_name = sub_args
781 0 : .get_one::<String>("branch-name")
782 0 : .map(|s| s.as_str())
783 0 : .unwrap_or(DEFAULT_BRANCH_NAME);
784 0 : let endpoint_id = sub_args
785 0 : .get_one::<String>("endpoint_id")
786 0 : .map(String::to_string)
787 0 : .unwrap_or_else(|| format!("ep-{branch_name}"));
788 0 : let update_catalog = sub_args
789 0 : .get_one::<bool>("update-catalog")
790 0 : .cloned()
791 0 : .unwrap_or_default();
792 :
793 0 : let lsn = sub_args
794 0 : .get_one::<String>("lsn")
795 0 : .map(|lsn_str| Lsn::from_str(lsn_str))
796 0 : .transpose()
797 0 : .context("Failed to parse Lsn from the request")?;
798 0 : let timeline_id = env
799 0 : .get_branch_timeline_id(branch_name, tenant_id)
800 0 : .ok_or_else(|| anyhow!("Found no timeline id for branch name '{branch_name}'"))?;
801 :
802 0 : let pg_port: Option<u16> = sub_args.get_one::<u16>("pg-port").copied();
803 0 : let http_port: Option<u16> = sub_args.get_one::<u16>("http-port").copied();
804 0 : let pg_version = sub_args
805 0 : .get_one::<u32>("pg-version")
806 0 : .copied()
807 0 : .context("Failed to parse postgres version from the argument string")?;
808 :
809 0 : let hot_standby = sub_args
810 0 : .get_one::<bool>("hot-standby")
811 0 : .copied()
812 0 : .unwrap_or(false);
813 0 :
814 0 : let allow_multiple = sub_args.get_flag("allow-multiple");
815 :
816 0 : let mode = match (lsn, hot_standby) {
817 0 : (Some(lsn), false) => ComputeMode::Static(lsn),
818 0 : (None, true) => ComputeMode::Replica,
819 0 : (None, false) => ComputeMode::Primary,
820 0 : (Some(_), true) => anyhow::bail!("cannot specify both lsn and hot-standby"),
821 : };
822 :
823 0 : match (mode, hot_standby) {
824 : (ComputeMode::Static(_), true) => {
825 0 : bail!("Cannot start a node in hot standby mode when it is already configured as a static replica")
826 : }
827 : (ComputeMode::Primary, true) => {
828 0 : bail!("Cannot start a node as a hot standby replica, it is already configured as primary node")
829 : }
830 0 : _ => {}
831 0 : }
832 0 :
833 0 : if !allow_multiple {
834 0 : cplane.check_conflicting_endpoints(mode, tenant_id, timeline_id)?;
835 0 : }
836 :
837 0 : cplane.new_endpoint(
838 0 : &endpoint_id,
839 0 : tenant_id,
840 0 : timeline_id,
841 0 : pg_port,
842 0 : http_port,
843 0 : pg_version,
844 0 : mode,
845 0 : !update_catalog,
846 0 : )?;
847 : }
848 0 : "start" => {
849 0 : let endpoint_id = sub_args
850 0 : .get_one::<String>("endpoint_id")
851 0 : .ok_or_else(|| anyhow!("No endpoint ID was provided to start"))?;
852 :
853 0 : let pageserver_id =
854 0 : if let Some(id_str) = sub_args.get_one::<String>("endpoint-pageserver-id") {
855 : Some(NodeId(
856 0 : id_str.parse().context("while parsing pageserver id")?,
857 : ))
858 : } else {
859 0 : None
860 : };
861 :
862 0 : let remote_ext_config = sub_args.get_one::<String>("remote-ext-config");
863 0 :
864 0 : let allow_multiple = sub_args.get_flag("allow-multiple");
865 :
866 : // If --safekeepers argument is given, use only the listed safekeeper nodes.
867 0 : let safekeepers =
868 0 : if let Some(safekeepers_str) = sub_args.get_one::<String>("safekeepers") {
869 0 : let mut safekeepers: Vec<NodeId> = Vec::new();
870 0 : for sk_id in safekeepers_str.split(',').map(str::trim) {
871 0 : let sk_id = NodeId(u64::from_str(sk_id).map_err(|_| {
872 0 : anyhow!("invalid node ID \"{sk_id}\" in --safekeepers list")
873 0 : })?);
874 0 : safekeepers.push(sk_id);
875 : }
876 0 : safekeepers
877 : } else {
878 0 : env.safekeepers.iter().map(|sk| sk.id).collect()
879 : };
880 :
881 0 : let endpoint = cplane
882 0 : .endpoints
883 0 : .get(endpoint_id.as_str())
884 0 : .ok_or_else(|| anyhow::anyhow!("endpoint {endpoint_id} not found"))?;
885 :
886 0 : let create_test_user = sub_args
887 0 : .get_one::<bool>("create-test-user")
888 0 : .cloned()
889 0 : .unwrap_or_default();
890 0 :
891 0 : if !allow_multiple {
892 0 : cplane.check_conflicting_endpoints(
893 0 : endpoint.mode,
894 0 : endpoint.tenant_id,
895 0 : endpoint.timeline_id,
896 0 : )?;
897 0 : }
898 :
899 0 : let (pageservers, stripe_size) = if let Some(pageserver_id) = pageserver_id {
900 0 : let conf = env.get_pageserver_conf(pageserver_id).unwrap();
901 0 : let parsed = parse_host_port(&conf.listen_pg_addr).expect("Bad config");
902 0 : (
903 0 : vec![(parsed.0, parsed.1.unwrap_or(5432))],
904 0 : // If caller is telling us what pageserver to use, this is not a tenant which is
905 0 : // full managed by storage controller, therefore not sharded.
906 0 : ShardParameters::DEFAULT_STRIPE_SIZE,
907 0 : )
908 : } else {
909 : // Look up the currently attached location of the tenant, and its striping metadata,
910 : // to pass these on to postgres.
911 0 : let storage_controller = StorageController::from_env(env);
912 0 : let locate_result = storage_controller.tenant_locate(endpoint.tenant_id).await?;
913 0 : let pageservers = locate_result
914 0 : .shards
915 0 : .into_iter()
916 0 : .map(|shard| {
917 0 : (
918 0 : Host::parse(&shard.listen_pg_addr)
919 0 : .expect("Storage controller reported bad hostname"),
920 0 : shard.listen_pg_port,
921 0 : )
922 0 : })
923 0 : .collect::<Vec<_>>();
924 0 : let stripe_size = locate_result.shard_params.stripe_size;
925 0 :
926 0 : (pageservers, stripe_size)
927 : };
928 0 : assert!(!pageservers.is_empty());
929 :
930 0 : let ps_conf = env.get_pageserver_conf(DEFAULT_PAGESERVER_ID)?;
931 0 : let auth_token = if matches!(ps_conf.pg_auth_type, AuthType::NeonJWT) {
932 0 : let claims = Claims::new(Some(endpoint.tenant_id), Scope::Tenant);
933 0 :
934 0 : Some(env.generate_auth_token(&claims)?)
935 : } else {
936 0 : None
937 : };
938 :
939 0 : println!("Starting existing endpoint {endpoint_id}...");
940 0 : endpoint
941 0 : .start(
942 0 : &auth_token,
943 0 : safekeepers,
944 0 : pageservers,
945 0 : remote_ext_config,
946 0 : stripe_size.0 as usize,
947 0 : create_test_user,
948 0 : )
949 0 : .await?;
950 : }
951 0 : "reconfigure" => {
952 0 : let endpoint_id = sub_args
953 0 : .get_one::<String>("endpoint_id")
954 0 : .ok_or_else(|| anyhow!("No endpoint ID provided to reconfigure"))?;
955 0 : let endpoint = cplane
956 0 : .endpoints
957 0 : .get(endpoint_id.as_str())
958 0 : .with_context(|| format!("postgres endpoint {endpoint_id} is not found"))?;
959 0 : let pageservers =
960 0 : if let Some(id_str) = sub_args.get_one::<String>("endpoint-pageserver-id") {
961 0 : let ps_id = NodeId(id_str.parse().context("while parsing pageserver id")?);
962 0 : let pageserver = PageServerNode::from_env(env, env.get_pageserver_conf(ps_id)?);
963 0 : vec![(
964 0 : pageserver.pg_connection_config.host().clone(),
965 0 : pageserver.pg_connection_config.port(),
966 0 : )]
967 : } else {
968 0 : let storage_controller = StorageController::from_env(env);
969 0 : storage_controller
970 0 : .tenant_locate(endpoint.tenant_id)
971 0 : .await?
972 : .shards
973 0 : .into_iter()
974 0 : .map(|shard| {
975 0 : (
976 0 : Host::parse(&shard.listen_pg_addr)
977 0 : .expect("Storage controller reported malformed host"),
978 0 : shard.listen_pg_port,
979 0 : )
980 0 : })
981 0 : .collect::<Vec<_>>()
982 : };
983 0 : endpoint.reconfigure(pageservers, None).await?;
984 : }
985 0 : "stop" => {
986 0 : let endpoint_id = sub_args
987 0 : .get_one::<String>("endpoint_id")
988 0 : .ok_or_else(|| anyhow!("No endpoint ID was provided to stop"))?;
989 0 : let destroy = sub_args.get_flag("destroy");
990 0 : let mode = sub_args.get_one::<String>("mode").expect("has a default");
991 :
992 0 : let endpoint = cplane
993 0 : .endpoints
994 0 : .get(endpoint_id.as_str())
995 0 : .with_context(|| format!("postgres endpoint {endpoint_id} is not found"))?;
996 0 : endpoint.stop(mode, destroy)?;
997 : }
998 :
999 0 : _ => bail!("Unexpected endpoint subcommand '{sub_name}'"),
1000 : }
1001 :
1002 0 : Ok(())
1003 0 : }
1004 :
1005 0 : fn handle_mappings(sub_match: &ArgMatches, env: &mut local_env::LocalEnv) -> Result<()> {
1006 0 : let (sub_name, sub_args) = match sub_match.subcommand() {
1007 0 : Some(ep_subcommand_data) => ep_subcommand_data,
1008 0 : None => bail!("no mappings subcommand provided"),
1009 : };
1010 :
1011 0 : match sub_name {
1012 0 : "map" => {
1013 0 : let branch_name = sub_args
1014 0 : .get_one::<String>("branch-name")
1015 0 : .expect("branch-name argument missing");
1016 0 :
1017 0 : let tenant_id = sub_args
1018 0 : .get_one::<String>("tenant-id")
1019 0 : .map(|x| TenantId::from_str(x))
1020 0 : .expect("tenant-id argument missing")
1021 0 : .expect("malformed tenant-id arg");
1022 0 :
1023 0 : let timeline_id = sub_args
1024 0 : .get_one::<String>("timeline-id")
1025 0 : .map(|x| TimelineId::from_str(x))
1026 0 : .expect("timeline-id argument missing")
1027 0 : .expect("malformed timeline-id arg");
1028 0 :
1029 0 : env.register_branch_mapping(branch_name.to_owned(), tenant_id, timeline_id)?;
1030 :
1031 0 : Ok(())
1032 : }
1033 0 : other => unimplemented!("mappings subcommand {other}"),
1034 : }
1035 0 : }
1036 :
1037 0 : fn get_pageserver(env: &local_env::LocalEnv, args: &ArgMatches) -> Result<PageServerNode> {
1038 0 : let node_id = if let Some(id_str) = args.get_one::<String>("pageserver-id") {
1039 0 : NodeId(id_str.parse().context("while parsing pageserver id")?)
1040 : } else {
1041 0 : DEFAULT_PAGESERVER_ID
1042 : };
1043 :
1044 : Ok(PageServerNode::from_env(
1045 0 : env,
1046 0 : env.get_pageserver_conf(node_id)?,
1047 : ))
1048 0 : }
1049 :
1050 0 : fn get_start_timeout(args: &ArgMatches) -> &Duration {
1051 0 : let humantime_duration = args
1052 0 : .get_one::<humantime::Duration>("start-timeout")
1053 0 : .expect("invalid value for start-timeout");
1054 0 : humantime_duration.as_ref()
1055 0 : }
1056 :
1057 0 : async fn handle_pageserver(sub_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
1058 0 : match sub_match.subcommand() {
1059 0 : Some(("start", subcommand_args)) => {
1060 0 : if let Err(e) = get_pageserver(env, subcommand_args)?
1061 0 : .start(get_start_timeout(subcommand_args))
1062 0 : .await
1063 : {
1064 0 : eprintln!("pageserver start failed: {e}");
1065 0 : exit(1);
1066 0 : }
1067 : }
1068 :
1069 0 : Some(("stop", subcommand_args)) => {
1070 0 : let immediate = subcommand_args
1071 0 : .get_one::<String>("stop-mode")
1072 0 : .map(|s| s.as_str())
1073 0 : == Some("immediate");
1074 :
1075 0 : if let Err(e) = get_pageserver(env, subcommand_args)?.stop(immediate) {
1076 0 : eprintln!("pageserver stop failed: {}", e);
1077 0 : exit(1);
1078 0 : }
1079 : }
1080 :
1081 0 : Some(("restart", subcommand_args)) => {
1082 0 : let pageserver = get_pageserver(env, subcommand_args)?;
1083 : //TODO what shutdown strategy should we use here?
1084 0 : if let Err(e) = pageserver.stop(false) {
1085 0 : eprintln!("pageserver stop failed: {}", e);
1086 0 : exit(1);
1087 0 : }
1088 :
1089 0 : if let Err(e) = pageserver.start(get_start_timeout(sub_match)).await {
1090 0 : eprintln!("pageserver start failed: {e}");
1091 0 : exit(1);
1092 0 : }
1093 : }
1094 :
1095 0 : Some(("status", subcommand_args)) => {
1096 0 : match get_pageserver(env, subcommand_args)?.check_status().await {
1097 0 : Ok(_) => println!("Page server is up and running"),
1098 0 : Err(err) => {
1099 0 : eprintln!("Page server is not available: {}", err);
1100 0 : exit(1);
1101 : }
1102 : }
1103 : }
1104 :
1105 0 : Some((sub_name, _)) => bail!("Unexpected pageserver subcommand '{}'", sub_name),
1106 0 : None => bail!("no pageserver subcommand provided"),
1107 : }
1108 0 : Ok(())
1109 0 : }
1110 :
1111 0 : async fn handle_storage_controller(
1112 0 : sub_match: &ArgMatches,
1113 0 : env: &local_env::LocalEnv,
1114 0 : ) -> Result<()> {
1115 0 : let svc = StorageController::from_env(env);
1116 0 : match sub_match.subcommand() {
1117 0 : Some(("start", start_match)) => {
1118 0 : if let Err(e) = svc.start(get_start_timeout(start_match)).await {
1119 0 : eprintln!("start failed: {e}");
1120 0 : exit(1);
1121 0 : }
1122 : }
1123 :
1124 0 : Some(("stop", stop_match)) => {
1125 0 : let immediate = stop_match
1126 0 : .get_one::<String>("stop-mode")
1127 0 : .map(|s| s.as_str())
1128 0 : == Some("immediate");
1129 :
1130 0 : if let Err(e) = svc.stop(immediate).await {
1131 0 : eprintln!("stop failed: {}", e);
1132 0 : exit(1);
1133 0 : }
1134 : }
1135 0 : Some((sub_name, _)) => bail!("Unexpected storage_controller subcommand '{}'", sub_name),
1136 0 : None => bail!("no storage_controller subcommand provided"),
1137 : }
1138 0 : Ok(())
1139 0 : }
1140 :
1141 0 : fn get_safekeeper(env: &local_env::LocalEnv, id: NodeId) -> Result<SafekeeperNode> {
1142 0 : if let Some(node) = env.safekeepers.iter().find(|node| node.id == id) {
1143 0 : Ok(SafekeeperNode::from_env(env, node))
1144 : } else {
1145 0 : bail!("could not find safekeeper {id}")
1146 : }
1147 0 : }
1148 :
1149 : // Get list of options to append to safekeeper command invocation.
1150 0 : fn safekeeper_extra_opts(init_match: &ArgMatches) -> Vec<String> {
1151 0 : init_match
1152 0 : .get_many::<String>("safekeeper-extra-opt")
1153 0 : .into_iter()
1154 0 : .flatten()
1155 0 : .map(|s| s.to_owned())
1156 0 : .collect()
1157 0 : }
1158 :
1159 0 : async fn handle_safekeeper(sub_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
1160 0 : let (sub_name, sub_args) = match sub_match.subcommand() {
1161 0 : Some(safekeeper_command_data) => safekeeper_command_data,
1162 0 : None => bail!("no safekeeper subcommand provided"),
1163 : };
1164 :
1165 : // All the commands take an optional safekeeper name argument
1166 0 : let sk_id = if let Some(id_str) = sub_args.get_one::<String>("id") {
1167 0 : NodeId(id_str.parse().context("while parsing safekeeper id")?)
1168 : } else {
1169 0 : DEFAULT_SAFEKEEPER_ID
1170 : };
1171 0 : let safekeeper = get_safekeeper(env, sk_id)?;
1172 :
1173 0 : match sub_name {
1174 0 : "start" => {
1175 0 : let extra_opts = safekeeper_extra_opts(sub_args);
1176 :
1177 0 : if let Err(e) = safekeeper
1178 0 : .start(extra_opts, get_start_timeout(sub_args))
1179 0 : .await
1180 : {
1181 0 : eprintln!("safekeeper start failed: {}", e);
1182 0 : exit(1);
1183 0 : }
1184 : }
1185 :
1186 0 : "stop" => {
1187 0 : let immediate =
1188 0 : sub_args.get_one::<String>("stop-mode").map(|s| s.as_str()) == Some("immediate");
1189 :
1190 0 : if let Err(e) = safekeeper.stop(immediate) {
1191 0 : eprintln!("safekeeper stop failed: {}", e);
1192 0 : exit(1);
1193 0 : }
1194 : }
1195 :
1196 0 : "restart" => {
1197 0 : let immediate =
1198 0 : sub_args.get_one::<String>("stop-mode").map(|s| s.as_str()) == Some("immediate");
1199 :
1200 0 : if let Err(e) = safekeeper.stop(immediate) {
1201 0 : eprintln!("safekeeper stop failed: {}", e);
1202 0 : exit(1);
1203 0 : }
1204 0 :
1205 0 : let extra_opts = safekeeper_extra_opts(sub_args);
1206 0 : if let Err(e) = safekeeper
1207 0 : .start(extra_opts, get_start_timeout(sub_args))
1208 0 : .await
1209 : {
1210 0 : eprintln!("safekeeper start failed: {}", e);
1211 0 : exit(1);
1212 0 : }
1213 : }
1214 :
1215 : _ => {
1216 0 : bail!("Unexpected safekeeper subcommand '{}'", sub_name)
1217 : }
1218 : }
1219 0 : Ok(())
1220 0 : }
1221 :
1222 0 : async fn handle_start_all(
1223 0 : env: &local_env::LocalEnv,
1224 0 : retry_timeout: &Duration,
1225 0 : ) -> anyhow::Result<()> {
1226 0 : // Endpoints are not started automatically
1227 0 :
1228 0 : broker::start_broker_process(env, retry_timeout).await?;
1229 :
1230 : // Only start the storage controller if the pageserver is configured to need it
1231 0 : if env.control_plane_api.is_some() {
1232 0 : let storage_controller = StorageController::from_env(env);
1233 0 : if let Err(e) = storage_controller.start(retry_timeout).await {
1234 0 : eprintln!("storage_controller start failed: {:#}", e);
1235 0 : try_stop_all(env, true).await;
1236 0 : exit(1);
1237 0 : }
1238 0 : }
1239 :
1240 0 : for ps_conf in &env.pageservers {
1241 0 : let pageserver = PageServerNode::from_env(env, ps_conf);
1242 0 : if let Err(e) = pageserver.start(retry_timeout).await {
1243 0 : eprintln!("pageserver {} start failed: {:#}", ps_conf.id, e);
1244 0 : try_stop_all(env, true).await;
1245 0 : exit(1);
1246 0 : }
1247 : }
1248 :
1249 0 : for node in env.safekeepers.iter() {
1250 0 : let safekeeper = SafekeeperNode::from_env(env, node);
1251 0 : if let Err(e) = safekeeper.start(vec![], retry_timeout).await {
1252 0 : eprintln!("safekeeper {} start failed: {:#}", safekeeper.id, e);
1253 0 : try_stop_all(env, false).await;
1254 0 : exit(1);
1255 0 : }
1256 : }
1257 0 : Ok(())
1258 0 : }
1259 :
1260 0 : async fn handle_stop_all(sub_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
1261 0 : let immediate =
1262 0 : sub_match.get_one::<String>("stop-mode").map(|s| s.as_str()) == Some("immediate");
1263 0 :
1264 0 : try_stop_all(env, immediate).await;
1265 :
1266 0 : Ok(())
1267 0 : }
1268 :
1269 0 : async fn try_stop_all(env: &local_env::LocalEnv, immediate: bool) {
1270 0 : // Stop all endpoints
1271 0 : match ComputeControlPlane::load(env.clone()) {
1272 0 : Ok(cplane) => {
1273 0 : for (_k, node) in cplane.endpoints {
1274 0 : if let Err(e) = node.stop(if immediate { "immediate" } else { "fast" }, false) {
1275 0 : eprintln!("postgres stop failed: {e:#}");
1276 0 : }
1277 : }
1278 : }
1279 0 : Err(e) => {
1280 0 : eprintln!("postgres stop failed, could not restore control plane data from env: {e:#}")
1281 : }
1282 : }
1283 :
1284 0 : for ps_conf in &env.pageservers {
1285 0 : let pageserver = PageServerNode::from_env(env, ps_conf);
1286 0 : if let Err(e) = pageserver.stop(immediate) {
1287 0 : eprintln!("pageserver {} stop failed: {:#}", ps_conf.id, e);
1288 0 : }
1289 : }
1290 :
1291 0 : for node in env.safekeepers.iter() {
1292 0 : let safekeeper = SafekeeperNode::from_env(env, node);
1293 0 : if let Err(e) = safekeeper.stop(immediate) {
1294 0 : eprintln!("safekeeper {} stop failed: {:#}", safekeeper.id, e);
1295 0 : }
1296 : }
1297 :
1298 0 : if let Err(e) = broker::stop_broker_process(env) {
1299 0 : eprintln!("neon broker stop failed: {e:#}");
1300 0 : }
1301 :
1302 0 : if env.control_plane_api.is_some() {
1303 0 : let storage_controller = StorageController::from_env(env);
1304 0 : if let Err(e) = storage_controller.stop(immediate).await {
1305 0 : eprintln!("storage controller stop failed: {e:#}");
1306 0 : }
1307 0 : }
1308 0 : }
1309 :
1310 2 : fn cli() -> Command {
1311 2 : let timeout_arg = Arg::new("start-timeout")
1312 2 : .long("start-timeout")
1313 2 : .short('t')
1314 2 : .global(true)
1315 2 : .help("timeout until we fail the command, e.g. 30s")
1316 2 : .value_parser(value_parser!(humantime::Duration))
1317 2 : .default_value("10s")
1318 2 : .required(false);
1319 2 :
1320 2 : let branch_name_arg = Arg::new("branch-name")
1321 2 : .long("branch-name")
1322 2 : .help("Name of the branch to be created or used as an alias for other services")
1323 2 : .required(false);
1324 2 :
1325 2 : let endpoint_id_arg = Arg::new("endpoint_id")
1326 2 : .help("Postgres endpoint id")
1327 2 : .required(false);
1328 2 :
1329 2 : let safekeeper_id_arg = Arg::new("id").help("safekeeper id").required(false);
1330 2 :
1331 2 : // --id, when using a pageserver command
1332 2 : let pageserver_id_arg = Arg::new("pageserver-id")
1333 2 : .long("id")
1334 2 : .global(true)
1335 2 : .help("pageserver id")
1336 2 : .required(false);
1337 2 : // --pageserver-id when using a non-pageserver command
1338 2 : let endpoint_pageserver_id_arg = Arg::new("endpoint-pageserver-id")
1339 2 : .long("pageserver-id")
1340 2 : .required(false);
1341 2 :
1342 2 : let safekeeper_extra_opt_arg = Arg::new("safekeeper-extra-opt")
1343 2 : .short('e')
1344 2 : .long("safekeeper-extra-opt")
1345 2 : .num_args(1)
1346 2 : .action(ArgAction::Append)
1347 2 : .help("Additional safekeeper invocation options, e.g. -e=--http-auth-public-key-path=foo")
1348 2 : .required(false);
1349 2 :
1350 2 : let tenant_id_arg = Arg::new("tenant-id")
1351 2 : .long("tenant-id")
1352 2 : .help("Tenant id. Represented as a hexadecimal string 32 symbols length")
1353 2 : .required(false);
1354 2 :
1355 2 : let timeline_id_arg = Arg::new("timeline-id")
1356 2 : .long("timeline-id")
1357 2 : .help("Timeline id. Represented as a hexadecimal string 32 symbols length")
1358 2 : .required(false);
1359 2 :
1360 2 : let pg_version_arg = Arg::new("pg-version")
1361 2 : .long("pg-version")
1362 2 : .help("Postgres version to use for the initial tenant")
1363 2 : .required(false)
1364 2 : .value_parser(value_parser!(u32))
1365 2 : .default_value(DEFAULT_PG_VERSION);
1366 2 :
1367 2 : let pg_port_arg = Arg::new("pg-port")
1368 2 : .long("pg-port")
1369 2 : .required(false)
1370 2 : .value_parser(value_parser!(u16))
1371 2 : .value_name("pg-port");
1372 2 :
1373 2 : let http_port_arg = Arg::new("http-port")
1374 2 : .long("http-port")
1375 2 : .required(false)
1376 2 : .value_parser(value_parser!(u16))
1377 2 : .value_name("http-port");
1378 2 :
1379 2 : let safekeepers_arg = Arg::new("safekeepers")
1380 2 : .long("safekeepers")
1381 2 : .required(false)
1382 2 : .value_name("safekeepers");
1383 2 :
1384 2 : let stop_mode_arg = Arg::new("stop-mode")
1385 2 : .short('m')
1386 2 : .value_parser(["fast", "immediate"])
1387 2 : .default_value("fast")
1388 2 : .help("If 'immediate', don't flush repository data at shutdown")
1389 2 : .required(false)
1390 2 : .value_name("stop-mode");
1391 2 :
1392 2 : let remote_ext_config_args = Arg::new("remote-ext-config")
1393 2 : .long("remote-ext-config")
1394 2 : .num_args(1)
1395 2 : .help("Configure the remote extensions storage proxy gateway to request for extensions.")
1396 2 : .required(false);
1397 2 :
1398 2 : let lsn_arg = Arg::new("lsn")
1399 2 : .long("lsn")
1400 2 : .help("Specify Lsn on the timeline to start from. By default, end of the timeline would be used.")
1401 2 : .required(false);
1402 2 :
1403 2 : let hot_standby_arg = Arg::new("hot-standby")
1404 2 : .value_parser(value_parser!(bool))
1405 2 : .long("hot-standby")
1406 2 : .help("If set, the node will be a hot replica on the specified timeline")
1407 2 : .required(false);
1408 2 :
1409 2 : let force_arg = Arg::new("force")
1410 2 : .value_parser(value_parser!(InitForceMode))
1411 2 : .long("force")
1412 2 : .default_value(
1413 2 : InitForceMode::MustNotExist
1414 2 : .to_possible_value()
1415 2 : .unwrap()
1416 2 : .get_name()
1417 2 : .to_owned(),
1418 2 : )
1419 2 : .help("Force initialization even if the repository is not empty")
1420 2 : .required(false);
1421 2 :
1422 2 : let num_pageservers_arg = Arg::new("num-pageservers")
1423 2 : .value_parser(value_parser!(u16))
1424 2 : .long("num-pageservers")
1425 2 : .help("How many pageservers to create (default 1)");
1426 2 :
1427 2 : let update_catalog = Arg::new("update-catalog")
1428 2 : .value_parser(value_parser!(bool))
1429 2 : .long("update-catalog")
1430 2 : .help("If set, will set up the catalog for neon_superuser")
1431 2 : .required(false);
1432 2 :
1433 2 : let create_test_user = Arg::new("create-test-user")
1434 2 : .value_parser(value_parser!(bool))
1435 2 : .long("create-test-user")
1436 2 : .help("If set, will create test user `user` and `neondb` database. Requires `update-catalog = true`")
1437 2 : .required(false);
1438 2 :
1439 2 : let allow_multiple = Arg::new("allow-multiple")
1440 2 : .help("Allow multiple primary endpoints running on the same branch. Shouldn't be used normally, but useful for tests.")
1441 2 : .long("allow-multiple")
1442 2 : .action(ArgAction::SetTrue)
1443 2 : .required(false);
1444 2 :
1445 2 : Command::new("Neon CLI")
1446 2 : .arg_required_else_help(true)
1447 2 : .version(GIT_VERSION)
1448 2 : .subcommand(
1449 2 : Command::new("init")
1450 2 : .about("Initialize a new Neon repository, preparing configs for services to start with")
1451 2 : .arg(num_pageservers_arg.clone())
1452 2 : .arg(
1453 2 : Arg::new("config")
1454 2 : .long("config")
1455 2 : .required(false)
1456 2 : .value_parser(value_parser!(PathBuf))
1457 2 : .value_name("config")
1458 2 : )
1459 2 : .arg(pg_version_arg.clone())
1460 2 : .arg(force_arg)
1461 2 : )
1462 2 : .subcommand(
1463 2 : Command::new("timeline")
1464 2 : .about("Manage timelines")
1465 2 : .arg_required_else_help(true)
1466 2 : .subcommand(Command::new("list")
1467 2 : .about("List all timelines, available to this pageserver")
1468 2 : .arg(tenant_id_arg.clone()))
1469 2 : .subcommand(Command::new("branch")
1470 2 : .about("Create a new timeline, using another timeline as a base, copying its data")
1471 2 : .arg(tenant_id_arg.clone())
1472 2 : .arg(branch_name_arg.clone())
1473 2 : .arg(Arg::new("ancestor-branch-name").long("ancestor-branch-name")
1474 2 : .help("Use last Lsn of another timeline (and its data) as base when creating the new timeline. The timeline gets resolved by its branch name.").required(false))
1475 2 : .arg(Arg::new("ancestor-start-lsn").long("ancestor-start-lsn")
1476 2 : .help("When using another timeline as base, use a specific Lsn in it instead of the latest one").required(false)))
1477 2 : .subcommand(Command::new("create")
1478 2 : .about("Create a new blank timeline")
1479 2 : .arg(tenant_id_arg.clone())
1480 2 : .arg(timeline_id_arg.clone())
1481 2 : .arg(branch_name_arg.clone())
1482 2 : .arg(pg_version_arg.clone())
1483 2 : )
1484 2 : .subcommand(Command::new("import")
1485 2 : .about("Import timeline from basebackup directory")
1486 2 : .arg(tenant_id_arg.clone())
1487 2 : .arg(timeline_id_arg.clone())
1488 2 : .arg(Arg::new("node-name").long("node-name")
1489 2 : .help("Name to assign to the imported timeline"))
1490 2 : .arg(Arg::new("base-tarfile")
1491 2 : .long("base-tarfile")
1492 2 : .value_parser(value_parser!(PathBuf))
1493 2 : .help("Basebackup tarfile to import")
1494 2 : )
1495 2 : .arg(Arg::new("base-lsn").long("base-lsn")
1496 2 : .help("Lsn the basebackup starts at"))
1497 2 : .arg(Arg::new("wal-tarfile")
1498 2 : .long("wal-tarfile")
1499 2 : .value_parser(value_parser!(PathBuf))
1500 2 : .help("Wal to add after base")
1501 2 : )
1502 2 : .arg(Arg::new("end-lsn").long("end-lsn")
1503 2 : .help("Lsn the basebackup ends at"))
1504 2 : .arg(pg_version_arg.clone())
1505 2 : .arg(update_catalog.clone())
1506 2 : )
1507 2 : ).subcommand(
1508 2 : Command::new("tenant")
1509 2 : .arg_required_else_help(true)
1510 2 : .about("Manage tenants")
1511 2 : .subcommand(Command::new("list"))
1512 2 : .subcommand(Command::new("create")
1513 2 : .arg(tenant_id_arg.clone())
1514 2 : .arg(timeline_id_arg.clone().help("Use a specific timeline id when creating a tenant and its initial timeline"))
1515 2 : .arg(Arg::new("config").short('c').num_args(1).action(ArgAction::Append).required(false))
1516 2 : .arg(pg_version_arg.clone())
1517 2 : .arg(Arg::new("set-default").long("set-default").action(ArgAction::SetTrue).required(false)
1518 2 : .help("Use this tenant in future CLI commands where tenant_id is needed, but not specified"))
1519 2 : .arg(Arg::new("shard-count").value_parser(value_parser!(u8)).long("shard-count").action(ArgAction::Set).help("Number of shards in the new tenant (default 1)"))
1520 2 : .arg(Arg::new("shard-stripe-size").value_parser(value_parser!(u32)).long("shard-stripe-size").action(ArgAction::Set).help("Sharding stripe size in pages"))
1521 2 : .arg(Arg::new("placement-policy").value_parser(value_parser!(String)).long("placement-policy").action(ArgAction::Set).help("Placement policy shards in this tenant"))
1522 2 : )
1523 2 : .subcommand(Command::new("set-default").arg(tenant_id_arg.clone().required(true))
1524 2 : .about("Set a particular tenant as default in future CLI commands where tenant_id is needed, but not specified"))
1525 2 : .subcommand(Command::new("config")
1526 2 : .arg(tenant_id_arg.clone())
1527 2 : .arg(Arg::new("config").short('c').num_args(1).action(ArgAction::Append).required(false)))
1528 2 : .subcommand(Command::new("import").arg(tenant_id_arg.clone().required(true))
1529 2 : .about("Import a tenant that is present in remote storage, and create branches for its timelines"))
1530 2 : )
1531 2 : .subcommand(
1532 2 : Command::new("pageserver")
1533 2 : .arg_required_else_help(true)
1534 2 : .about("Manage pageserver")
1535 2 : .arg(pageserver_id_arg)
1536 2 : .subcommand(Command::new("status"))
1537 2 : .subcommand(Command::new("start")
1538 2 : .about("Start local pageserver")
1539 2 : .arg(timeout_arg.clone())
1540 2 : )
1541 2 : .subcommand(Command::new("stop")
1542 2 : .about("Stop local pageserver")
1543 2 : .arg(stop_mode_arg.clone())
1544 2 : )
1545 2 : .subcommand(Command::new("restart")
1546 2 : .about("Restart local pageserver")
1547 2 : .arg(timeout_arg.clone())
1548 2 : )
1549 2 : )
1550 2 : .subcommand(
1551 2 : Command::new("storage_controller")
1552 2 : .arg_required_else_help(true)
1553 2 : .about("Manage storage_controller")
1554 2 : .subcommand(Command::new("start").about("Start storage controller")
1555 2 : .arg(timeout_arg.clone()))
1556 2 : .subcommand(Command::new("stop").about("Stop storage controller")
1557 2 : .arg(stop_mode_arg.clone()))
1558 2 : )
1559 2 : .subcommand(
1560 2 : Command::new("safekeeper")
1561 2 : .arg_required_else_help(true)
1562 2 : .about("Manage safekeepers")
1563 2 : .subcommand(Command::new("start")
1564 2 : .about("Start local safekeeper")
1565 2 : .arg(safekeeper_id_arg.clone())
1566 2 : .arg(safekeeper_extra_opt_arg.clone())
1567 2 : .arg(timeout_arg.clone())
1568 2 : )
1569 2 : .subcommand(Command::new("stop")
1570 2 : .about("Stop local safekeeper")
1571 2 : .arg(safekeeper_id_arg.clone())
1572 2 : .arg(stop_mode_arg.clone())
1573 2 : )
1574 2 : .subcommand(Command::new("restart")
1575 2 : .about("Restart local safekeeper")
1576 2 : .arg(safekeeper_id_arg)
1577 2 : .arg(stop_mode_arg.clone())
1578 2 : .arg(safekeeper_extra_opt_arg)
1579 2 : .arg(timeout_arg.clone())
1580 2 : )
1581 2 : )
1582 2 : .subcommand(
1583 2 : Command::new("endpoint")
1584 2 : .arg_required_else_help(true)
1585 2 : .about("Manage postgres instances")
1586 2 : .subcommand(Command::new("list").arg(tenant_id_arg.clone()))
1587 2 : .subcommand(Command::new("create")
1588 2 : .about("Create a compute endpoint")
1589 2 : .arg(endpoint_id_arg.clone())
1590 2 : .arg(branch_name_arg.clone())
1591 2 : .arg(tenant_id_arg.clone())
1592 2 : .arg(lsn_arg.clone())
1593 2 : .arg(pg_port_arg.clone())
1594 2 : .arg(http_port_arg.clone())
1595 2 : .arg(endpoint_pageserver_id_arg.clone())
1596 2 : .arg(
1597 2 : Arg::new("config-only")
1598 2 : .help("Don't do basebackup, create endpoint directory with only config files")
1599 2 : .long("config-only")
1600 2 : .required(false))
1601 2 : .arg(pg_version_arg.clone())
1602 2 : .arg(hot_standby_arg.clone())
1603 2 : .arg(update_catalog)
1604 2 : .arg(allow_multiple.clone())
1605 2 : )
1606 2 : .subcommand(Command::new("start")
1607 2 : .about("Start postgres.\n If the endpoint doesn't exist yet, it is created.")
1608 2 : .arg(endpoint_id_arg.clone())
1609 2 : .arg(endpoint_pageserver_id_arg.clone())
1610 2 : .arg(safekeepers_arg)
1611 2 : .arg(remote_ext_config_args)
1612 2 : .arg(create_test_user)
1613 2 : .arg(allow_multiple.clone())
1614 2 : .arg(timeout_arg.clone())
1615 2 : )
1616 2 : .subcommand(Command::new("reconfigure")
1617 2 : .about("Reconfigure the endpoint")
1618 2 : .arg(endpoint_pageserver_id_arg)
1619 2 : .arg(endpoint_id_arg.clone())
1620 2 : .arg(tenant_id_arg.clone())
1621 2 : )
1622 2 : .subcommand(
1623 2 : Command::new("stop")
1624 2 : .arg(endpoint_id_arg)
1625 2 : .arg(
1626 2 : Arg::new("destroy")
1627 2 : .help("Also delete data directory (now optional, should be default in future)")
1628 2 : .long("destroy")
1629 2 : .action(ArgAction::SetTrue)
1630 2 : .required(false)
1631 2 : )
1632 2 : .arg(
1633 2 : Arg::new("mode")
1634 2 : .help("Postgres shutdown mode, passed to \"pg_ctl -m <mode>\"")
1635 2 : .long("mode")
1636 2 : .action(ArgAction::Set)
1637 2 : .required(false)
1638 2 : .value_parser(["smart", "fast", "immediate"])
1639 2 : .default_value("fast")
1640 2 : )
1641 2 : )
1642 2 :
1643 2 : )
1644 2 : .subcommand(
1645 2 : Command::new("mappings")
1646 2 : .arg_required_else_help(true)
1647 2 : .about("Manage neon_local branch name mappings")
1648 2 : .subcommand(
1649 2 : Command::new("map")
1650 2 : .about("Create new mapping which cannot exist already")
1651 2 : .arg(branch_name_arg.clone())
1652 2 : .arg(tenant_id_arg.clone())
1653 2 : .arg(timeline_id_arg.clone())
1654 2 : )
1655 2 : )
1656 2 : // Obsolete old name for 'endpoint'. We now just print an error if it's used.
1657 2 : .subcommand(
1658 2 : Command::new("pg")
1659 2 : .hide(true)
1660 2 : .arg(Arg::new("ignore-rest").allow_hyphen_values(true).num_args(0..).required(false))
1661 2 : .trailing_var_arg(true)
1662 2 : )
1663 2 : .subcommand(
1664 2 : Command::new("start")
1665 2 : .about("Start page server and safekeepers")
1666 2 : .arg(timeout_arg.clone())
1667 2 : )
1668 2 : .subcommand(
1669 2 : Command::new("stop")
1670 2 : .about("Stop page server and safekeepers")
1671 2 : .arg(stop_mode_arg)
1672 2 : )
1673 2 : }
1674 :
1675 : #[test]
1676 2 : fn verify_cli() {
1677 2 : cli().debug_assert();
1678 2 : }
|