Compare commits

...

15 Commits

Author SHA1 Message Date
Konstantin Knizhnik
1c4bed27be Resolve merge conflicts 2025-04-16 08:20:46 +03:00
Konstantin Knizhnik
fdf0f1bdc0 Fix rust formatting 2025-04-16 07:49:47 +03:00
Konstantin Knizhnik
0bdd388dd8 Make it possible to control lazy_sru_download through tenant config 2025-04-16 07:49:47 +03:00
Konstantin Knizhnik
712b4cf83c Update compute_tools/src/compute.rs
Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
2025-04-16 07:49:46 +03:00
Konstantin Knizhnik
15b6bb5026 Update libs/compute_api/src/spec.rs
Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
2025-04-16 07:49:44 +03:00
Konstantin Knizhnik
61d642e541 Update pageserver/src/page_service.rs
Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
2025-04-16 07:48:59 +03:00
Konstantin Knizhnik
1d24b887b8 Refector construction of basebackup command 2025-04-16 07:48:58 +03:00
Konstantin Knizhnik
955175c791 Make clippy happy 2025-04-16 07:48:58 +03:00
Konstantin Knizhnik
5fb0bcdd6a Make clippy happy 2025-04-16 07:48:58 +03:00
Konstantin Knizhnik
f146fa86f8 Use lazy SLRU download for all timelines is feature flag is set 2025-04-16 07:48:56 +03:00
Konstantin Knizhnik
961008116b Use lazy SLRU download for all timelines is feature flag is set 2025-04-16 07:47:55 +03:00
Konstantin Knizhnik
42d2d3addc Fix checking lazy SLRU download condition 2025-04-16 07:45:35 +03:00
Konstantin Knizhnik
06d0bed566 Always update lazy_slru_download flag during basebackup 2025-04-16 07:45:35 +03:00
Konstantin Knizhnik
aa367e5d82 Add lazy_slru_download_threshold parameter to page server config 2025-04-16 07:45:33 +03:00
Konstantin Knizhnik
6b76e1c526 Add lazy_slru_download compute feature flag 2025-04-16 07:42:32 +03:00
5 changed files with 83 additions and 41 deletions

View File

@@ -897,32 +897,28 @@ impl ComputeNode {
let mut client = config.connect(NoTls)?;
let pageserver_connect_micros = start_time.elapsed().as_micros() as u64;
let basebackup_cmd = match lsn {
Lsn(0) => {
if spec.spec.mode != ComputeMode::Primary {
format!(
"basebackup {} {} --gzip --replica",
spec.tenant_id, spec.timeline_id
)
} else {
format!("basebackup {} {} --gzip", spec.tenant_id, spec.timeline_id)
}
}
_ => {
if spec.spec.mode != ComputeMode::Primary {
format!(
"basebackup {} {} {} --gzip --replica",
spec.tenant_id, spec.timeline_id, lsn
)
} else {
format!(
"basebackup {} {} {} --gzip",
spec.tenant_id, spec.timeline_id, lsn
)
}
}
};
let tenant_id = spec.tenant_id.to_string();
let timeline_id = spec.timeline_id.to_string();
let lsn_str = lsn.to_string();
let mut cmd = Vec::new();
cmd.push("basebackup");
cmd.push(&tenant_id);
cmd.push(&timeline_id);
if lsn != Lsn::INVALID {
cmd.push(&lsn_str);
}
cmd.push("--gzip");
if spec.spec.mode != ComputeMode::Primary {
cmd.push("--replica");
}
if spec
.spec
.features
.contains(&ComputeFeature::LazySlruDownload)
{
cmd.push("--lazy-slru-download")
}
let basebackup_cmd = cmd.join(" ");
let copyreader = client.copy_out(basebackup_cmd.as_str())?;
let mut measured_reader = MeasuredReader::new(copyreader);
let mut bufreader = std::io::BufReader::new(&mut measured_reader);

View File

@@ -183,6 +183,9 @@ pub enum ComputeFeature {
/// track short-lived connections as user activity.
ActivityMonitorExperimental,
/// Download all SLRU files on demand
LazySlruDownload,
/// This is a special feature flag that is used to represent unknown feature flags.
/// Basically all unknown to enum flags are represented as this one. See unit test
/// `parse_unknown_features()` for more details.

View File

@@ -73,6 +73,7 @@ impl From<GetVectoredError> for BasebackupError {
/// * When working without safekeepers. In this situation it is important to match the lsn
/// we are taking basebackup on with the lsn that is used in pageserver's walreceiver
/// to start the replication.
#[allow(clippy::too_many_arguments)]
pub async fn send_basebackup_tarball<'a, W>(
write: &'a mut W,
timeline: &'a Timeline,
@@ -80,6 +81,7 @@ pub async fn send_basebackup_tarball<'a, W>(
prev_lsn: Option<Lsn>,
full_backup: bool,
replica: bool,
lazy_slru_download_enabled: bool,
ctx: &'a RequestContext,
) -> Result<(), BasebackupError>
where
@@ -131,8 +133,8 @@ where
};
info!(
"taking basebackup lsn={}, prev_lsn={} (full_backup={}, replica={})",
backup_lsn, prev_lsn, full_backup, replica
"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 {
@@ -142,6 +144,7 @@ where
prev_record_lsn: prev_lsn,
full_backup,
replica,
lazy_slru_download_enabled,
ctx,
io_concurrency: IoConcurrency::spawn_from_conf(
timeline.conf,
@@ -170,6 +173,7 @@ where
prev_record_lsn: Lsn,
full_backup: bool,
replica: bool,
lazy_slru_download_enabled: bool,
ctx: &'a RequestContext,
io_concurrency: IoConcurrency,
}
@@ -308,7 +312,10 @@ where
self.timeline.pg_version,
)?;
let lazy_slru_download = self.timeline.get_lazy_slru_download() && !self.full_backup;
let lazy_slru_download = self
.timeline
.get_lazy_slru_download(self.lazy_slru_download_enabled)
&& !self.full_backup;
let pgversion = self.timeline.pg_version;
let subdirs = dispatch_pgversion!(pgversion, &pgv::bindings::PGDATA_SUBDIRS[..]);

View File

@@ -2394,6 +2394,7 @@ impl PageServerHandler {
full_backup: bool,
gzip: bool,
replica: bool,
lazy_slru_download: bool,
ctx: &RequestContext,
) -> Result<(), QueryError>
where
@@ -2461,6 +2462,7 @@ impl PageServerHandler {
prev_lsn,
full_backup,
replica,
lazy_slru_download,
&ctx,
)
.await
@@ -2484,6 +2486,7 @@ impl PageServerHandler {
prev_lsn,
full_backup,
replica,
lazy_slru_download,
&ctx,
)
.await
@@ -2501,6 +2504,7 @@ impl PageServerHandler {
prev_lsn,
full_backup,
replica,
lazy_slru_download,
&ctx,
)
.await
@@ -2550,7 +2554,7 @@ impl PageServerHandler {
}
}
/// `basebackup tenant timeline [lsn] [--gzip] [--replica]`
/// `basebackup tenant timeline [lsn] [--gzip] [--replica] [--lazy-slru-download]`
#[derive(Debug, Clone, Eq, PartialEq)]
struct BaseBackupCmd {
tenant_id: TenantId,
@@ -2558,6 +2562,7 @@ struct BaseBackupCmd {
lsn: Option<Lsn>,
gzip: bool,
replica: bool,
lazy_slru_download: bool,
}
/// `fullbackup tenant timeline [lsn] [prev_lsn]`
@@ -2690,6 +2695,7 @@ impl BaseBackupCmd {
let mut gzip = false;
let mut replica = false;
let mut lazy_slru_download = false;
for &param in &parameters[flags_parse_from..] {
match param {
@@ -2705,6 +2711,12 @@ impl BaseBackupCmd {
}
replica = true
}
"--lazy-slru-download" => {
if lazy_slru_download {
bail!("duplicate parameter for basebackup command: {param}")
}
lazy_slru_download = true
}
_ => bail!("invalid parameter for basebackup command: {param}"),
}
}
@@ -2714,6 +2726,7 @@ impl BaseBackupCmd {
lsn,
gzip,
replica,
lazy_slru_download,
})
}
}
@@ -2928,6 +2941,7 @@ where
lsn,
gzip,
replica,
lazy_slru_download,
}) => {
tracing::Span::current()
.record("tenant_id", field::display(tenant_id))
@@ -2949,6 +2963,7 @@ where
false,
gzip,
replica,
lazy_slru_download,
&ctx,
)
.await?;
@@ -2986,6 +3001,7 @@ where
true,
false,
false,
false,
&ctx,
)
.await?;
@@ -3120,7 +3136,8 @@ mod tests {
timeline_id,
lsn: None,
gzip: false,
replica: false
replica: false,
lazy_slru_download: false
})
);
let cmd =
@@ -3132,7 +3149,8 @@ mod tests {
timeline_id,
lsn: None,
gzip: true,
replica: false
replica: false,
lazy_slru_download: false
})
);
let cmd =
@@ -3144,7 +3162,8 @@ mod tests {
timeline_id,
lsn: None,
gzip: false,
replica: false
replica: false,
lazy_slru_download: false
})
);
let cmd = PageServiceCmd::parse(&format!("basebackup {tenant_id} {timeline_id} 0/16ABCDE"))
@@ -3156,7 +3175,8 @@ mod tests {
timeline_id,
lsn: Some(Lsn::from_str("0/16ABCDE").unwrap()),
gzip: false,
replica: false
replica: false,
lazy_slru_download: false
})
);
let cmd = PageServiceCmd::parse(&format!(
@@ -3170,7 +3190,23 @@ mod tests {
timeline_id,
lsn: None,
gzip: true,
replica: true
replica: true,
lazy_slru_download: false
})
);
let cmd = PageServiceCmd::parse(&format!(
"basebackup {tenant_id} {timeline_id} --replica --gzip --lazy-slru-download"
))
.unwrap();
assert_eq!(
cmd,
PageServiceCmd::BaseBackup(BaseBackupCmd {
tenant_id,
timeline_id,
lsn: None,
gzip: true,
replica: true,
lazy_slru_download: true
})
);
let cmd = PageServiceCmd::parse(&format!(
@@ -3184,7 +3220,8 @@ mod tests {
timeline_id,
lsn: Some(Lsn::from_str("0/16ABCDE").unwrap()),
gzip: true,
replica: true
replica: true,
lazy_slru_download: false
})
);
let cmd = PageServiceCmd::parse(&format!("fullbackup {tenant_id} {timeline_id}")).unwrap();

View File

@@ -2490,12 +2490,11 @@ impl Timeline {
tenant_conf.is_gc_blocked_by_lsn_lease_deadline()
}
pub(crate) fn get_lazy_slru_download(&self) -> bool {
pub(crate) fn get_lazy_slru_download(&self, lazy_slru_download_enabled_by_cp: bool) -> bool {
let tenant_conf = self.tenant_conf.load();
tenant_conf
.tenant_conf
.lazy_slru_download
.unwrap_or(self.conf.default_tenant_conf.lazy_slru_download)
tenant_conf.tenant_conf.lazy_slru_download.unwrap_or(
lazy_slru_download_enabled_by_cp || self.conf.default_tenant_conf.lazy_slru_download,
)
}
/// Checks if a get page request should get perf tracing