pub struct SegmentManager<D: DirectoryWriter + 'static> { /* private fields */ }Expand description
Segment manager — coordinates segment commit, background merging, and trained structures.
SOLE owner of metadata.json. All metadata mutations go through state Mutex.
Implementations§
Source§impl<D: DirectoryWriter + 'static> SegmentManager<D>
impl<D: DirectoryWriter + 'static> SegmentManager<D>
Sourcepub fn new(
directory: Arc<D>,
schema: Arc<Schema>,
metadata: IndexMetadata,
merge_policy: Box<dyn MergePolicy>,
term_cache_blocks: usize,
max_concurrent_merges: usize,
) -> Self
pub fn new( directory: Arc<D>, schema: Arc<Schema>, metadata: IndexMetadata, merge_policy: Box<dyn MergePolicy>, term_cache_blocks: usize, max_concurrent_merges: usize, ) -> Self
Create a new segment manager with existing metadata
Sourcepub async fn get_segment_ids(&self) -> Vec<String>
pub async fn get_segment_ids(&self) -> Vec<String>
Get the current segment IDs
Sourcepub fn trained(&self) -> Option<Arc<TrainedVectorStructures>>
pub fn trained(&self) -> Option<Arc<TrainedVectorStructures>>
Get trained vector structures (lock-free via ArcSwap)
Sourcepub async fn load_and_publish_trained(&self)
pub async fn load_and_publish_trained(&self)
Load trained structures from disk and publish to ArcSwap. Copies metadata under lock, releases lock, then does disk I/O.
Sourcepub async fn acquire_snapshot(&self) -> SegmentSnapshot
pub async fn acquire_snapshot(&self) -> SegmentSnapshot
Acquire a snapshot of current segments for reading. The snapshot holds references — segments won’t be deleted while snapshot exists.
Sourcepub fn tracker(&self) -> Arc<SegmentTracker>
pub fn tracker(&self) -> Arc<SegmentTracker>
Get the segment tracker
Source§impl<D: DirectoryWriter + 'static> SegmentManager<D>
impl<D: DirectoryWriter + 'static> SegmentManager<D>
Sourcepub async fn commit(&self, new_segments: Vec<(String, u32)>) -> Result<()>
pub async fn commit(&self, new_segments: Vec<(String, u32)>) -> Result<()>
Atomic commit: register new segments + persist metadata.
Sourcepub async fn maybe_merge(self: &Arc<Self>)
pub async fn maybe_merge(self: &Arc<Self>)
Evaluate merge policy and spawn background merges for all eligible candidates.
Single lock scope: builds segment list AND calls find_merges atomically to prevent stale-list races with concurrent replace_segments. Segments already involved in active merges are excluded from policy evaluation so the policy only sees truly available segments.
Note: max_concurrent_merges is a soft limit — concurrent auto-triggers
may briefly exceed it by one or two due to TOCTOU between slot counting
and handle registration.
Sourcepub async fn wait_for_merging_thread(self: &Arc<Self>)
pub async fn wait_for_merging_thread(self: &Arc<Self>)
Wait for all current in-flight merges to complete.
Sourcepub async fn wait_for_all_merges(self: &Arc<Self>)
pub async fn wait_for_all_merges(self: &Arc<Self>)
Wait for all eligible merges to complete, including cascading merges.
Drains current handles, then loops. Each completed merge auto-triggers
maybe_merge (which pushes new handles) before its JoinHandle resolves,
so by the time h.await returns all cascading handles are registered.
Sourcepub async fn force_merge(self: &Arc<Self>) -> Result<()>
pub async fn force_merge(self: &Arc<Self>) -> Result<()>
Force merge all segments into one. Iterates in batches until ≤1 segment remains.
Each batch is registered in merge_inventory via MergeGuard to prevent
maybe_merge from spawning a conflicting background merge.
Sourcepub async fn cleanup_orphan_segments(&self) -> Result<usize>
pub async fn cleanup_orphan_segments(&self) -> Result<usize>
Clean up orphan segment files not registered in metadata.
Non-blocking: reads both metadata and merge_inventory to determine which
segments are legitimate. In-flight merge outputs are protected by the inventory.
Auto Trait Implementations§
impl<D> !Freeze for SegmentManager<D>
impl<D> !RefUnwindSafe for SegmentManager<D>
impl<D> Send for SegmentManager<D>
impl<D> Sync for SegmentManager<D>
impl<D> Unpin for SegmentManager<D>
impl<D> !UnwindSafe for SegmentManager<D>
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
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.