reifydb_store_transaction/
lib.rs1#![cfg_attr(not(debug_assertions), deny(warnings))]
5
6use reifydb_core::interface::version::{ComponentType, HasVersion, SystemVersion};
7pub use reifydb_type::Result;
8
9pub mod backend;
10pub(crate) mod cdc;
11pub mod config;
12mod multi;
13mod single;
15pub mod stats;
16mod store;
17
18use std::collections::Bound;
19
20use async_trait::async_trait;
21pub use cdc::{CdcBatch, CdcCount, CdcGet, CdcRange, CdcStore};
22pub use config::{BackendConfig, MergeConfig, RetentionConfig, StorageStatsConfig, TransactionStoreConfig};
23pub use multi::*;
24use reifydb_core::{
25 CommitVersion, CowVec, EncodedKey, EncodedKeyRange,
26 delta::Delta,
27 interface::{Cdc, MultiVersionValues, SingleVersionValues},
28};
29pub use single::*;
30pub use stats::{ObjectId, StorageStats, StorageTracker, Tier, TierStats};
31pub use store::StandardTransactionStore;
32
33pub mod memory {
34 pub use crate::backend::memory::MemoryPrimitiveStorage;
35}
36pub mod sqlite {
37 pub use crate::backend::sqlite::{SqliteConfig, SqlitePrimitiveStorage};
38}
39
40pub struct TransactionStoreVersion;
41
42impl HasVersion for TransactionStoreVersion {
43 fn version(&self) -> SystemVersion {
44 SystemVersion {
45 name: "store-transaction".to_string(),
46 version: env!("CARGO_PKG_VERSION").to_string(),
47 description: "Transaction storage for OLTP operations and recent data".to_string(),
48 r#type: ComponentType::Module,
49 }
50 }
51}
52
53#[repr(u8)]
54#[derive(Clone)]
55pub enum TransactionStore {
56 Standard(StandardTransactionStore) = 0,
57 }
59
60impl TransactionStore {
61 pub fn standard(config: TransactionStoreConfig) -> Self {
62 Self::Standard(StandardTransactionStore::new(config).unwrap())
63 }
64}
65
66impl TransactionStore {
67 pub async fn testing_memory() -> Self {
68 TransactionStore::Standard(StandardTransactionStore::testing_memory().await)
69 }
70
71 pub fn stats_tracker(&self) -> &StorageTracker {
73 match self {
74 TransactionStore::Standard(store) => store.stats_tracker(),
75 }
76 }
77}
78
79#[async_trait]
81impl MultiVersionGet for TransactionStore {
82 #[inline]
83 async fn get(&self, key: &EncodedKey, version: CommitVersion) -> Result<Option<MultiVersionValues>> {
84 match self {
85 TransactionStore::Standard(store) => MultiVersionGet::get(store, key, version).await,
86 }
87 }
88}
89
90#[async_trait]
91impl MultiVersionContains for TransactionStore {
92 #[inline]
93 async fn contains(&self, key: &EncodedKey, version: CommitVersion) -> Result<bool> {
94 match self {
95 TransactionStore::Standard(store) => MultiVersionContains::contains(store, key, version).await,
96 }
97 }
98}
99
100#[async_trait]
101impl MultiVersionCommit for TransactionStore {
102 #[inline]
103 async fn commit(&self, deltas: CowVec<Delta>, version: CommitVersion) -> Result<()> {
104 match self {
105 TransactionStore::Standard(store) => store.commit(deltas, version).await,
106 }
107 }
108}
109
110#[async_trait]
111impl MultiVersionRange for TransactionStore {
112 #[inline]
113 async fn range_batch(
114 &self,
115 range: EncodedKeyRange,
116 version: CommitVersion,
117 batch_size: u64,
118 ) -> Result<MultiVersionBatch> {
119 match self {
120 TransactionStore::Standard(store) => {
121 MultiVersionRange::range_batch(store, range, version, batch_size).await
122 }
123 }
124 }
125}
126
127#[async_trait]
128impl MultiVersionRangeRev for TransactionStore {
129 #[inline]
130 async fn range_rev_batch(
131 &self,
132 range: EncodedKeyRange,
133 version: CommitVersion,
134 batch_size: u64,
135 ) -> Result<MultiVersionBatch> {
136 match self {
137 TransactionStore::Standard(store) => {
138 MultiVersionRangeRev::range_rev_batch(store, range, version, batch_size).await
139 }
140 }
141 }
142}
143
144#[async_trait]
146impl SingleVersionGet for TransactionStore {
147 #[inline]
148 async fn get(&self, key: &EncodedKey) -> Result<Option<SingleVersionValues>> {
149 match self {
150 TransactionStore::Standard(store) => SingleVersionGet::get(store, key).await,
151 }
152 }
153}
154
155#[async_trait]
156impl SingleVersionContains for TransactionStore {
157 #[inline]
158 async fn contains(&self, key: &EncodedKey) -> Result<bool> {
159 match self {
160 TransactionStore::Standard(store) => SingleVersionContains::contains(store, key).await,
161 }
162 }
163}
164
165impl SingleVersionSet for TransactionStore {}
166
167impl SingleVersionRemove for TransactionStore {}
168
169#[async_trait]
170impl SingleVersionCommit for TransactionStore {
171 #[inline]
172 async fn commit(&mut self, deltas: CowVec<Delta>) -> Result<()> {
173 match self {
174 TransactionStore::Standard(store) => SingleVersionCommit::commit(store, deltas).await,
175 }
176 }
177}
178
179#[async_trait]
180impl SingleVersionRange for TransactionStore {
181 #[inline]
182 async fn range_batch(&self, range: EncodedKeyRange, batch_size: u64) -> Result<SingleVersionBatch> {
183 match self {
184 TransactionStore::Standard(store) => {
185 SingleVersionRange::range_batch(store, range, batch_size).await
186 }
187 }
188 }
189}
190
191#[async_trait]
192impl SingleVersionRangeRev for TransactionStore {
193 #[inline]
194 async fn range_rev_batch(&self, range: EncodedKeyRange, batch_size: u64) -> Result<SingleVersionBatch> {
195 match self {
196 TransactionStore::Standard(store) => {
197 SingleVersionRangeRev::range_rev_batch(store, range, batch_size).await
198 }
199 }
200 }
201}
202
203#[async_trait]
205impl CdcGet for TransactionStore {
206 #[inline]
207 async fn get(&self, version: CommitVersion) -> Result<Option<Cdc>> {
208 match self {
209 TransactionStore::Standard(store) => CdcGet::get(store, version).await,
210 }
211 }
212}
213
214#[async_trait]
215impl CdcRange for TransactionStore {
216 #[inline]
217 async fn range_batch(
218 &self,
219 start: Bound<CommitVersion>,
220 end: Bound<CommitVersion>,
221 batch_size: u64,
222 ) -> Result<CdcBatch> {
223 match self {
224 TransactionStore::Standard(store) => CdcRange::range_batch(store, start, end, batch_size).await,
225 }
226 }
227}
228
229#[async_trait]
230impl CdcCount for TransactionStore {
231 #[inline]
232 async fn count(&self, version: CommitVersion) -> Result<usize> {
233 match self {
234 TransactionStore::Standard(store) => CdcCount::count(store, version).await,
235 }
236 }
237}
238
239impl MultiVersionStore for TransactionStore {}
241impl SingleVersionStore for TransactionStore {}
242impl CdcStore for TransactionStore {}