have claude generate plumbing for standby_horizon_lease_length

This commit is contained in:
Christian Schwarz
2025-07-25 13:16:20 +02:00
parent 23d1029afd
commit 2ee24900ca
4 changed files with 54 additions and 10 deletions

View File

@@ -612,6 +612,10 @@ pub struct TenantConfigToml {
#[serde(with = "humantime_serde")]
pub lsn_lease_length_for_ts: Duration,
/// The length for a standby horizon lease.
#[serde(with = "humantime_serde")]
pub standby_horizon_lease_length: Duration,
/// Enable auto-offloading of timelines.
/// (either this flag or the pageserver-global one need to be set)
pub timeline_offloading: bool,
@@ -937,6 +941,7 @@ impl Default for TenantConfigToml {
image_creation_preempt_threshold: DEFAULT_IMAGE_CREATION_PREEMPT_THRESHOLD,
lsn_lease_length: LsnLease::DEFAULT_LENGTH,
lsn_lease_length_for_ts: LsnLease::DEFAULT_LENGTH_FOR_TS,
standby_horizon_lease_length: LsnLease::DEFAULT_STANDBY_HORIZON_LENGTH,
timeline_offloading: true,
rel_size_v2_enabled: false,
gc_compaction_enabled: DEFAULT_GC_COMPACTION_ENABLED,

View File

@@ -180,6 +180,9 @@ impl LsnLease {
/// `get_lsn_by_timestamp` request (1 minutes).
pub const DEFAULT_LENGTH_FOR_TS: Duration = Duration::from_secs(60);
/// The default length for a standby horizon lease (10 minutes).
pub const DEFAULT_STANDBY_HORIZON_LENGTH: Duration = Duration::from_secs(10 * 60);
/// Checks whether the lease is expired.
pub fn is_expired(&self, now: &SystemTime) -> bool {
now > &self.valid_until
@@ -643,6 +646,8 @@ pub struct TenantConfigPatch {
pub relsize_snapshot_cache_capacity: FieldPatch<usize>,
#[serde(skip_serializing_if = "FieldPatch::is_noop")]
pub basebackup_cache_enabled: FieldPatch<bool>,
#[serde(skip_serializing_if = "FieldPatch::is_noop")]
pub standby_horizon_lease_length: FieldPatch<String>,
}
/// Like [`crate::config::TenantConfigToml`], but preserves the information
@@ -775,6 +780,10 @@ pub struct TenantConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub basebackup_cache_enabled: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(with = "humantime_serde")]
pub standby_horizon_lease_length: Option<Duration>,
}
impl TenantConfig {
@@ -821,6 +830,7 @@ impl TenantConfig {
mut sampling_ratio,
mut relsize_snapshot_cache_capacity,
mut basebackup_cache_enabled,
mut standby_horizon_lease_length,
} = self;
patch.checkpoint_distance.apply(&mut checkpoint_distance);
@@ -925,6 +935,10 @@ impl TenantConfig {
patch
.basebackup_cache_enabled
.apply(&mut basebackup_cache_enabled);
patch
.standby_horizon_lease_length
.map(|v| humantime::parse_duration(&v))?
.apply(&mut standby_horizon_lease_length);
Ok(Self {
checkpoint_distance,
@@ -965,6 +979,7 @@ impl TenantConfig {
sampling_ratio,
relsize_snapshot_cache_capacity,
basebackup_cache_enabled,
standby_horizon_lease_length,
})
}
@@ -1076,6 +1091,9 @@ impl TenantConfig {
basebackup_cache_enabled: self
.basebackup_cache_enabled
.unwrap_or(global_conf.basebackup_cache_enabled),
standby_horizon_lease_length: self
.standby_horizon_lease_length
.unwrap_or(global_conf.standby_horizon_lease_length),
}
}
}

View File

@@ -4213,6 +4213,19 @@ impl TenantShard {
.unwrap_or(conf.default_tenant_conf.lsn_lease_length)
}
pub fn get_standby_horizon_lease_length(&self) -> Duration {
Self::get_standby_horizon_lease_length_impl(self.conf, &self.tenant_conf.load().tenant_conf)
}
pub fn get_standby_horizon_lease_length_impl(
conf: &'static PageServerConf,
tenant_conf: &pageserver_api::models::TenantConfig,
) -> Duration {
tenant_conf
.standby_horizon_lease_length
.unwrap_or(conf.default_tenant_conf.standby_horizon_lease_length)
}
pub fn get_timeline_offloading_enabled(&self) -> bool {
if self.conf.timeline_offloading {
return true;
@@ -8876,15 +8889,15 @@ mod tests {
],
// image layers
vec![
(Lsn(0x10), vec![(key1, test_img("metadata key 1"))]),
(
Lsn(0x30),
vec![
(key0, test_img("metadata key 0")),
(key3, test_img("metadata key 3")),
],
),
],
(Lsn(0x10), vec![(key1, test_img("metadata key 1"))]),
(
Lsn(0x30),
vec![
(key0, test_img("metadata key 0")),
(key3, test_img("metadata key 3")),
],
),
],
Lsn(0x30),
)
.await?;

View File

@@ -1886,7 +1886,7 @@ impl Timeline {
}
let applied_gc_cutoff_lsn =
todo!("think about boundary conditions? we didn't have any before though");
let length = todo!("duplicate init lease deadline logic?");
let length = self.get_standby_horizon_lease_length();
self.standby_horizons
.upsert_lease(lease_id, lsn, length)
.map(|lease| lease.valid_until)
@@ -2669,6 +2669,14 @@ impl Timeline {
.unwrap_or(self.conf.default_tenant_conf.lsn_lease_length_for_ts)
}
pub(crate) fn get_standby_horizon_lease_length(&self) -> Duration {
let tenant_conf = self.tenant_conf.load();
tenant_conf
.tenant_conf
.standby_horizon_lease_length
.unwrap_or(self.conf.default_tenant_conf.standby_horizon_lease_length)
}
pub(crate) fn is_gc_blocked_by_lsn_lease_deadline(&self) -> bool {
let tenant_conf = self.tenant_conf.load();
tenant_conf.is_gc_blocked_by_lsn_lease_deadline()