From 95505e5ac1bf9852febb62d5627dcf44ae1016d3 Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 22 Dec 2023 11:01:53 +0000 Subject: [PATCH] neon_local: add shard split command --- control_plane/src/attachment_service.rs | 10 +++++----- control_plane/src/bin/attachment_service.rs | 3 ++- control_plane/src/bin/neon_local.rs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/control_plane/src/attachment_service.rs b/control_plane/src/attachment_service.rs index 3914c65aa5..0089ebaa50 100644 --- a/control_plane/src/attachment_service.rs +++ b/control_plane/src/attachment_service.rs @@ -4,8 +4,8 @@ use camino::Utf8PathBuf; use hyper::{Method, StatusCode}; use pageserver_api::{ models::{ - ShardParameters, TenantCreateRequest, TenantShardSplitRequest, TimelineCreateRequest, - TimelineInfo, + ShardParameters, TenantCreateRequest, TenantShardSplitRequest, TenantShardSplitResponse, + TimelineCreateRequest, TimelineInfo, }, shard::TenantShardId, }; @@ -264,9 +264,9 @@ impl AttachmentService { &self, tenant_id: TenantId, new_shard_count: u8, - ) -> anyhow::Result<()> { - self.dispatch::<_, ()>( - Method::POST, + ) -> anyhow::Result { + self.dispatch( + Method::PUT, format!("tenant/{tenant_id}/shard_split"), Some(TenantShardSplitRequest { new_shard_count }), ) diff --git a/control_plane/src/bin/attachment_service.rs b/control_plane/src/bin/attachment_service.rs index 78a02c984c..e824595841 100644 --- a/control_plane/src/bin/attachment_service.rs +++ b/control_plane/src/bin/attachment_service.rs @@ -738,8 +738,9 @@ async fn handle_tenant_locate(req: Request) -> Result, ApiE } let shard_params = shard_params.expect("result is non-empty, therefore this is set"); tracing::info!( - "Located tenant {} on shards {}", + "Located tenant {} with params {:?} on shards {}", tenant_id, + shard_params, result .iter() .map(|s| format!("{:?}", s)) diff --git a/control_plane/src/bin/neon_local.rs b/control_plane/src/bin/neon_local.rs index bac106bc12..d8de00f94a 100644 --- a/control_plane/src/bin/neon_local.rs +++ b/control_plane/src/bin/neon_local.rs @@ -580,6 +580,15 @@ async fn handle_tenant( println!("{tenant_table}"); println!("{shard_table}"); } + Some(("shard-split", matches)) => { + let tenant_id = get_tenant_id(matches, env)?; + let shard_count: u8 = matches.get_one::("shard-count").cloned().unwrap_or(0); + + let attachment_service = AttachmentService::from_env(env); + attachment_service + .tenant_split(tenant_id, shard_count) + .await?; + } Some((sub_name, _)) => bail!("Unexpected tenant subcommand '{}'", sub_name), None => bail!("no tenant subcommand provided"), @@ -1507,7 +1516,11 @@ fn cli() -> Command { .arg(pageserver_id_arg.clone())) .subcommand(Command::new("status") .about("Human readable summary of the tenant's shards and attachment locations") + .arg(tenant_id_arg.clone())) + .subcommand(Command::new("shard-split") + .about("Increase the number of shards in the tenant") .arg(tenant_id_arg.clone()) + .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)")) ) ) .subcommand(