From feae5f716f5883b9372cf2733fafd29224475955 Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 7 Nov 2023 15:48:55 +0000 Subject: [PATCH] pageserver: carry a ShardIdentity in LocationConf --- libs/pageserver_api/src/models.rs | 3 +++ pageserver/src/tenant/config.rs | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libs/pageserver_api/src/models.rs b/libs/pageserver_api/src/models.rs index cb99dc0a55..4587f790fc 100644 --- a/libs/pageserver_api/src/models.rs +++ b/libs/pageserver_api/src/models.rs @@ -259,6 +259,9 @@ pub struct LocationConfigSecondary { /// for use in external-facing APIs. #[derive(Serialize, Deserialize, Debug)] pub struct LocationConfig { + pub shard_number: u8, + pub shard_count: u8, + pub shard_stripe_size: u32, pub mode: LocationConfigMode, /// If attaching, in what generation? #[serde(default)] diff --git a/pageserver/src/tenant/config.rs b/pageserver/src/tenant/config.rs index 5f8c7f6c59..9e8ab3a083 100644 --- a/pageserver/src/tenant/config.rs +++ b/pageserver/src/tenant/config.rs @@ -10,6 +10,7 @@ //! use anyhow::Context; use pageserver_api::models; +use pageserver_api::shard::{ShardCount, ShardIdentity, ShardNumber, ShardStripeSize}; use serde::{Deserialize, Serialize}; use std::num::NonZeroU64; use std::time::Duration; @@ -85,6 +86,11 @@ pub(crate) enum LocationMode { /// but have distinct LocationConf. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub(crate) struct LocationConf { + /// Detailed identity of this TenantShard. The shard number and count usually + /// appear in the keys of maps containing tenants, but it is convenient to also + /// store it here. + pub(crate) shard: ShardIdentity, + /// The location-specific part of the configuration, describes the operating /// mode of this pageserver for this tenant. pub(crate) mode: LocationMode, @@ -156,6 +162,7 @@ impl LocationConf { /// possible state. This function should eventually be removed. pub(crate) fn attached_single(tenant_conf: TenantConfOpt, generation: Generation) -> Self { Self { + shard: ShardIdentity::none(), mode: LocationMode::Attached(AttachedLocationConfig { generation, attach_mode: AttachmentMode::Single, @@ -226,7 +233,21 @@ impl LocationConf { } }; - Ok(Self { mode, tenant_conf }) + let shard = if conf.shard_count == 0 { + ShardIdentity::none() + } else { + ShardIdentity::new( + ShardNumber(conf.shard_number), + ShardCount(conf.shard_count), + ShardStripeSize(conf.shard_stripe_size), + ) + }; + + Ok(Self { + shard, + mode, + tenant_conf, + }) } } @@ -236,6 +257,7 @@ impl Default for LocationConf { // => tech debt since https://github.com/neondatabase/neon/issues/1555 fn default() -> Self { Self { + shard: ShardIdentity::none(), mode: LocationMode::Attached(AttachedLocationConfig { generation: Generation::none(), attach_mode: AttachmentMode::Single,