pub struct SegmentManager<D: DirectoryWriter + 'static> { /* private fields */ }Expand description
Segment manager - coordinates segment registration and background merging
This is the central point for:
- Tracking all segment IDs
- Registering new segments (from builds or merges)
- Triggering merge checks when segments are added
- Coordinating background merge tasks
Implementations§
Source§impl<D: DirectoryWriter + 'static> SegmentManager<D>
impl<D: DirectoryWriter + 'static> SegmentManager<D>
Sourcepub fn new(
directory: Arc<D>,
schema: Arc<Schema>,
segment_ids: Vec<String>,
merge_policy: Box<dyn MergePolicy>,
term_cache_blocks: usize,
) -> Self
pub fn new( directory: Arc<D>, schema: Arc<Schema>, segment_ids: Vec<String>, merge_policy: Box<dyn MergePolicy>, term_cache_blocks: usize, ) -> Self
Create a new segment manager
Sourcepub fn segment_ids(&self) -> Arc<AsyncMutex<Vec<String>>>
pub fn segment_ids(&self) -> Arc<AsyncMutex<Vec<String>>>
Get a clone of the segment_ids Arc for sharing with background tasks
Sourcepub async fn get_segment_ids(&self) -> Vec<String>
pub async fn get_segment_ids(&self) -> Vec<String>
Get the current segment IDs
Sourcepub async fn register_segment(&self, segment_id: String)
pub async fn register_segment(&self, segment_id: String)
Register a new segment and trigger merge check
This is the main entry point for adding segments. It:
- Adds the segment ID to the list
- Checks the merge policy and spawns background merges if needed
Sourcepub fn pending_merge_count(&self) -> usize
pub fn pending_merge_count(&self) -> usize
Get the number of pending background merges
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 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 segments.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.