pub struct StorageMetadataIndex {
pub entries: HashMap<u64, MetadataIndexEntry>,
pub field_index: HashMap<MetadataField, Vec<u64>>,
pub stats: MetadataIndexStats,
}Expand description
Secondary index over block metadata fields enabling efficient filtered queries.
§Design
Two data structures are maintained in tandem:
entries— aHashMap<block_id, MetadataIndexEntry>for O(1) point lookups and to support fast replacement when the same block is re-inserted.field_index— an inverted index mapping eachMetadataFieldto the set ofblock_ids that carry that field.
Queries intersect the posting lists of all must_have fields (giving the
candidate set), then subtract any block whose entry contains a must_not_have
field.
Fields§
§entries: HashMap<u64, MetadataIndexEntry>Primary store: block_id → entry.
field_index: HashMap<MetadataField, Vec<u64>>Inverted index: field → block_ids.
stats: MetadataIndexStatsRunning statistics.
Implementations§
Source§impl StorageMetadataIndex
impl StorageMetadataIndex
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty StorageMetadataIndex.
Sourcepub fn insert(&mut self, entry: MetadataIndexEntry)
pub fn insert(&mut self, entry: MetadataIndexEntry)
Insert (or replace) a block entry.
If a block with the same block_id already exists its old field index
postings are removed before the new entry is written.
Sourcepub fn remove(&mut self, block_id: u64) -> bool
pub fn remove(&mut self, block_id: u64) -> bool
Remove the entry for block_id.
Returns true if an entry was present and removed, false otherwise.
Sourcepub fn query(&mut self, q: &MetadataQuery) -> Vec<MetadataQueryResult>
pub fn query(&mut self, q: &MetadataQuery) -> Vec<MetadataQueryResult>
Execute a structured metadata query.
§Algorithm
- Candidate set – if
must_haveis empty, all block IDs are candidates; otherwise the candidate set is the intersection of the posting lists for eachmust_havefield. - Exclusion – remove any candidate whose entry contains any
must_not_havefield. - Projection – build a
MetadataQueryResultper surviving candidate recording whichmust_havefields matched. - Sort – apply
sort_byif present. - Limit – truncate to
limitif present. - Stats – increment
total_queries.
Sourcepub fn get(&self, block_id: u64) -> Option<&MetadataIndexEntry>
pub fn get(&self, block_id: u64) -> Option<&MetadataIndexEntry>
Return a reference to the entry for block_id, or None.
Sourcepub fn stats(&self) -> &MetadataIndexStats
pub fn stats(&self) -> &MetadataIndexStats
Return a reference to the current statistics snapshot.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageMetadataIndex
impl RefUnwindSafe for StorageMetadataIndex
impl Send for StorageMetadataIndex
impl Sync for StorageMetadataIndex
impl Unpin for StorageMetadataIndex
impl UnsafeUnpin for StorageMetadataIndex
impl UnwindSafe for StorageMetadataIndex
Blanket Implementations§
impl<T> Allocation for T
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