Skip to main content

reifydb_store_multi/tier/commit/memory/
entry.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use std::{cmp::Reverse, collections::BTreeMap, sync::Arc};
5
6use reifydb_codec::key::encoded::EncodedKey;
7use reifydb_core::{common::CommitVersion, interface::store::EntryKind};
8use reifydb_runtime::sync::{
9	map::Map,
10	rwlock::{RwLock, RwLockWriteGuard},
11};
12use reifydb_value::util::cowvec::CowVec;
13use tracing::instrument;
14
15pub(super) type Value = Option<CowVec<u8>>;
16
17pub(super) type CurrentMap = BTreeMap<EncodedKey, (CommitVersion, Value)>;
18
19pub(super) type HistoricalMap = BTreeMap<EncodedKey, BTreeMap<Reverse<CommitVersion>, Value>>;
20
21pub(super) struct Entry {
22	pub current: Arc<RwLock<CurrentMap>>,
23
24	pub historical: Arc<RwLock<HistoricalMap>>,
25}
26
27impl Entry {
28	pub fn new() -> Self {
29		Self {
30			current: Arc::new(RwLock::new(BTreeMap::new())),
31			historical: Arc::new(RwLock::new(BTreeMap::new())),
32		}
33	}
34
35	#[instrument(name = "store::multi::memory::write_acquire", level = "debug", skip_all)]
36	pub fn write_pair(&self) -> (RwLockWriteGuard<'_, CurrentMap>, RwLockWriteGuard<'_, HistoricalMap>) {
37		(self.current.write(), self.historical.write())
38	}
39}
40
41impl Clone for Entry {
42	fn clone(&self) -> Self {
43		Self {
44			current: Arc::clone(&self.current),
45			historical: Arc::clone(&self.historical),
46		}
47	}
48}
49
50pub(super) struct Entries {
51	pub(super) data: Map<EntryKind, Entry>,
52}
53
54impl Default for Entries {
55	fn default() -> Self {
56		Self {
57			data: Map::new(),
58		}
59	}
60}