This commit is contained in:
John Spray
2024-01-07 20:53:20 +00:00
parent 7c3d2f0c61
commit a1c1c1e747
7 changed files with 62 additions and 15 deletions

View File

@@ -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)

View File

@@ -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,

View File

@@ -555,9 +555,35 @@ impl TryFrom<toml_edit::Item> for TenantConfOpt {
}
}
/// This is a conversion from our internal tenant config object to the one used
/// in external APIs.
impl From<TenantConfOpt> 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),
}
}
}

View File

@@ -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,