summavy/indexer/
segment_entry.rs

1use std::fmt;
2
3use common::BitSet;
4
5use crate::core::{SegmentId, SegmentMeta};
6use crate::indexer::delete_queue::DeleteCursor;
7
8/// A segment entry describes the state of
9/// a given segment, at a given instant.
10///
11/// In addition to segment `meta`,
12/// it contains a few transient states
13/// - `alive_bitset` is a bitset describing
14/// documents that were alive during the commit
15/// itself.
16/// - `delete_cursor` is the position in the delete queue.
17/// Deletes happening before the cursor are reflected either
18/// in the .del file or in the `alive_bitset`.
19#[derive(Clone)]
20pub struct SegmentEntry {
21    meta: SegmentMeta,
22    alive_bitset: Option<BitSet>,
23    delete_cursor: DeleteCursor,
24}
25
26impl SegmentEntry {
27    /// Create a new `SegmentEntry`
28    pub fn new(
29        segment_meta: SegmentMeta,
30        delete_cursor: DeleteCursor,
31        alive_bitset: Option<BitSet>,
32    ) -> SegmentEntry {
33        SegmentEntry {
34            meta: segment_meta,
35            alive_bitset,
36            delete_cursor,
37        }
38    }
39
40    /// Return a reference to the segment entry deleted bitset.
41    ///
42    /// `DocId` in this bitset are flagged as deleted.
43    pub fn alive_bitset(&self) -> Option<&BitSet> {
44        self.alive_bitset.as_ref()
45    }
46
47    /// Set the `SegmentMeta` for this segment.
48    pub fn set_meta(&mut self, segment_meta: SegmentMeta) {
49        self.meta = segment_meta;
50    }
51
52    /// Return a reference to the segment_entry's delete cursor
53    pub fn delete_cursor(&mut self) -> &mut DeleteCursor {
54        &mut self.delete_cursor
55    }
56
57    /// Returns the segment id.
58    pub fn segment_id(&self) -> SegmentId {
59        self.meta.id()
60    }
61
62    /// Accessor to the `SegmentMeta`
63    pub fn meta(&self) -> &SegmentMeta {
64        &self.meta
65    }
66}
67
68impl fmt::Debug for SegmentEntry {
69    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
70        write!(formatter, "SegmentEntry({:?})", self.meta)
71    }
72}