Skip to content

Commit 198a47d

Browse files
committed
simplify MiniTsdb and make ingest not immediately available for querying
1 parent e7c74da commit 198a47d

5 files changed

Lines changed: 146 additions & 333 deletions

File tree

open-tsdb/src/delta.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,43 @@ pub(crate) struct TsdbDelta {
129129
pub(crate) samples: HashMap<SeriesId, Vec<Sample>>,
130130
}
131131

132+
impl TsdbDelta {
133+
/// Create an empty delta for a bucket
134+
pub(crate) fn empty(bucket: TimeBucket) -> Self {
135+
Self {
136+
bucket,
137+
forward_index: ForwardIndex::default(),
138+
inverted_index: InvertedIndex::default(),
139+
series_dict: HashMap::new(),
140+
samples: HashMap::new(),
141+
}
142+
}
143+
144+
/// Check if delta has any data
145+
pub(crate) fn is_empty(&self) -> bool {
146+
self.samples.is_empty() && self.series_dict.is_empty()
147+
}
148+
149+
/// Merge another delta into this one, accumulating all data
150+
pub(crate) fn merge(&mut self, other: TsdbDelta) {
151+
// Merge forward index
152+
self.forward_index.merge(&other.forward_index);
153+
154+
// Merge inverted index
155+
self.inverted_index.merge(other.inverted_index);
156+
157+
// Merge series dict
158+
for (fingerprint, series_id) in other.series_dict {
159+
self.series_dict.insert(fingerprint, series_id);
160+
}
161+
162+
// Merge samples
163+
for (series_id, samples) in other.samples {
164+
self.samples.entry(series_id).or_default().extend(samples);
165+
}
166+
}
167+
}
168+
132169
#[cfg(test)]
133170
mod tests {
134171
use super::*;

0 commit comments

Comments
 (0)