1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2025 ReifyDB
use serde::{Deserialize, Serialize};
use crate::common::CommitVersion;
/// Retention strategy for managing MVCC version cleanup
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum RetentionStrategy {
/// Keep all versions forever (default)
#[default]
KeepForever,
/// Keep only the last N versions
KeepVersions {
count: u64,
cleanup_mode: CleanupMode,
},
}
/// Cleanup mode determines how old versions are removed
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CleanupMode {
/// Create tombstones and CDC entries (only for non-deleted keys)
/// Simulates user deletion - maintains audit trail
Delete,
/// Silent removal from storage (works on both live and tombstoned keys)
/// No CDC entries, no tombstones - direct storage cleanup
Drop,
}
/// Action to take during cleanup
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CleanupAction {
/// Create tombstone (mark as deleted)
Delete,
/// Remove from storage
Drop,
/// Do nothing
Keep,
}
impl RetentionStrategy {
/// Check if a version should be retained based on the strategy
pub fn should_retain(
&self,
_version: CommitVersion,
_current_version: CommitVersion,
version_count: u64,
) -> bool {
match self {
RetentionStrategy::KeepForever => true,
RetentionStrategy::KeepVersions {
count,
..
} => {
// Keep if within the last N versions
version_count <= *count
}
}
}
/// Get the cleanup mode for this strategy
pub fn cleanup_mode(&self) -> Option<CleanupMode> {
match self {
RetentionStrategy::KeepForever => None,
RetentionStrategy::KeepVersions {
cleanup_mode,
..
} => Some(*cleanup_mode),
}
}
}