Skip to main content

reifydb_store_multi/
config.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use reifydb_core::event::EventBus;
5use reifydb_runtime::{actor::system::ActorSpawner, context::clock::Clock};
6#[cfg(all(feature = "sqlite", not(target_arch = "wasm32")))]
7use reifydb_sqlite::{SqliteConfig, SqliteTempPathGuard};
8use reifydb_store_commit::store::CommitStore;
9use reifydb_value::value::duration::Duration;
10
11use crate::tier::{persistent::MultiPersistentTier, point::MultiPointConfig, range::MultiRangeConfig};
12
13#[derive(Clone)]
14pub struct MultiStoreConfig {
15	pub commit: CommitStoreConfig,
16	pub persistent: Option<PersistentConfig>,
17	pub point: Option<MultiPointConfig>,
18	pub range: Option<MultiRangeConfig>,
19	pub retention: RetentionConfig,
20	pub merge_config: MergeConfig,
21	pub event_bus: EventBus,
22	pub spawner: ActorSpawner,
23	pub clock: Clock,
24}
25
26impl MultiStoreConfig {
27	pub fn memory(spawner: ActorSpawner, clock: Clock, event_bus: EventBus) -> Self {
28		Self {
29			commit: CommitStoreConfig {
30				storage: CommitStore::new(),
31			},
32			persistent: None,
33			point: None,
34			range: None,
35			retention: Default::default(),
36			merge_config: Default::default(),
37			event_bus,
38			spawner,
39			clock,
40		}
41	}
42
43	#[cfg(all(feature = "sqlite", not(target_arch = "wasm32")))]
44	pub fn sqlite(persistent: PersistentConfig, spawner: ActorSpawner, clock: Clock, event_bus: EventBus) -> Self {
45		Self {
46			commit: CommitStoreConfig {
47				storage: CommitStore::new(),
48			},
49			persistent: Some(persistent),
50			point: None,
51			range: None,
52			retention: Default::default(),
53			merge_config: Default::default(),
54			event_bus,
55			spawner,
56			clock,
57		}
58	}
59}
60
61#[derive(Clone)]
62pub struct CommitStoreConfig {
63	pub storage: CommitStore,
64}
65
66#[derive(Clone)]
67pub struct PersistentConfig {
68	pub storage: MultiPersistentTier,
69}
70
71impl PersistentConfig {
72	pub fn opened(storage: MultiPersistentTier) -> Self {
73		Self {
74			storage,
75		}
76	}
77
78	#[cfg(all(feature = "sqlite", not(target_arch = "wasm32")))]
79	pub fn sqlite(sqlite_config: SqliteConfig) -> Self {
80		Self::opened(MultiPersistentTier::sqlite(sqlite_config))
81	}
82
83	#[cfg(all(feature = "sqlite", not(target_arch = "wasm32")))]
84	pub fn sqlite_in_memory() -> (Self, SqliteTempPathGuard) {
85		let (storage, guard) = MultiPersistentTier::sqlite_in_memory();
86		(Self::opened(storage), guard)
87	}
88}
89
90#[derive(Clone, Debug)]
91pub struct RetentionConfig {
92	pub buffer: Duration,
93	pub persistent: Duration,
94}
95
96#[derive(Clone, Debug)]
97pub struct MergeConfig {
98	pub merge_threshold_rows: usize,
99	pub merge_batch_size: usize,
100	pub enable_auto_eviction: bool,
101}
102
103impl Default for RetentionConfig {
104	fn default() -> Self {
105		Self {
106			buffer: Duration::from_seconds(300).unwrap(),
107			persistent: Duration::from_seconds(3600).unwrap(),
108		}
109	}
110}
111
112impl Default for MergeConfig {
113	fn default() -> Self {
114		Self {
115			merge_threshold_rows: 100_000,
116			merge_batch_size: 10_000,
117			enable_auto_eviction: true,
118		}
119	}
120}