MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / spawn_cold_tier_task

Function spawn_cold_tier_task

nodedb/src/control/cold_tier.rs:28–70  ·  view source on GitHub ↗

Spawn the cold tiering background task. Scans `data_dir/segments/` every `tier_check_interval_secs` seconds and uploads segment files older than `tier_after_secs` to cold storage. The local file is removed after a successful upload. The task exits cleanly when `shutdown_rx` is set to `true`.

(
    shared: Arc<SharedState>,
    settings: ColdStorageSettings,
    data_dir: PathBuf,
    mut shutdown_rx: tokio::sync::watch::Receiver<bool>,
)

Source from the content-addressed store, hash-verified

26///
27/// The task exits cleanly when `shutdown_rx` is set to `true`.
28pub fn spawn_cold_tier_task(
29 shared: Arc<SharedState>,
30 settings: ColdStorageSettings,
31 data_dir: PathBuf,
32 mut shutdown_rx: tokio::sync::watch::Receiver<bool>,
33) -> tokio::task::JoinHandle<()> {
34 let check_interval = Duration::from_secs(settings.tier_check_interval_secs);
35 let tier_after = Duration::from_secs(settings.tier_after_secs);
36 let prefix = settings.prefix.clone();
37 let segments_dir = data_dir.join("segments");
38
39 tokio::spawn(async move {
40 info!(
41 check_interval_secs = settings.tier_check_interval_secs,
42 tier_after_secs = settings.tier_after_secs,
43 segments_dir = %segments_dir.display(),
44 "cold tier task started"
45 );
46
47 loop {
48 tokio::select! {
49 _ = tokio::time::sleep(check_interval) => {}
50 _ = shutdown_rx.changed() => {
51 if *shutdown_rx.borrow() {
52 info!("cold tier task stopping on shutdown signal");
53 return;
54 }
55 }
56 }
57
58 let cold = match shared.cold_storage.as_ref() {
59 Some(c) => Arc::clone(c),
60 None => {
61 // Cold storage was removed from shared state; stop the task.
62 warn!("cold tier: cold_storage is None, stopping task");
63 return;
64 }
65 };
66
67 run_tier_cycle_at(&cold, &segments_dir, tier_after, &prefix).await;
68 }
69 })
70}
71
72/// Run one tiering cycle against the given segments directory.
73///

Callers 1

spawn_background_loopsFunction · 0.85

Calls 5

run_tier_cycle_atFunction · 0.85
joinMethod · 0.80
spawnFunction · 0.50
cloneMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected