Skip to main content

reifydb_store_multi/tier/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4pub mod persistent;
5pub mod point;
6pub mod range;
7
8use std::ops::Bound;
9
10use reifydb_core::{common::CommitVersion, interface::store::EntryKind};
11use reifydb_store_commit::{
12	MultiVersionScope, RangeBatch, RangeCursor, TierBatch, VersionedGetResult, store::CommitStore,
13};
14use reifydb_value::Result;
15
16pub trait TierStorage: Send + Sync + Clone + 'static {
17	fn get(&self, table: EntryKind, key: &[u8], version: CommitVersion) -> Result<VersionedGetResult>;
18
19	fn get_many(
20		&self,
21		table: EntryKind,
22		keys: &[&[u8]],
23		version: CommitVersion,
24	) -> Result<Vec<VersionedGetResult>> {
25		let mut out = Vec::with_capacity(keys.len());
26		for &key in keys {
27			out.push(self.get(table, key, version)?);
28		}
29		Ok(out)
30	}
31
32	fn contains(&self, table: EntryKind, key: &[u8], version: CommitVersion) -> Result<bool> {
33		Ok(matches!(self.get(table, key, version)?, VersionedGetResult::Value { .. }))
34	}
35
36	fn set(&self, version: CommitVersion, batches: TierBatch) -> Result<()>;
37
38	fn range_next(
39		&self,
40		table: EntryKind,
41		cursor: &mut RangeCursor,
42		start: Bound<&[u8]>,
43		end: Bound<&[u8]>,
44		scope: MultiVersionScope,
45		batch_size: usize,
46	) -> Result<RangeBatch>;
47
48	fn range_rev_next(
49		&self,
50		table: EntryKind,
51		cursor: &mut RangeCursor,
52		start: Bound<&[u8]>,
53		end: Bound<&[u8]>,
54		scope: MultiVersionScope,
55		batch_size: usize,
56	) -> Result<RangeBatch>;
57
58	fn ensure_table(&self, table: EntryKind) -> Result<()>;
59
60	fn clear_table(&self, table: EntryKind) -> Result<()>;
61}
62
63impl TierStorage for CommitStore {
64	fn get(&self, table: EntryKind, key: &[u8], version: CommitVersion) -> Result<VersionedGetResult> {
65		CommitStore::get(self, table, key, version)
66	}
67
68	fn contains(&self, table: EntryKind, key: &[u8], version: CommitVersion) -> Result<bool> {
69		CommitStore::contains(self, table, key, version)
70	}
71
72	fn set(&self, version: CommitVersion, batches: TierBatch) -> Result<()> {
73		CommitStore::set(self, version, batches)
74	}
75
76	fn range_next(
77		&self,
78		table: EntryKind,
79		cursor: &mut RangeCursor,
80		start: Bound<&[u8]>,
81		end: Bound<&[u8]>,
82		scope: MultiVersionScope,
83		batch_size: usize,
84	) -> Result<RangeBatch> {
85		CommitStore::range_next(self, table, cursor, start, end, scope, batch_size)
86	}
87
88	fn range_rev_next(
89		&self,
90		table: EntryKind,
91		cursor: &mut RangeCursor,
92		start: Bound<&[u8]>,
93		end: Bound<&[u8]>,
94		scope: MultiVersionScope,
95		batch_size: usize,
96	) -> Result<RangeBatch> {
97		CommitStore::range_rev_next(self, table, cursor, start, end, scope, batch_size)
98	}
99
100	fn ensure_table(&self, table: EntryKind) -> Result<()> {
101		CommitStore::ensure_table(self, table)
102	}
103
104	fn clear_table(&self, table: EntryKind) -> Result<()> {
105		CommitStore::clear_table(self, table)
106	}
107}