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 500 : pub async fn task_main(conf: SafeKeeperConf) -> anyhow::Result<()> {
11 500 : let wal_removal_interval = Duration::from_millis(5000);
12 : loop {
13 1590 : let tlis = GlobalTimelines::get_all();
14 2971 : for tli in &tlis {
15 1381 : if !tli.is_active().await {
16 18 : continue;
17 1363 : }
18 1363 : let ttid = tli.ttid;
19 1363 : if let Err(e) = tli
20 1363 : .maybe_persist_control_file()
21 1363 : .instrument(info_span!("", tenant = %ttid.tenant_id, timeline = %ttid.timeline_id))
22 116 : .await
23 : {
24 UBC 0 : warn!("failed to persist control file: {e}");
25 CBC 1363 : }
26 1363 : if let Err(e) = tli
27 1363 : .remove_old_wal(conf.wal_backup_enabled)
28 1363 : .instrument(info_span!("", tenant = %ttid.tenant_id, timeline = %ttid.timeline_id))
29 126 : .await
30 : {
31 UBC 0 : error!("failed to remove WAL: {}", e);
32 CBC 1363 : }
33 : }
34 1590 : sleep(wal_removal_interval).await;
35 : }
36 : }
|