Spawn the checkpoint manager as a background Tokio task. Runs `run_checkpoint_cycle` at the configured interval until the shutdown signal is received. Performs a final checkpoint on graceful shutdown.
(
shared: Arc<crate::control::state::SharedState>,
num_cores: usize,
config: CheckpointManagerConfig,
mut shutdown: tokio::sync::watch::Receiver<bool>,
)
| 278 | /// Runs `run_checkpoint_cycle` at the configured interval until the |
| 279 | /// shutdown signal is received. Performs a final checkpoint on graceful shutdown. |
| 280 | pub fn spawn_checkpoint_task( |
| 281 | shared: Arc<crate::control::state::SharedState>, |
| 282 | num_cores: usize, |
| 283 | config: CheckpointManagerConfig, |
| 284 | mut shutdown: tokio::sync::watch::Receiver<bool>, |
| 285 | ) -> tokio::task::JoinHandle<()> { |
| 286 | tokio::spawn(async move { |
| 287 | info!( |
| 288 | interval_secs = config.interval.as_secs(), |
| 289 | "checkpoint manager started" |
| 290 | ); |
| 291 | |
| 292 | loop { |
| 293 | tokio::select! { |
| 294 | _ = tokio::time::sleep(config.interval) => {} |
| 295 | _ = shutdown.changed() => { |
| 296 | if *shutdown.borrow() { |
| 297 | info!("shutdown: running final checkpoint"); |
| 298 | run_checkpoint_cycle( |
| 299 | &shared.dispatcher, |
| 300 | &shared.tracker, |
| 301 | &shared.wal, |
| 302 | num_cores, |
| 303 | config.core_timeout, |
| 304 | shared.cold_storage.clone(), |
| 305 | shared.credentials.catalog().as_ref(), |
| 306 | ).await; |
| 307 | info!("checkpoint manager stopped"); |
| 308 | return; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | run_checkpoint_cycle( |
| 314 | &shared.dispatcher, |
| 315 | &shared.tracker, |
| 316 | &shared.wal, |
| 317 | num_cores, |
| 318 | config.core_timeout, |
| 319 | shared.cold_storage.clone(), |
| 320 | shared.credentials.catalog().as_ref(), |
| 321 | ) |
| 322 | .await; |
| 323 | } |
| 324 | }) |
| 325 | } |
| 326 | |
| 327 | /// Archive WAL segments that will be deleted by the upcoming `truncate_before(checkpoint_lsn)`. |
| 328 | /// |
no test coverage detected