reifydb_core/key/operator/keyspace/
ringbuffer.rs1use 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<u64>,
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 PartitionedRingbufferEntryKey {
45 pub partition: Asc<Partition>,
46 pub row: Asc<RowNumber>,
47}
48
49#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
50pub struct PartitionedRingbufferExpiryKey {
51 pub partition: Asc<Partition>,
52 pub expires_at: Asc<u64>,
53 pub row: Asc<RowNumber>,
54}
55
56#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
57pub struct PartitionedRingbufferTtlArmKey {
58 pub partition: Asc<Partition>,
59}
60
61#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
62pub struct PartitionedRingbufferMetaKey {
63 pub partition: Asc<Partition>,
64}
65
66#[derive(Clone, Copy, Debug, PartialEq, Eq)]
67pub struct RingbufferForward;
68
69impl Keyspace for RingbufferForward {
70 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_FORWARD;
71 const NAME: &'static str = "RINGBUFFER_FORWARD";
72 const RANGE_CACHED: bool = true;
73
74 type GroupedKey = RingbufferForwardKey;
75 type Suffix = RingbufferForwardKey;
76
77 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
78 (GroupId::ROOT, *key)
79 }
80
81 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
82 suffix
83 }
84}
85
86#[derive(Clone, Copy, Debug, PartialEq, Eq)]
87pub struct RingbufferEntry;
88
89impl Keyspace for RingbufferEntry {
90 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_ENTRY;
91 const NAME: &'static str = "RINGBUFFER_ENTRY";
92 const RANGE_CACHED: bool = true;
93
94 type GroupedKey = RingbufferEntryKey;
95 type Suffix = RingbufferEntryKey;
96
97 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
98 (GroupId::ROOT, *key)
99 }
100
101 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
102 suffix
103 }
104}
105
106#[derive(Clone, Copy, Debug, PartialEq, Eq)]
107pub struct RingbufferExpiry;
108
109impl Keyspace for RingbufferExpiry {
110 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_EXPIRY;
111 const NAME: &'static str = "RINGBUFFER_EXPIRY";
112 const RANGE_CACHED: bool = true;
113
114 type GroupedKey = RingbufferExpiryKey;
115 type Suffix = RingbufferExpiryKey;
116
117 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
118 (GroupId::ROOT, *key)
119 }
120
121 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
122 suffix
123 }
124}
125
126#[derive(Clone, Copy, Debug, PartialEq, Eq)]
127pub struct RingbufferTtlArm;
128
129impl Keyspace for RingbufferTtlArm {
130 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_TTL_ARM;
131 const NAME: &'static str = "RINGBUFFER_TTL_ARM";
132 const RANGE_CACHED: bool = true;
133
134 type GroupedKey = RingbufferTtlArmKey;
135 type Suffix = RingbufferTtlArmKey;
136
137 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
138 (GroupId::ROOT, *key)
139 }
140
141 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
142 suffix
143 }
144}
145
146#[derive(Clone, Copy, Debug, PartialEq, Eq)]
147pub struct RingbufferMeta;
148
149impl Keyspace for RingbufferMeta {
150 const ID: KeyspaceId = KeyspaceId::RINGBUFFER_META;
151 const NAME: &'static str = "RINGBUFFER_META";
152 const RANGE_CACHED: bool = true;
153
154 type GroupedKey = RingbufferMetaKey;
155 type Suffix = RingbufferMetaKey;
156
157 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
158 (GroupId::ROOT, *key)
159 }
160
161 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
162 suffix
163 }
164}
165
166#[derive(Clone, Copy, Debug, PartialEq, Eq)]
167pub struct PartitionedRingbufferEntry;
168
169impl Keyspace for PartitionedRingbufferEntry {
170 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_ENTRY;
171 const NAME: &'static str = "PARTITIONED_RINGBUFFER_ENTRY";
172 const RANGE_CACHED: bool = true;
173
174 type GroupedKey = PartitionedRingbufferEntryKey;
175 type Suffix = PartitionedRingbufferEntryKey;
176
177 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
178 (GroupId::ROOT, *key)
179 }
180
181 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
182 suffix
183 }
184}
185
186#[derive(Clone, Copy, Debug, PartialEq, Eq)]
187pub struct PartitionedRingbufferExpiry;
188
189impl Keyspace for PartitionedRingbufferExpiry {
190 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_EXPIRY;
191 const NAME: &'static str = "PARTITIONED_RINGBUFFER_EXPIRY";
192 const RANGE_CACHED: bool = true;
193
194 type GroupedKey = PartitionedRingbufferExpiryKey;
195 type Suffix = PartitionedRingbufferExpiryKey;
196
197 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
198 (GroupId::ROOT, *key)
199 }
200
201 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
202 suffix
203 }
204}
205
206#[derive(Clone, Copy, Debug, PartialEq, Eq)]
207pub struct PartitionedRingbufferTtlArm;
208
209impl Keyspace for PartitionedRingbufferTtlArm {
210 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_TTL_ARM;
211 const NAME: &'static str = "PARTITIONED_RINGBUFFER_TTL_ARM";
212 const RANGE_CACHED: bool = true;
213
214 type GroupedKey = PartitionedRingbufferTtlArmKey;
215 type Suffix = PartitionedRingbufferTtlArmKey;
216
217 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
218 (GroupId::ROOT, *key)
219 }
220
221 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
222 suffix
223 }
224}
225
226#[derive(Clone, Copy, Debug, PartialEq, Eq)]
227pub struct PartitionedRingbufferMeta;
228
229impl Keyspace for PartitionedRingbufferMeta {
230 const ID: KeyspaceId = KeyspaceId::PARTITIONED_RINGBUFFER_META;
231 const NAME: &'static str = "PARTITIONED_RINGBUFFER_META";
232 const RANGE_CACHED: bool = true;
233
234 type GroupedKey = PartitionedRingbufferMetaKey;
235 type Suffix = PartitionedRingbufferMetaKey;
236
237 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
238 (GroupId::ROOT, *key)
239 }
240
241 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
242 suffix
243 }
244}