1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Per-adapter resource budgets: the vector adapter's own cache budget
//! (`vector_cache_bytes`, a child of the managed limit), and a named child of
//! the shared phase budget per query adapter (SQL, graph), so each adapter's
//! `peak`/`used` (a real, measured high-water mark — see
//! [`crate::resources::ByteBudget::snapshot`]) is individually observable.
//! Each phase child's limit equals its parent's, so those are pure
//! attribution: they do not narrow the shared capacity the adapters contend
//! on (see [`crate::resources::ByteBudget::child`]).
use crate::resources::ByteBudget;
use crate::{StorageError, Store};
/// The vector cache budget and one named attribution child per query
/// adapter. `None` exactly when its budget (`vector_cache_bytes` /
/// `phase_resources`) is disabled.
pub(crate) struct AdapterBudgets {
vector_cache: Option<ByteBudget>,
sql_phase: Option<ByteBudget>,
graph_phase: Option<ByteBudget>,
}
impl AdapterBudgets {
pub(crate) fn new(
vector_cache: Option<ByteBudget>,
phase: Option<&ByteBudget>,
) -> Result<Self, StorageError> {
let child = |parent: Option<&ByteBudget>, name: &'static str| {
parent
.map(|parent| parent.child(name, parent.snapshot().limit))
.transpose()
.map_err(|e| StorageError::InvalidConfiguration(e.to_string()))
};
Ok(Self {
vector_cache,
sql_phase: child(phase, "sql-phase")?,
graph_phase: child(phase, "graph-phase")?,
})
}
}
impl Store {
/// The vector adapter's cache budget (`vector_cache_bytes`).
#[must_use]
pub fn vector_cache_budget(&self) -> Option<ByteBudget> {
self.adapter_budgets.vector_cache.clone()
}
/// The SQL adapter's named child of [`Store::phase_budget`].
#[must_use]
pub fn sql_phase_budget(&self) -> Option<ByteBudget> {
self.adapter_budgets.sql_phase.clone()
}
/// The native graph/query adapter's named child of [`Store::phase_budget`]
#[must_use]
pub fn graph_phase_budget(&self) -> Option<ByteBudget> {
self.adapter_budgets.graph_phase.clone()
}
}