pub struct TagInvertedIndex { /* private fields */ }Expand description
Thread-safe inverted tag index.
Maps "tag_key=tag_value" → set of segment IDs that contain that
tag value. This enables O(1) lookup to determine which segments
could possibly match a tag filter, avoiding full segment scans.
A reverse index (segment_id → set of tag keys) enables O(k) segment
removal where k is the number of tag values for that segment, instead
of scanning all entries.
§Thread Safety
A single RwLock<InvertedState> is used intentionally —
remove_segment must atomically update all three maps (index, reverse,
key_values) to prevent partial state on crash/panic. parking_lot::RwLock
allows concurrent readers; writers only hold the lock during short
segment catalog mutations (add/remove), which are infrequent relative
to the query read-path.
Implementations§
Source§impl TagInvertedIndex
impl TagInvertedIndex
Sourcepub fn with_max_cardinality(max_tag_cardinality: usize) -> Self
pub fn with_max_cardinality(max_tag_cardinality: usize) -> Self
Create an empty inverted tag index with a custom cardinality limit.
Limits the number of distinct values tracked per tag key.
Sourcepub fn add_segment(&self, segment_id: SegmentId, tag_values: &[(&str, &str)])
pub fn add_segment(&self, segment_id: SegmentId, tag_values: &[(&str, &str)])
Register a segment’s tag values in the index.
For each tag column in the segment’s catalog entry, the distinct values (if available via column stats or direct metadata) are mapped to the segment ID.
Sourcepub fn remove_segment(&self, segment_id: SegmentId)
pub fn remove_segment(&self, segment_id: SegmentId)
Remove a segment from the index in O(k) time where k is the number of tag values for that segment.
Sourcepub fn segments_for_tag(&self, key: &str, value: &str) -> Vec<SegmentId>
pub fn segments_for_tag(&self, key: &str, value: &str) -> Vec<SegmentId>
Find segments that contain a specific tag value.
Sourcepub fn replace_segments(
&self,
old_segment_ids: &[SegmentId],
new_segment_id: SegmentId,
new_tag_values: &[(&str, &str)],
)
pub fn replace_segments( &self, old_segment_ids: &[SegmentId], new_segment_id: SegmentId, new_tag_values: &[(&str, &str)], )
Atomically replace multiple old segments with a single new segment.
Used during compaction to avoid a window where the old segments have been removed but the new one hasn’t been added yet, which would cause concurrent tag-filtered queries to miss data.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Returns the total number of indexed tag-value pairs.
Sourcepub fn values_for_key(&self, key: &str) -> Vec<String>
pub fn values_for_key(&self, key: &str) -> Vec<String>
Returns all distinct values for a given tag key.
O(1) lookup via the secondary key_values index
instead of scanning all entries with strip_prefix.
Trait Implementations§
Source§impl Debug for TagInvertedIndex
impl Debug for TagInvertedIndex
Auto Trait Implementations§
impl !Freeze for TagInvertedIndex
impl !RefUnwindSafe for TagInvertedIndex
impl Send for TagInvertedIndex
impl Sync for TagInvertedIndex
impl Unpin for TagInvertedIndex
impl UnsafeUnpin for TagInvertedIndex
impl UnwindSafe for TagInvertedIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more