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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! Shared reconcile rule layer (issue #947).
//!
//! The Cassandra `Cells#reconcile` cell tie-break and the complex-deletion
//! strict-supersede + shadow-before-purge boundaries used to be implemented
//! TWICE and hand-synced:
//!
//! * the COMPACTION/merge path (`merge/mod.rs` + `merge/reconcile.rs`),
//! reconciling [`CellData`](super::merge::CellData);
//! * the FLUSH/write path
//! (`sstable::writer::data_writer::rows::DataWriter::merge_row_group`),
//! reconciling `MergedOp`.
//!
//! Both paths now adapt their concrete cell type into the minimal common
//! [`ReconcileCell`] view and call the pure decision functions below, so the
//! load-bearing comparisons live in ONE place and consistency is structural —
//! not a comment promising two copies were kept in sync.
//!
//! These are pure scalar predicates (no allocation, no I/O). The per-container
//! iteration (a `HashMap` of `CellData` winners vs. a `Vec` of `MergedOp`)
//! differs between the two call sites and stays at each site; only the
//! decision rules are shared.
//!
//! ## Parity anchors (do not change without a Cassandra reference)
//!
//! * [`cell_wins`] — `Cells#reconcile` (commit `a62c749`; issues #848/#498).
//! * [`complex_deletion_supersedes`] — strict-supersede (commit `bd244649`).
//! * [`element_survives_complex_deletion`] — shadow-before-purge boundary
//! (commit `f66fa14f`; the `<=` element-vs-marker rule, #498).
/// Minimal common view of a reconcilable cell.
///
/// The only two accessors BOTH write paths share for the `Cells#reconcile`
/// tie-break: the cell's write timestamp and whether it is a deletion
/// (tombstone). Each call site implements this over its concrete type
/// ([`CellData`](super::merge::CellData) on the merge path, `MergedOp` on the
/// writer path) and how it RECOGNIZES a tombstone — a `Value::Tombstone`
/// payload vs. a `CellOperation::Delete` op — stays with the type, since that
/// recognition is genuinely type-specific.
///
/// The on-disk `localDeletionTime` is intentionally NOT part of this view: it
/// is consulted only by the merge path's gc-grace purge stage (which the flush
/// path has no analogue for), so sharing it here would force a meaningless
/// accessor on the writer type. The tie-break itself never consults LDT — a
/// same-timestamp tombstone wins BEFORE any LDT compare.
pub
/// Cassandra `Cells#reconcile` replace decision (parity commit `a62c749`):
/// returns `true` when `candidate` should replace the current `existing` winner.
///
/// Decided IN THIS ORDER, short-circuiting:
/// 1. **timestamp** — a strictly higher write timestamp always wins.
/// 2. **deletion vs live/expiring at EQUAL timestamp** — a cell DELETION
/// (tombstone) beats a LIVE or EXPIRING (TTL) cell, decided BEFORE any
/// `localDeletionTime` compare, so an expiring cell can never resurrect data
/// over a same-timestamp tombstone (issues #848 / #498). An expiring cell is
/// treated as LIVE (it carries a real value + a TTL, not a tombstone), so
/// this one rule subsumes both tombstone-beats-live and
/// tombstone-beats-expiring.
/// 3. **equal timestamp + equal liveness** — returns `false`. Cassandra's
/// reconcile is order-independent and equivalent here, so the caller keeps
/// its first-seen winner. (The writer path overlays an order-dependent
/// last-write-wins tie-break for this single case at its call site; that
/// overlay is writer-only and NOT part of this shared rule.)
pub Sized>
/// Strict-supersede predicate for complex (collection / UDT) deletion markers
/// (parity commit `bd244649`): a candidate marker supersedes the active one for
/// the SAME column ONLY when its `markedForDeleteAt` is STRICTLY GREATER. Equal
/// (or lesser) timestamps do NOT supersede.
///
/// Both call sites reduce their carried markers to one active deletion per
/// column NAME using this predicate; the per-column iteration differs but the
/// strictly-greater comparison is shared here.
pub
/// Shadow-before-purge boundary (parity commit `f66fa14f`; the element-vs-marker
/// `<=` rule, #498): a complex ELEMENT survives the active complex deletion on
/// its column only when the element's own timestamp is STRICTLY GREATER than the
/// marker's `markedForDeleteAt`. An element with `ts <= mfda` is shadowed
/// (covered) and dropped before the marker can be purged.
///
/// Returns `true` when the element SURVIVES.
pub