Skip to main content

noxu_db/
checkpoint_config.rs

1//! Configuration for manual checkpoint operations.
2//!
3//! Implements `CheckpointConfig`.
4
5/// Specifies the attributes of a checkpoint operation invoked via
6/// [`Environment::checkpoint`][crate::environment::Environment::checkpoint].
7///
8/// # Defaults
9///
10/// All thresholds default to 0 (disabled) and `force = false`.  If all
11/// thresholds are 0 and `force = false`, calling `checkpoint()` still runs
12/// a checkpoint subject to normal dirty-node conditions.
13#[derive(Clone, Debug, Default)]
14pub struct CheckpointConfig {
15    /// If `true`, force a checkpoint regardless of whether thresholds have
16    /// been exceeded.  Equivalent to`CheckpointConfig.setForce(true)`.
17    pub force: bool,
18    /// Run a checkpoint if more than this many kibibytes of log data have
19    /// been written since the last checkpoint.  `0` means disabled.
20    pub k_bytes: u32,
21    /// Run a checkpoint if more than this many minutes have elapsed since
22    /// the last checkpoint.  `0` means disabled.
23    pub minutes: u32,
24    /// If `true`, perform a full checkpoint that minimises future recovery
25    /// time (writes all dirty nodes, not just the minimum required).
26    pub minimize_recovery_time: bool,
27}
28
29impl CheckpointConfig {
30    /// Creates a `CheckpointConfig` with all defaults.
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    /// Builder: set `force`.
36    pub fn with_force(mut self, force: bool) -> Self {
37        self.force = force;
38        self
39    }
40
41    /// Builder: set `k_bytes` threshold.
42    pub fn with_k_bytes(mut self, k_bytes: u32) -> Self {
43        self.k_bytes = k_bytes;
44        self
45    }
46
47    /// Builder: set `minutes` threshold.
48    pub fn with_minutes(mut self, minutes: u32) -> Self {
49        self.minutes = minutes;
50        self
51    }
52
53    /// Builder: set `minimize_recovery_time`.
54    pub fn with_minimize_recovery_time(mut self, minimize: bool) -> Self {
55        self.minimize_recovery_time = minimize;
56        self
57    }
58}