1use reifydb_value::value::{partition::Partition, row_number::RowNumber};
5
6use crate::{
7 key::{
8 operator::{
9 state::{GroupId, KeyspaceId},
10 traits::Keyspace,
11 },
12 typed::{
13 BoundedKey, DenseKey, KeyLayout,
14 direction::{Asc, Direction, KeyField},
15 layout::{KeyColumn, KeyColumnType, KeyLayout, KeyValue, KeyValues},
16 },
17 },
18 metrics::heap::HeapSize,
19};
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
22pub struct RingbufferForwardKey {
23 pub row: Asc<RowNumber>,
24}
25
26#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
27pub struct RingbufferEntryKey {
28 pub row: Asc<RowNumber>,
29}
30
31#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
32pub struct RingbufferExpiryKey {
33 pub expires_at: Asc<i64>,
34 pub row: Asc<RowNumber>,
35}
36
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
38pub struct RingbufferTtlArmKey {}
39
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
41pub struct RingbufferMetaKey {}
42
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
44pub struct RingbufferNextRowKey {}
45
46#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
47pub struct PartitionedRingbufferEntryKey {
48 pub partition: Asc<Partition>,
49 pub row: Asc<RowNumber>,
50}
51
52#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
53pub struct PartitionedRingbufferExpiryKey {
54 pub partition: Asc<Partition>,
55 pub expires_at: Asc<i64>,
56 pub row: Asc<RowNumber>,
57}
58
59#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
60pub struct PartitionedRingbufferTtlArmKey {
61 pub partition: Asc<Partition>,
62}
63
64#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
65pub struct PartitionedRingbufferMetaKey {
66 pub partition: Asc<Partition>,
67}
68
69#[derive(Clone, Copy, Debug, PartialEq, Eq)]
70pub struct RingbufferForward;
71
72impl Keyspace for RingbufferForward {
73 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_FORWARD;
74 const NAME: &'static str = "RINGBUFFER_FORWARD";
75 const RANGE_CACHED: bool = true;
76
77 type GroupedKey = RingbufferForwardKey;
78 type Suffix = RingbufferForwardKey;
79
80 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
81 (GroupId::ROOT, *key)
82 }
83
84 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
85 suffix
86 }
87}
88
89#[derive(Clone, Copy, Debug, PartialEq, Eq)]
90pub struct RingbufferEntry;
91
92impl Keyspace for RingbufferEntry {
93 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_ENTRY;
94 const NAME: &'static str = "RINGBUFFER_ENTRY";
95 const RANGE_CACHED: bool = true;
96
97 type GroupedKey = RingbufferEntryKey;
98 type Suffix = RingbufferEntryKey;
99
100 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
101 (GroupId::ROOT, *key)
102 }
103
104 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
105 suffix
106 }
107}
108
109#[derive(Clone, Copy, Debug, PartialEq, Eq)]
110pub struct RingbufferExpiry;
111
112impl Keyspace for RingbufferExpiry {
113 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_EXPIRY;
114 const NAME: &'static str = "RINGBUFFER_EXPIRY";
115 const RANGE_CACHED: bool = true;
116
117 type GroupedKey = RingbufferExpiryKey;
118 type Suffix = RingbufferExpiryKey;
119
120 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
121 (GroupId::ROOT, *key)
122 }
123
124 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
125 suffix
126 }
127}
128
129#[derive(Clone, Copy, Debug, PartialEq, Eq)]
130pub struct RingbufferTtlArm;
131
132impl Keyspace for RingbufferTtlArm {
133 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_TTL_ARM;
134 const NAME: &'static str = "RINGBUFFER_TTL_ARM";
135 const RANGE_CACHED: bool = true;
136
137 type GroupedKey = RingbufferTtlArmKey;
138 type Suffix = RingbufferTtlArmKey;
139
140 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
141 (GroupId::ROOT, *key)
142 }
143
144 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
145 suffix
146 }
147}
148
149#[derive(Clone, Copy, Debug, PartialEq, Eq)]
150pub struct RingbufferNextRow;
151
152impl Keyspace for RingbufferNextRow {
153 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_NEXT_ROW;
154 const NAME: &'static str = "RINGBUFFER_NEXT_ROW";
155 const RANGE_CACHED: bool = true;
156
157 type GroupedKey = RingbufferNextRowKey;
158 type Suffix = RingbufferNextRowKey;
159
160 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
161 (GroupId::ROOT, *key)
162 }
163
164 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
165 suffix
166 }
167}
168
169#[derive(Clone, Copy, Debug, PartialEq, Eq)]
170pub struct RingbufferMeta;
171
172impl Keyspace for RingbufferMeta {
173 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_META;
174 const NAME: &'static str = "RINGBUFFER_META";
175 const RANGE_CACHED: bool = true;
176
177 type GroupedKey = RingbufferMetaKey;
178 type Suffix = RingbufferMetaKey;
179
180 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
181 (GroupId::ROOT, *key)
182 }
183
184 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
185 suffix
186 }
187}
188
189#[derive(Clone, Copy, Debug, PartialEq, Eq)]
190pub struct PartitionedRingbufferEntry;
191
192impl Keyspace for PartitionedRingbufferEntry {
193 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_ENTRY;
194 const NAME: &'static str = "PARTITIONED_RINGBUFFER_ENTRY";
195 const RANGE_CACHED: bool = true;
196
197 type GroupedKey = PartitionedRingbufferEntryKey;
198 type Suffix = PartitionedRingbufferEntryKey;
199
200 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
201 (GroupId::ROOT, *key)
202 }
203
204 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
205 suffix
206 }
207}
208
209#[derive(Clone, Copy, Debug, PartialEq, Eq)]
210pub struct PartitionedRingbufferExpiry;
211
212impl Keyspace for PartitionedRingbufferExpiry {
213 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_EXPIRY;
214 const NAME: &'static str = "PARTITIONED_RINGBUFFER_EXPIRY";
215 const RANGE_CACHED: bool = true;
216
217 type GroupedKey = PartitionedRingbufferExpiryKey;
218 type Suffix = PartitionedRingbufferExpiryKey;
219
220 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
221 (GroupId::ROOT, *key)
222 }
223
224 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
225 suffix
226 }
227}
228
229#[derive(Clone, Copy, Debug, PartialEq, Eq)]
230pub struct PartitionedRingbufferTtlArm;
231
232impl Keyspace for PartitionedRingbufferTtlArm {
233 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_TTL_ARM;
234 const NAME: &'static str = "PARTITIONED_RINGBUFFER_TTL_ARM";
235 const RANGE_CACHED: bool = true;
236
237 type GroupedKey = PartitionedRingbufferTtlArmKey;
238 type Suffix = PartitionedRingbufferTtlArmKey;
239
240 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
241 (GroupId::ROOT, *key)
242 }
243
244 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
245 suffix
246 }
247}
248
249#[derive(Clone, Copy, Debug, PartialEq, Eq)]
250pub struct PartitionedRingbufferMeta;
251
252impl Keyspace for PartitionedRingbufferMeta {
253 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_META;
254 const NAME: &'static str = "PARTITIONED_RINGBUFFER_META";
255 const RANGE_CACHED: bool = true;
256
257 type GroupedKey = PartitionedRingbufferMetaKey;
258 type Suffix = PartitionedRingbufferMetaKey;
259
260 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
261 (GroupId::ROOT, *key)
262 }
263
264 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
265 suffix
266 }
267}