LCOV - code coverage report
Current view: top level - safekeeper/src - remove_wal.rs (source / functions) Coverage Total Hit
Test: 5fe7fa8d483b39476409aee736d6d5e32728bfac.info Lines: 92.9 % 14 13
Test Date: 2025-03-12 16:10:49 Functions: 100.0 % 1 1

            Line data    Source code
       1              : use utils::lsn::Lsn;
       2              : 
       3              : use crate::timeline_manager::StateSnapshot;
       4              : 
       5              : /// Get oldest LSN we still need to keep.
       6              : ///
       7              : /// We hold WAL till it is consumed by
       8              : /// 1) pageserver (remote_consistent_lsn)
       9              : /// 2) s3 offloading.
      10              : /// 3) Additionally we must store WAL since last local commit_lsn because
      11              : ///    that's where we start looking for last WAL record on start.
      12              : ///
      13              : /// If some peer safekeeper misses data it will fetch it from the remote
      14              : /// storage. While it is safe to use inmem values for determining horizon, we
      15              : /// use persistent to make possible normal states less surprising. All segments
      16              : /// covering LSNs before horizon_lsn can be removed.
      17           34 : pub(crate) fn calc_horizon_lsn(state: &StateSnapshot, extra_horizon_lsn: Option<Lsn>) -> Lsn {
      18              :     use std::cmp::min;
      19              : 
      20           34 :     let mut horizon_lsn = state.cfile_remote_consistent_lsn;
      21           34 :     // we don't want to remove WAL that is not yet offloaded to s3
      22           34 :     horizon_lsn = min(horizon_lsn, state.cfile_backup_lsn);
      23           34 :     // Min by local commit_lsn to be able to begin reading WAL from somewhere on
      24           34 :     // sk start. Technically we don't allow local commit_lsn to be higher than
      25           34 :     // flush_lsn, but let's be double safe by including it as well.
      26           34 :     horizon_lsn = min(horizon_lsn, state.cfile_commit_lsn);
      27           34 :     horizon_lsn = min(horizon_lsn, state.flush_lsn);
      28           34 :     if let Some(extra_horizon_lsn) = extra_horizon_lsn {
      29            0 :         horizon_lsn = min(horizon_lsn, extra_horizon_lsn);
      30           34 :     }
      31              : 
      32           34 :     horizon_lsn
      33           34 : }
        

Generated by: LCOV version 2.1-beta