Add lazy_slru_download_threshold parameter to page server config

This commit is contained in:
Konstantin Knizhnik
2025-02-27 08:46:51 +02:00
parent 6b76e1c526
commit aa367e5d82
7 changed files with 64 additions and 17 deletions

View File

@@ -80,7 +80,7 @@ pub async fn send_basebackup_tarball<'a, W>(
prev_lsn: Option<Lsn>,
full_backup: bool,
replica: bool,
lazy_slru_download: bool,
lazy_slru_download_enabled: bool,
ctx: &'a RequestContext,
) -> Result<(), BasebackupError>
where
@@ -132,8 +132,8 @@ where
};
info!(
"taking basebackup lsn={}, prev_lsn={} (full_backup={}, replica={}, lazy_slru_download={})",
backup_lsn, prev_lsn, full_backup, replica, lazy_slru_download
"taking basebackup lsn={}, prev_lsn={} (full_backup={}, replica={}, lazy_slru_download_enabled={})",
backup_lsn, prev_lsn, full_backup, replica, lazy_slru_download_enabled
);
let basebackup = Basebackup {
@@ -143,7 +143,7 @@ where
prev_record_lsn: prev_lsn,
full_backup,
replica,
lazy_slru_dpownload,
lazy_slru_download_enabled,
ctx,
io_concurrency: IoConcurrency::spawn_from_conf(
timeline.conf,
@@ -172,7 +172,7 @@ where
prev_record_lsn: Lsn,
full_backup: bool,
replica: bool,
lazy_slru_download: bool,
lazy_slru_download_enabled: bool,
ctx: &'a RequestContext,
io_concurrency: IoConcurrency,
}
@@ -311,7 +311,9 @@ where
self.timeline.pg_version,
)?;
let lazy_slru_download = (self.self.lazy_slru_download || timeline.get_lazy_slru_download()) && !self.full_backup;
let lazy_slru_download = self.lazy_slru_download_enabled
&& self.timeline.get_lazy_slru_download()
&& !self.full_backup;
let pgversion = self.timeline.pg_version;
let subdirs = dispatch_pgversion!(pgversion, &pgv::bindings::PGDATA_SUBDIRS[..]);
@@ -362,6 +364,10 @@ where
.get_vectored(query, self.io_concurrency.clone(), self.ctx)
.await?;
if blocks.len() > self.timeline.conf.lazy_slru_download_threshold {
self.timeline.set_lazy_slru_download(true);
}
for (key, block) in blocks {
let block = block?;
slru_builder.add_block(&key, block).await?;

View File

@@ -224,6 +224,10 @@ pub struct PageServerConf {
/// Does not force TLS: the client negotiates TLS usage during the handshake.
/// Uses key and certificate from ssl_key_file/ssl_cert_file.
pub enable_tls_page_service_api: bool,
///
/// Size of SLRU object in blocks which triggers on-demand download rarther than including it in basebackup
///
pub lazy_slru_download_threshold: usize,
}
/// Token for authentication to safekeepers
@@ -397,6 +401,7 @@ impl PageServerConf {
generate_unarchival_heatmap,
tracing,
enable_tls_page_service_api,
lazy_slru_download_threshold,
} = config_toml;
let mut conf = PageServerConf {
@@ -501,6 +506,7 @@ impl PageServerConf {
}
None => Vec::new(),
},
lazy_slru_download_threshold,
};
// ------------------------------------------------------------

View File

@@ -2726,7 +2726,7 @@ impl BaseBackupCmd {
lsn,
gzip,
replica,
lazy_slru_download,
lazy_slru_download,
})
}
}
@@ -2941,7 +2941,7 @@ where
lsn,
gzip,
replica,
lazy_slru_download,
lazy_slru_download,
}) => {
tracing::Span::current()
.record("tenant_id", field::display(tenant_id))
@@ -3001,6 +3001,7 @@ where
true,
false,
false,
false,
&ctx,
)
.await?;
@@ -3220,7 +3221,7 @@ mod tests {
lsn: Some(Lsn::from_str("0/16ABCDE").unwrap()),
gzip: true,
replica: true,
lazy_slru_download: false
lazy_slru_download: false
})
);
let cmd = PageServiceCmd::parse(&format!("fullbackup {tenant_id} {timeline_id}")).unwrap();

View File

@@ -285,6 +285,11 @@ pub struct Timeline {
// them yet.
disk_consistent_lsn: AtomicLsn,
//
// Flag indicating that SLRU for this timeline should be loaded on demand rathert than included in basesbackup
//
lazy_slru_download: AtomicBool,
// Parent timeline that this timeline was branched from, and the LSN
// of the branch point.
ancestor_timeline: Option<Arc<Timeline>>,
@@ -2491,6 +2496,9 @@ impl Timeline {
}
pub(crate) fn get_lazy_slru_download(&self) -> bool {
if self.lazy_slru_download.load(AtomicOrdering::Relaxed) {
return true;
}
let tenant_conf = self.tenant_conf.load();
tenant_conf
.tenant_conf
@@ -2498,6 +2506,7 @@ impl Timeline {
.unwrap_or(self.conf.default_tenant_conf.lazy_slru_download)
}
<<<<<<< HEAD
/// Checks if a get page request should get perf tracing
///
/// The configuration priority is: tenant config override, default tenant config,
@@ -2521,6 +2530,11 @@ impl Timeline {
}
None => false,
}
=======
pub(crate) fn set_lazy_slru_download(&self, enabled: bool) {
self.lazy_slru_download
.store(enabled, AtomicOrdering::Relaxed);
>>>>>>> 7f7f353dc (Add lazy_slru_download_threshold parameter to page server config)
}
fn get_checkpoint_distance(&self) -> u64 {
@@ -2898,6 +2912,7 @@ impl Timeline {
prev: metadata.prev_record_lsn().unwrap_or(Lsn(0)),
}),
disk_consistent_lsn: AtomicLsn::new(disk_consistent_lsn.0),
lazy_slru_download: AtomicBool::new(false),
gc_compaction_state: ArcSwap::new(Arc::new(gc_compaction_state)),