From a1c1c1e74787f2950db8b93ba58f663cec742d66 Mon Sep 17 00:00:00 2001 From: John Spray Date: Sun, 7 Jan 2024 20:53:20 +0000 Subject: [PATCH] wip --- pageserver/src/http/routes.rs | 4 +--- pageserver/src/tenant.rs | 12 +++++------- pageserver/src/tenant/config.rs | 28 +++++++++++++++++++++++++++- pageserver/src/tenant/secondary.rs | 27 ++++++++++++++++++++++++++- vendor/postgres-v14 | 2 +- vendor/postgres-v15 | 2 +- vendor/postgres-v16 | 2 +- 7 files changed, 62 insertions(+), 15 deletions(-) diff --git a/pageserver/src/http/routes.rs b/pageserver/src/http/routes.rs index 36a68bee2b..f053708e0f 100644 --- a/pageserver/src/http/routes.rs +++ b/pageserver/src/http/routes.rs @@ -1309,9 +1309,7 @@ async fn list_location_config_handler( .map(|(tenant_shard_id, slot)| { let v = match slot { TenantSlot::Attached(t) => Some(t.get_location_conf()), - TenantSlot::Secondary => { - todo!(); - } + TenantSlot::Secondary(s) => Some(s.get_location_conf()), TenantSlot::InProgress(_) => None, }; (tenant_shard_id, v) diff --git a/pageserver/src/tenant.rs b/pageserver/src/tenant.rs index 97114d3be9..90749f48b1 100644 --- a/pageserver/src/tenant.rs +++ b/pageserver/src/tenant.rs @@ -18,8 +18,6 @@ use futures::stream::FuturesUnordered; use futures::FutureExt; use futures::StreamExt; use pageserver_api::models; -use pageserver_api::models::LocationConfig; -use pageserver_api::models::LocationConfigMode; use pageserver_api::models::ShardParameters; use pageserver_api::models::TimelineState; use pageserver_api::shard::ShardIdentity; @@ -2312,19 +2310,19 @@ impl Tenant { /// For API access: generate a LocationConfig equivalent to the one that would be used to /// create a Tenant in the same state. Do not use this in hot paths: it's for relatively /// rare external API calls, like a reconciliation at startup. - pub(crate) fn get_location_conf(&self) -> LocationConfig { + pub(crate) fn get_location_conf(&self) -> models::LocationConfig { let conf = self.tenant_conf.read().unwrap(); let location_config_mode = match conf.location.attach_mode { - AttachmentMode::Single => LocationConfigMode::AttachedSingle, - AttachmentMode::Multi => LocationConfigMode::AttachedMulti, - AttachmentMode::Stale => LocationConfigMode::AttachedStale, + AttachmentMode::Single => models::LocationConfigMode::AttachedSingle, + AttachmentMode::Multi => models::LocationConfigMode::AttachedMulti, + AttachmentMode::Stale => models::LocationConfigMode::AttachedStale, }; // We have a pageserver TenantConf, we need the API-facing TenantConfig. let tenant_config: models::TenantConfig = conf.tenant_conf.clone().into(); - LocationConfig { + models::LocationConfig { mode: location_config_mode, generation: self.generation.into(), secondary_conf: None, diff --git a/pageserver/src/tenant/config.rs b/pageserver/src/tenant/config.rs index de6fa24731..b40422c8a2 100644 --- a/pageserver/src/tenant/config.rs +++ b/pageserver/src/tenant/config.rs @@ -555,9 +555,35 @@ impl TryFrom for TenantConfOpt { } } +/// This is a conversion from our internal tenant config object to the one used +/// in external APIs. impl From for models::TenantConfig { fn from(value: TenantConfOpt) -> Self { - todo!(); + fn humantime(d: Duration) -> String { + format!("{}s", d.as_secs()) + } + Self { + checkpoint_distance: value.checkpoint_distance, + checkpoint_timeout: value.checkpoint_timeout.map(humantime), + compaction_target_size: value.compaction_target_size, + compaction_period: value.compaction_period.map(humantime), + compaction_threshold: value.compaction_threshold, + gc_horizon: value.gc_horizon, + gc_period: value.gc_period.map(humantime), + image_creation_threshold: value.image_creation_threshold, + pitr_interval: value.pitr_interval.map(humantime), + walreceiver_connect_timeout: value.walreceiver_connect_timeout.map(humantime), + lagging_wal_timeout: value.lagging_wal_timeout.map(humantime), + max_lsn_wal_lag: value.max_lsn_wal_lag, + trace_read_requests: value.trace_read_requests, + eviction_policy: value.eviction_policy, + min_resident_size_override: value.min_resident_size_override, + evictions_low_residence_duration_metric_threshold: value + .evictions_low_residence_duration_metric_threshold + .map(humantime), + gc_feedback: value.gc_feedback, + heatmap_period: value.heatmap_period.map(humantime), + } } } diff --git a/pageserver/src/tenant/secondary.rs b/pageserver/src/tenant/secondary.rs index 2331447266..243473ca15 100644 --- a/pageserver/src/tenant/secondary.rs +++ b/pageserver/src/tenant/secondary.rs @@ -14,7 +14,7 @@ use self::{ use super::{config::SecondaryLocationConfig, mgr::TenantManager}; -use pageserver_api::shard::TenantShardId; +use pageserver_api::{models, shard::TenantShardId}; use remote_storage::GenericRemoteStorage; use tokio_util::sync::CancellationToken; @@ -110,6 +110,31 @@ impl SecondaryTenant { fn get_tenant_shard_id(&self) -> &TenantShardId { &self.tenant_shard_id } + + /// For API access: generate a LocationConfig equivalent to the one that would be used to + /// create a Tenant in the same state. Do not use this in hot paths: it's for relatively + /// rare external API calls, like a reconciliation at startup. + pub(crate) fn get_location_conf(&self) -> models::LocationConfig { + let conf = self.detail.lock().unwrap().config.clone(); + + let conf = models::LocationConfigSecondary { warm: conf.warm }; + + models::LocationConfig { + mode: models::LocationConfigMode::Secondary, + generation: None, + secondary_conf: Some(conf), + shard_number: self.tenant_shard_id.shard_number.0, + shard_count: self.tenant_shard_id.shard_count.0, + // FIXME: our location conf calls include a stripe size, but we don't + // store it in secondary mode. See comment about tenant_conf below. + shard_stripe_size: 0, + // FIXME: our location conf calls include a config, but we don't store it + // here because we don't use any of the values. But this makes it awkward + // for external services to check current state against intended state by + // direct equality. + tenant_conf: models::TenantConfig::default(), + } + } } /// The SecondaryController is a pseudo-rpc client for administrative control of secondary mode downloads, diff --git a/vendor/postgres-v14 b/vendor/postgres-v14 index 03358bb0b5..0bb356aa0c 160000 --- a/vendor/postgres-v14 +++ b/vendor/postgres-v14 @@ -1 +1 @@ -Subproject commit 03358bb0b5e0d33c238710139e768db9e75cfcc8 +Subproject commit 0bb356aa0cd1582112926fbcf0b5370222c2db6d diff --git a/vendor/postgres-v15 b/vendor/postgres-v15 index a2dc225ddf..24333abb81 160000 --- a/vendor/postgres-v15 +++ b/vendor/postgres-v15 @@ -1 +1 @@ -Subproject commit a2dc225ddfc8cae1849aa2316f435c58f0333d8c +Subproject commit 24333abb81a9ecae4541019478f0bf7d0b289df7 diff --git a/vendor/postgres-v16 b/vendor/postgres-v16 index 225071f482..863b71572b 160000 --- a/vendor/postgres-v16 +++ b/vendor/postgres-v16 @@ -1 +1 @@ -Subproject commit 225071f482774943854c2eec4540757e01171557 +Subproject commit 863b71572bc441581efb3bbee2ad18af037be1bb