TLA Line data Source code
1 : //! Thread removing old WAL.
2 :
3 : use std::time::Duration;
4 :
5 : use tokio::time::sleep;
6 : use tracing::*;
7 :
8 : use crate::{GlobalTimelines, SafeKeeperConf};
9 :
10 CBC 485 : pub async fn task_main(conf: SafeKeeperConf) -> anyhow::Result<()> {
11 485 : let wal_removal_interval = Duration::from_millis(5000);
12 : loop {
13 2067 : let tlis = GlobalTimelines::get_all();
14 4028 : for tli in &tlis {
15 1961 : if !tli.is_active().await {
16 115 : continue;
17 1846 : }
18 1846 : let ttid = tli.ttid;
19 1846 : async {
20 1846 : if let Err(e) = tli.maybe_persist_control_file().await {
21 UBC 0 : warn!("failed to persist control file: {e}");
22 CBC 1846 : }
23 1846 : if let Err(e) = tli.remove_old_wal(conf.wal_backup_enabled).await {
24 UBC 0 : error!("failed to remove WAL: {}", e);
25 CBC 1846 : }
26 1846 : }
27 1846 : .instrument(info_span!("WAL removal", ttid = %ttid))
28 258 : .await;
29 : }
30 2067 : sleep(wal_removal_interval).await;
31 : }
32 : }
|