pub struct SegmentManager<D: DirectoryWriter + 'static> { /* private fields */ }Expand description
Segment manager - coordinates segment registration and background merging
This is the SOLE owner of metadata.json ensuring linearized access.
All segment list modifications and metadata updates go through here.
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,
) -> Self
pub fn new( directory: Arc<D>, schema: Arc<Schema>, metadata: IndexMetadata, merge_policy: Box<dyn MergePolicy>, term_cache_blocks: 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 (snapshot)
Sourcepub fn pending_merge_count(&self) -> usize
pub fn pending_merge_count(&self) -> usize
Get the number of pending background merges
Sourcepub fn metadata(&self) -> Arc<AsyncMutex<IndexMetadata>>
pub fn metadata(&self) -> Arc<AsyncMutex<IndexMetadata>>
Get a clone of the metadata Arc for read access
Sourcepub async fn update_metadata<F>(&self, f: F) -> Result<()>where
F: FnOnce(&mut IndexMetadata),
pub async fn update_metadata<F>(&self, f: F) -> Result<()>where
F: FnOnce(&mut IndexMetadata),
Update metadata with a closure and persist atomically
Sourcepub async fn acquire_snapshot(&self) -> SegmentSnapshot<D>
pub async fn acquire_snapshot(&self) -> SegmentSnapshot<D>
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>
Native-only methods for SegmentManager (merging, segment registration)
impl<D: DirectoryWriter + 'static> SegmentManager<D>
Native-only methods for SegmentManager (merging, segment registration)
Sourcepub async fn register_segment(&self, segment_id: String) -> Result<()>
pub async fn register_segment(&self, segment_id: String) -> Result<()>
Register a new segment, persist metadata, and trigger merge check
This is the main entry point for adding segments after builds complete.
Sourcepub async fn maybe_merge(&self)
pub async fn maybe_merge(&self)
Check merge policy and spawn background merges if needed
Sourcepub async fn wait_for_merges(&self)
pub async fn wait_for_merges(&self)
Wait for all pending merges to complete
Sourcepub async fn replace_segments(
&self,
new_segments: Vec<String>,
old_to_delete: Vec<String>,
) -> Result<()>
pub async fn replace_segments( &self, new_segments: Vec<String>, old_to_delete: Vec<String>, ) -> Result<()>
Replace segment list atomically (for force merge / rebuild)
Sourcepub async fn cleanup_orphan_segments(&self) -> Result<usize>
pub async fn cleanup_orphan_segments(&self) -> Result<usize>
Clean up orphan segment files that are not registered
This can happen if the process halts after segment files are written but before they are registered in metadata.json. Call this on startup to reclaim disk space from incomplete operations.
Returns the number of orphan segments deleted.
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.