mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-21 07:00:38 +00:00
This is a preparation for https://github.com/neondatabase/neon/issues/6337. The idea is to add FullAccessTimeline, which will act as a guard for tasks requiring access to WAL files. Eviction will be blocked on these tasks and WAL won't be deleted from disk until there is at least one active FullAccessTimeline. To get FullAccessTimeline, tasks call `tli.full_access_guard().await?`. After eviction is implemented, this function will be responsible for downloading missing WAL file and waiting until the download finishes. This commit also contains other small refactorings: - Separate `get_tenant_dir` and `get_timeline_dir` functions for building a local path. This is useful for looking at usages and finding tasks requiring access to local filesystem. - `timeline_manager` is now responsible for spawning all background tasks - WAL removal task is now spawned instantly after horizon is updated
26 lines
925 B
Rust
26 lines
925 B
Rust
use utils::lsn::Lsn;
|
|
|
|
use crate::timeline_manager::StateSnapshot;
|
|
|
|
/// Get oldest LSN we still need to keep. We hold WAL till it is consumed
|
|
/// by all of 1) pageserver (remote_consistent_lsn) 2) peers 3) s3
|
|
/// offloading.
|
|
/// While it is safe to use inmem values for determining horizon,
|
|
/// we use persistent to make possible normal states less surprising.
|
|
/// All segments covering LSNs before horizon_lsn can be removed.
|
|
pub fn calc_horizon_lsn(state: &StateSnapshot, extra_horizon_lsn: Option<Lsn>) -> Lsn {
|
|
use std::cmp::min;
|
|
|
|
let mut horizon_lsn = min(
|
|
state.cfile_remote_consistent_lsn,
|
|
state.cfile_peer_horizon_lsn,
|
|
);
|
|
// we don't want to remove WAL that is not yet offloaded to s3
|
|
horizon_lsn = min(horizon_lsn, state.cfile_backup_lsn);
|
|
if let Some(extra_horizon_lsn) = extra_horizon_lsn {
|
|
horizon_lsn = min(horizon_lsn, extra_horizon_lsn);
|
|
}
|
|
|
|
horizon_lsn
|
|
}
|