reifydb_core/key/operator/keyspace/
expiry.rs1use reifydb_value::util::hash::Hash128;
5
6use crate::{
7 key::{
8 operator::{
9 state::{GroupId, KeyspaceId},
10 traits::Keyspace,
11 },
12 typed::{
13 BoundedKey, DenseKey, KeyLayout,
14 direction::{Desc, 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 ExpiryKey {
23 pub threshold: Desc<u64>,
24 pub owner: Desc<Hash128>,
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
28pub struct TumblingExpiryKey {
29 pub group: Desc<GroupId>,
30 pub threshold: Desc<u64>,
31 pub owner: Desc<Hash128>,
32 pub window_start: Desc<u64>,
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
36pub struct TumblingExpirySuffix {
37 pub threshold: Desc<u64>,
38 pub owner: Desc<Hash128>,
39 pub window_start: Desc<u64>,
40}
41
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, KeyLayout, HeapSize)]
43pub struct ReapQueueKey {
44 pub group: Desc<GroupId>,
45}
46
47#[derive(Clone, Copy, Debug, PartialEq, Eq)]
48pub struct Expiry;
49
50impl Keyspace for Expiry {
51 const ID: KeyspaceId = KeyspaceId::ROLLING_EXPIRY;
52 const NAME: &'static str = "ROLLING_EXPIRY";
53 const RANGE_CACHED: bool = true;
54
55 type GroupedKey = ExpiryKey;
56 type Suffix = ExpiryKey;
57
58 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
59 (GroupId::ROOT, *key)
60 }
61
62 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
63 suffix
64 }
65}
66
67#[derive(Clone, Copy, Debug, PartialEq, Eq)]
68pub struct TumblingExpiry;
69
70impl Keyspace for TumblingExpiry {
71 const ID: KeyspaceId = KeyspaceId::TUMBLING_EXPIRY;
72 const NAME: &'static str = "TUMBLING_EXPIRY";
73 const RANGE_CACHED: bool = true;
74
75 type GroupedKey = TumblingExpiryKey;
76 type Suffix = TumblingExpirySuffix;
77
78 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
79 (
80 key.group.0,
81 TumblingExpirySuffix {
82 threshold: key.threshold,
83 owner: key.owner,
84 window_start: key.window_start,
85 },
86 )
87 }
88
89 fn join(group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
90 TumblingExpiryKey {
91 group: Desc(group),
92 threshold: suffix.threshold,
93 owner: suffix.owner,
94 window_start: suffix.window_start,
95 }
96 }
97}
98
99#[derive(Clone, Copy, Debug, PartialEq, Eq)]
100pub struct ReapQueue;
101
102impl Keyspace for ReapQueue {
103 const ID: KeyspaceId = KeyspaceId::REAP_QUEUE;
104 const NAME: &'static str = "REAP_QUEUE";
105 const RANGE_CACHED: bool = true;
106
107 type GroupedKey = ReapQueueKey;
108 type Suffix = ReapQueueKey;
109
110 fn split(key: &Self::GroupedKey) -> (GroupId, Self::Suffix) {
111 (GroupId::ROOT, *key)
112 }
113
114 fn join(_group: GroupId, suffix: Self::Suffix) -> Self::GroupedKey {
115 suffix
116 }
117}