Skip to main content

nucleus/checkpoint/
state.rs

1use crate::error::StateTransition;
2
3/// Checkpoint state tracking
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum CheckpointState {
6    /// No checkpoint in progress
7    None,
8    /// Checkpoint is being created
9    Dumping,
10    /// Checkpoint is complete
11    Dumped,
12    /// Restore is in progress
13    Restoring,
14    /// Restore is complete
15    Restored,
16}
17
18impl StateTransition for CheckpointState {
19    fn can_transition_to(&self, next: &CheckpointState) -> bool {
20        matches!(
21            (self, next),
22            (CheckpointState::None, CheckpointState::Dumping)
23                | (CheckpointState::Dumping, CheckpointState::Dumped)
24                | (CheckpointState::Dumping, CheckpointState::None)
25                | (CheckpointState::None, CheckpointState::Restoring)
26                | (CheckpointState::Restoring, CheckpointState::Restored)
27                | (CheckpointState::Restoring, CheckpointState::None)
28        )
29    }
30
31    fn is_terminal(&self) -> bool {
32        false
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_abort_transitions() {
42        // BUG-17: Dumping and Restoring must be able to transition back to None (abort)
43        let state = CheckpointState::Dumping;
44        assert!(
45            state.can_transition_to(&CheckpointState::None),
46            "Dumping must be able to abort back to None"
47        );
48        let state = CheckpointState::Restoring;
49        assert!(
50            state.can_transition_to(&CheckpointState::None),
51            "Restoring must be able to abort back to None"
52        );
53    }
54}