Skip to main content

reifydb_store_multi/store/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use std::{ops::Deref, sync::Arc};
5
6use reifydb_core::event::EventBus;
7use reifydb_runtime::{
8	SharedRuntimeConfig,
9	actor::{mailbox::ActorRef, system::ActorSystem},
10	clock::Clock,
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 worker::{DropActor, DropMessage, DropWorkerConfig};
23
24#[derive(Clone)]
25pub struct StandardMultiStore(Arc<StandardMultiStoreInner>);
26
27pub struct StandardMultiStoreInner {
28	pub(crate) hot: Option<HotStorage>,
29	pub(crate) warm: Option<WarmStorage>,
30	pub(crate) cold: Option<ColdStorage>,
31	/// Reference to the drop actor for sending drop requests.
32	pub(crate) drop_actor: ActorRef<DropMessage>,
33	/// Actor system that owns the drop actor.
34	_actor_system: ActorSystem,
35	/// Event bus for emitting storage statistics events.
36	pub(crate) event_bus: EventBus,
37}
38
39impl StandardMultiStore {
40	#[instrument(name = "store::multi::new", level = "debug", skip(config), fields(
41		has_hot = config.hot.is_some(),
42		has_warm = config.warm.is_some(),
43		has_cold = config.cold.is_some(),
44	))]
45	pub fn new(config: MultiStoreConfig) -> crate::Result<Self> {
46		let hot = config.hot.map(|c| c.storage);
47		// TODO: warm and cold are placeholders for now
48		let warm = None;
49		let cold = None;
50		let _ = config.warm;
51		let _ = config.cold;
52
53		// Use the provided actor system for the drop actor
54		let actor_system = config.actor_system.clone();
55
56		// Spawn drop actor
57		let storage = hot.as_ref().expect("hot tier is required");
58		let drop_config = DropWorkerConfig::default();
59		let drop_actor = DropActor::spawn(
60			&actor_system,
61			drop_config,
62			storage.clone(),
63			config.event_bus.clone(),
64			Clock::default(),
65		);
66
67		Ok(Self(Arc::new(StandardMultiStoreInner {
68			hot,
69			warm,
70			cold,
71			drop_actor,
72			_actor_system: actor_system,
73			event_bus: config.event_bus,
74		})))
75	}
76
77	/// Get access to the hot storage tier.
78	///
79	/// Returns `None` if the hot tier is not configured.
80	pub fn hot(&self) -> Option<&HotStorage> {
81		self.hot.as_ref()
82	}
83}
84
85impl Deref for StandardMultiStore {
86	type Target = StandardMultiStoreInner;
87
88	fn deref(&self) -> &Self::Target {
89		&self.0
90	}
91}
92
93impl StandardMultiStore {
94	pub fn testing_memory() -> Self {
95		let actor_system = ActorSystem::new(SharedRuntimeConfig::default().actor_system_config());
96		Self::testing_memory_with_eventbus(EventBus::new(&actor_system))
97	}
98
99	pub fn testing_memory_with_eventbus(event_bus: EventBus) -> Self {
100		let actor_system = ActorSystem::new(SharedRuntimeConfig::default().actor_system_config());
101		Self::new(MultiStoreConfig {
102			hot: Some(HotConfig {
103				storage: HotStorage::memory(),
104			}),
105			warm: None,
106			cold: None,
107			retention: Default::default(),
108			merge_config: Default::default(),
109			event_bus,
110			actor_system,
111		})
112		.unwrap()
113	}
114}