pub struct FlowStore { /* private fields */ }Expand description
The kept half: read and write a namespace’s days. Cheap to clone; every clone reads and writes the same document.
Implementations§
Source§impl FlowStore
impl FlowStore
Sourcepub fn new(store: Arc<dyn ControlStore>) -> Result<Self>
pub fn new(store: Arc<dyn ControlStore>) -> Result<Self>
Open the flow document held in store (the server’s control store). A
store that has never held one reads as empty, which is the truth for
every server that predates this file: no flow was counted, so no flow is
reported — never a zero that would read as nothing happened.
Sourcepub fn day(&self, namespace: &str, day: i64) -> Result<Option<FlowDay>>
pub fn day(&self, namespace: &str, day: i64) -> Result<Option<FlowDay>>
One namespace’s row for one day, or None when that day has no traffic.
Sourcepub fn series(
&self,
namespace: &str,
from_day: i64,
to_day: i64,
) -> Result<Vec<(i64, FlowDay)>>
pub fn series( &self, namespace: &str, from_day: i64, to_day: i64, ) -> Result<Vec<(i64, FlowDay)>>
The series for one namespace, oldest first, over the inclusive day range. Days with no traffic are absent rather than zero-filled: the caller knows the range it asked for, and a row that was never written is not a row of zeroes that was.
Sourcepub fn namespaces(&self) -> Result<Vec<String>>
pub fn namespaces(&self) -> Result<Vec<String>>
Every namespace that has ever had a row. Whole-map, O(entries) — the fleet view and the flush, never a transfer.
Sourcepub fn put(&self, rows: &[(String, i64, FlowDay)], today: i64) -> Result<()>
pub fn put(&self, rows: &[(String, i64, FlowDay)], today: i64) -> Result<()>
Write these rows, replacing whatever each day held, and drop anything
older than RETENTION_DAYS before today.
Replace and not add, because the live slot holds the whole of the day it is writing: see the module doc. An empty row REMOVES the day rather than storing zeroes — a namespace that had a row and then had a day of silence must not grow a row saying so.
One document update for the whole batch, so a flush touching forty namespaces is one compare-and-swap and not forty.