reifydb_store_multi/store/
mod.rs1use std::{ops::Deref, sync::Arc};
5
6use reifydb_core::event::EventBus;
7use reifydb_runtime::{
8 actor::{mailbox::ActorRef, system::ActorSystem},
9 context::clock::Clock,
10 pool::{PoolConfig, Pools},
11};
12use tracing::instrument;
13
14use crate::{HotConfig, cold::ColdStorage, config::MultiStoreConfig, hot::storage::HotStorage, warm::WarmStorage};
15
16pub mod drop;
17pub mod multi;
18pub mod router;
19pub mod version;
20pub mod worker;
21
22use reifydb_core::actors::drop::DropMessage;
23use worker::{DropActor, DropWorkerConfig};
24
25use crate::Result;
26
27#[derive(Clone)]
28pub struct StandardMultiStore(Arc<StandardMultiStoreInner>);
29
30pub struct StandardMultiStoreInner {
31 pub(crate) hot: Option<HotStorage>,
32 pub(crate) warm: Option<WarmStorage>,
33 pub(crate) cold: Option<ColdStorage>,
34 pub(crate) drop_actor: ActorRef<DropMessage>,
36 _actor_system: ActorSystem,
38 pub(crate) event_bus: EventBus,
40}
41
42impl StandardMultiStore {
43 #[instrument(name = "store::multi::new", level = "debug", skip(config), fields(
44 has_hot = config.hot.is_some(),
45 has_warm = config.warm.is_some(),
46 has_cold = config.cold.is_some(),
47 ))]
48 pub fn new(config: MultiStoreConfig) -> Result<Self> {
49 let hot = config.hot.map(|c| c.storage);
50 let warm = None;
52 let cold = None;
53 let _ = config.warm;
54 let _ = config.cold;
55
56 let actor_system = config.actor_system.clone();
58
59 let storage = hot.as_ref().expect("hot tier is required");
61 let drop_config = DropWorkerConfig::default();
62 let drop_actor = DropActor::spawn(
63 &actor_system,
64 drop_config,
65 storage.clone(),
66 config.event_bus.clone(),
67 config.clock,
68 );
69
70 Ok(Self(Arc::new(StandardMultiStoreInner {
71 hot,
72 warm,
73 cold,
74 drop_actor,
75 _actor_system: actor_system,
76 event_bus: config.event_bus,
77 })))
78 }
79
80 pub fn hot(&self) -> Option<&HotStorage> {
84 self.hot.as_ref()
85 }
86}
87
88impl Deref for StandardMultiStore {
89 type Target = StandardMultiStoreInner;
90
91 fn deref(&self) -> &Self::Target {
92 &self.0
93 }
94}
95
96impl StandardMultiStore {
97 pub fn testing_memory() -> Self {
98 let pools = Pools::new(PoolConfig::default());
99 let actor_system = ActorSystem::new(pools, Clock::Real);
100 Self::testing_memory_with_eventbus(EventBus::new(&actor_system))
101 }
102
103 pub fn testing_memory_with_eventbus(event_bus: EventBus) -> Self {
104 let pools = Pools::new(PoolConfig::default());
105 let actor_system = ActorSystem::new(pools, Clock::Real);
106 Self::new(MultiStoreConfig {
107 hot: Some(HotConfig {
108 storage: HotStorage::memory(),
109 }),
110 warm: None,
111 cold: None,
112 retention: Default::default(),
113 merge_config: Default::default(),
114 event_bus,
115 actor_system,
116 clock: Clock::Real,
117 })
118 .unwrap()
119 }
120}