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