mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-15 12:10:37 +00:00
Temporary enable it on staging to help with https://github.com/neondatabase/neon/issues/6403 Can be also deployed to prod if will work well on staging.
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
//! Thread removing old WAL.
|
|
|
|
use std::time::Duration;
|
|
|
|
use tokio::time::sleep;
|
|
use tracing::*;
|
|
|
|
use crate::{GlobalTimelines, SafeKeeperConf};
|
|
|
|
const ALLOW_INACTIVE_TIMELINES: bool = true;
|
|
|
|
pub async fn task_main(conf: SafeKeeperConf) -> anyhow::Result<()> {
|
|
let wal_removal_interval = Duration::from_millis(5000);
|
|
loop {
|
|
let now = tokio::time::Instant::now();
|
|
let mut active_timelines = 0;
|
|
|
|
let tlis = GlobalTimelines::get_all();
|
|
for tli in &tlis {
|
|
let is_active = tli.is_active().await;
|
|
if is_active {
|
|
active_timelines += 1;
|
|
}
|
|
if !ALLOW_INACTIVE_TIMELINES && !is_active {
|
|
continue;
|
|
}
|
|
let ttid = tli.ttid;
|
|
async {
|
|
if let Err(e) = tli.maybe_persist_control_file().await {
|
|
warn!("failed to persist control file: {e}");
|
|
}
|
|
if let Err(e) = tli.remove_old_wal(conf.wal_backup_enabled).await {
|
|
error!("failed to remove WAL: {}", e);
|
|
}
|
|
}
|
|
.instrument(info_span!("WAL removal", ttid = %ttid))
|
|
.await;
|
|
}
|
|
|
|
let elapsed = now.elapsed();
|
|
let total_timelines = tlis.len();
|
|
|
|
if elapsed > wal_removal_interval {
|
|
info!(
|
|
"WAL removal is too long, processed {} active timelines ({} total) in {:?}",
|
|
active_timelines, total_timelines, elapsed
|
|
);
|
|
}
|
|
|
|
sleep(wal_removal_interval).await;
|
|
}
|
|
}
|