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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2025 ReifyDB
use std::cmp;
use crate::encoded::{key::EncodedKey, row::EncodedRow};
#[derive(Debug, PartialEq, Eq)]
pub enum Delta {
Set {
key: EncodedKey,
row: EncodedRow,
},
/// Unset an entry, preserving the deleted values.
/// Symmetric with Set - use when the deleted data matters (e.g., row data, CDC).
Unset {
key: EncodedKey,
row: EncodedRow,
},
/// Remove an entry without preserving the deleted values.
/// Use when only the key matters (e.g., index entries, catalog metadata).
Remove {
key: EncodedKey,
},
/// Drop operation - completely erases historical versioned entries from storage.
/// Unlike Remove (which writes a tombstone and generates CDC), Drop:
/// - Deletes existing entries without writing anything new
/// - Never generates CDC events
/// - Only keeps the most recent version (aggressive cleanup)
Drop {
key: EncodedKey,
},
}
impl PartialOrd for Delta {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Delta {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.key().cmp(other.key())
}
}
impl Delta {
/// Returns the key
pub fn key(&self) -> &EncodedKey {
match self {
Self::Set {
key,
..
} => key,
Self::Unset {
key,
..
} => key,
Self::Remove {
key,
} => key,
Self::Drop {
key,
..
} => key,
}
}
/// Returns the encoded row, if None, it means the entry is marked as remove or drop.
pub fn row(&self) -> Option<&EncodedRow> {
match self {
Self::Set {
row,
..
} => Some(row),
Self::Unset {
..
} => None,
Self::Remove {
..
} => None,
Self::Drop {
..
} => None,
}
}
}
impl Clone for Delta {
fn clone(&self) -> Self {
match self {
Self::Set {
key,
row,
} => Self::Set {
key: key.clone(),
row: row.clone(),
},
Self::Unset {
key,
row,
} => Self::Unset {
key: key.clone(),
row: row.clone(),
},
Self::Remove {
key,
} => Self::Remove {
key: key.clone(),
},
Self::Drop {
key,
} => Self::Drop {
key: key.clone(),
},
}
}
}