Skip to main content

veilid_core/table_store/tasks/
mod.rs

1pub mod cleanup_tables;
2pub mod flush_tables;
3
4use super::*;
5
6impl TableStore {
7    pub(super) fn setup_tasks(&self) {
8        // Set flush tables tick task
9        veilid_log!(self debug "starting flush tables task");
10        impl_setup_task_async!(self, Self, flush_tables_task, flush_tables_task_routine);
11
12        // Set cleanup tables tick task
13        veilid_log!(self debug "starting cleanup tables task");
14        impl_setup_task_async!(self, Self, cleanup_tables_task, cleanup_tables_task_routine);
15    }
16
17    #[cfg_attr(feature = "instrument", instrument(parent = None, level = "trace", target = "tstore", name = "TableStore::tick", skip_all, err))]
18    /// Run the periodic flush and cleanup table maintenance tasks.
19    ///
20    /// No-op before init or after shutdown. Each subtask only runs once its interval has elapsed (60s flush, 600s cleanup), so calling more often is cheap; an actual flush or cleanup run blocks on disk.
21    pub async fn tick(&self, _lag: Option<TimestampDuration>) -> EyreResult<()> {
22        let Ok(_startup_guard) = self.startup_lock.enter() else {
23            return Ok(());
24        };
25
26        // Run the flush tables task
27        self.flush_tables_task.tick().await?;
28
29        // Run the cleanup tables task
30        self.cleanup_tables_task.tick().await?;
31
32        Ok(())
33    }
34
35    #[cfg_attr(
36        feature = "instrument",
37        instrument(level = "trace", target = "stor", skip_all)
38    )]
39    pub(super) async fn cancel_tasks(&self) {
40        veilid_log!(self debug "stopping flush tables task");
41        if let Err(e) = self.flush_tables_task.stop().await {
42            veilid_log!(self warn "flush_tables_task not stopped: {}", e);
43        }
44        veilid_log!(self debug "stopping cleanup tables task");
45        if let Err(e) = self.cleanup_tables_task.stop().await {
46            veilid_log!(self warn "cleanup_tables_task not stopped: {}", e);
47        }
48    }
49}