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