pub struct GrowingSegment { /* private fields */ }Expand description
Growing segment implementation (in-memory, writable)
Implementations§
Source§impl GrowingSegment
impl GrowingSegment
pub fn may_contain_graph_kind(&self, kind: GraphEntityKind) -> bool
pub fn scan_cursor(&self) -> SegmentScanCursor
Sourcepub fn scan_batch(
&self,
cursor: &mut SegmentScanCursor,
before_work: &mut impl FnMut() -> bool,
visit: &mut impl FnMut(EntityId),
) -> bool
pub fn scan_batch( &self, cursor: &mut SegmentScanCursor, before_work: &mut impl FnMut() -> bool, visit: &mut impl FnMut(EntityId), ) -> bool
Append-only slots survive insertions, deletions and sealing. The caller
owns the segment read guard and must not re-enter storage in visit.
IDs must be hydrated through the manager: retired sources can be stale.
Sourcepub fn for_each_fast<F>(&self, f: F) -> bool
pub fn for_each_fast<F>(&self, f: F) -> bool
Direct iteration without Box
pub fn checkpoint_revision(&self) -> u64
pub fn checkpoint_mutations_since(&self, revision: u64) -> Option<Vec<EntityId>>
pub fn checkpoint_tracking_bytes(&self) -> usize
pub fn update_hot_batch_with_metadata<'a, I>( &mut self, items: I, ) -> Result<(), SegmentError>
pub fn delete_batch( &mut self, ids: &[EntityId], ) -> Result<Vec<EntityId>, SegmentError>
Sourcepub fn memory_bytes(&self) -> u64
pub fn memory_bytes(&self) -> u64
This segment’s approximate resident bytes. One relaxed load — the
arena’s contribution to the shared accounting pool (ADR 0073 §2).
Unlike stats() this never walks the entity map, so a stats reader
does not pay O(entities) to observe memory.
Sourcepub fn resident_entity_count(&self) -> usize
pub fn resident_entity_count(&self) -> usize
Entities physically present, live or tombstoned-but-resident.
Sourcepub fn live_entity_count(&self) -> usize
pub fn live_entity_count(&self) -> usize
Entities visible to readers.
Sourcepub fn tombstone_count(&self) -> usize
pub fn tombstone_count(&self) -> usize
Tombstones this segment carries — including the ones whose entity body was already freed. The set itself is what leaks without consolidation.
Sourcepub fn resident_bytes(&self) -> u64
pub fn resident_bytes(&self) -> u64
Approximate bytes this segment holds: resident entity payloads plus the tombstone set.
Sourcepub fn reclaimable_bytes(&self) -> u64
pub fn reclaimable_bytes(&self) -> u64
Bytes a consolidation of this segment would return to the budget: the payloads of resident tombstones plus the tombstone set that buries them.
Sourcepub fn live_entity_ids(&self) -> Vec<EntityId>
pub fn live_entity_ids(&self) -> Vec<EntityId>
Snapshot the ids of every live entity, in iteration order.
Consolidation copies a segment across several maintenance ticks, so it needs a stable cursor into the segment that survives concurrent tombstoning. Ids are stable; iteration position is not.
Sourcepub fn insert_preserving_sequence(
&mut self,
entity: UnifiedEntity,
) -> Result<EntityId, SegmentError>
pub fn insert_preserving_sequence( &mut self, entity: UnifiedEntity, ) -> Result<EntityId, SegmentError>
Move an existing entity into a writable segment without assigning a new sequence identity. A pending update’s preimage must still match its durable checkpoint after the MVCC delete stamp is normalized.
Sourcepub fn adopt_entity(
&mut self,
entity: UnifiedEntity,
metadata: Option<Metadata>,
)
pub fn adopt_entity( &mut self, entity: UnifiedEntity, metadata: Option<Metadata>, )
Take an entity from another segment, preserving its identity.
Unlike insert, this keeps sequence_id — the merged segment is the
same rows, not new ones, and callers (physical_collection_roots, MVCC
ordering) read that field. All derived structures are rebuilt: kind
index, primary-key index, cross-reference forward/reverse indexes, and
per-column zone maps.
Sourcepub fn evict_entity(&mut self, id: EntityId) -> bool
pub fn evict_entity(&mut self, id: EntityId) -> bool
Physically remove an entity without leaving a tombstone.
Only legal on a segment nobody can see yet — the half-built merged segment, when the swap discovers a copied row was deleted from its source mid-consolidation. A tombstone here would defeat the whole point.
Sourcepub fn can_skip_zone_preds(&self, preds: &[(&str, ZoneColPred<'_>)]) -> bool
pub fn can_skip_zone_preds(&self, preds: &[(&str, ZoneColPred<'_>)]) -> bool
Returns true when this segment can be entirely skipped for the given predicates.
A segment is skipped only if ALL predicates say so (conservative: any non-skippable
predicate forces the scan to proceed).
pub fn graph_index_cursor( &self, kind: GraphEntityKind, keys: &[EntityId], before_work: &mut impl FnMut() -> bool, ) -> Option<GraphIndexCursor>
Sourcepub fn graph_index_batch(
&self,
kind: GraphEntityKind,
keys: &[EntityId],
cursor: &mut GraphIndexCursor,
before_work: &mut impl FnMut() -> bool,
visit: &mut impl FnMut(EntityId),
) -> bool
pub fn graph_index_batch( &self, kind: GraphEntityKind, keys: &[EntityId], cursor: &mut GraphIndexCursor, before_work: &mut impl FnMut() -> bool, visit: &mut impl FnMut(EntityId), ) -> bool
Collect at most SCAN_BATCH_SIZE physical index entries without payload copies. Resume by key seek, never by rescanning an already consumed prefix.
pub fn graph_index_batch_with_limit( &self, kind: GraphEntityKind, keys: &[EntityId], cursor: &mut GraphIndexCursor, before_work: &mut impl FnMut() -> bool, visit: &mut impl FnMut(EntityId), limit: usize, ) -> bool
Sourcepub fn find_unique_key_conflict(
&self,
columns: &[Vec<String>],
key_index: usize,
signatures: &[String],
exclude_id: Option<EntityId>,
reserves_key: &impl Fn(&UnifiedEntity) -> bool,
) -> Option<EntityId>
pub fn find_unique_key_conflict( &self, columns: &[Vec<String>], key_index: usize, signatures: &[String], exclude_id: Option<EntityId>, reserves_key: &impl Fn(&UnifiedEntity) -> bool, ) -> Option<EntityId>
Probe one declared UNIQUE/PRIMARY KEY against physical rows. Cache all current definitions together so alternating constraints never rebuilds the same segment. Schema changes replace the set; mutations invalidate it. The caller owns MVCC conflict policy and null-key admission.
Sourcepub fn find_key_entity(
&self,
key: &str,
newest: bool,
visible: &mut impl FnMut(&UnifiedEntity) -> bool,
) -> Option<&UnifiedEntity>
pub fn find_key_entity( &self, key: &str, newest: bool, visible: &mut impl FnMut(&UnifiedEntity) -> bool, ) -> Option<&UnifiedEntity>
Only matching-key candidates reach visible; no result vector or row clones.
Raw mutable rows are rechecked alongside indexed candidates.
Sourcepub fn visit_queue_dedup(
&self,
queue: &str,
key: Option<&str>,
now: u64,
visit: &mut impl FnMut(&UnifiedEntity) -> bool,
) -> bool
pub fn visit_queue_dedup( &self, queue: &str, key: Option<&str>, now: u64, visit: &mut impl FnMut(&UnifiedEntity) -> bool, ) -> bool
Visit only the requested producer key or expired dedup rows. Recheck original strings after hashing, including rows changed through raw access.
Sourcepub fn may_contain_exact_key(&self, key: &[u8]) -> bool
pub fn may_contain_exact_key(&self, key: &[u8]) -> bool
Check whether an early-exit probe key exists in this segment.
Sourcepub fn get_references_to(&self, id: EntityId) -> Vec<(EntityId, RefType)>
pub fn get_references_to(&self, id: EntityId) -> Vec<(EntityId, RefType)>
Get entities referencing the given entity
Sourcepub fn get_references_from(&self, id: EntityId) -> Vec<(EntityId, RefType)>
pub fn get_references_from(&self, id: EntityId) -> Vec<(EntityId, RefType)>
Get entities referenced by the given entity
Sourcepub fn bulk_insert(
&mut self,
entities: Vec<UnifiedEntity>,
) -> Result<Vec<EntityId>, SegmentError>
pub fn bulk_insert( &mut self, entities: Vec<UnifiedEntity>, ) -> Result<Vec<EntityId>, SegmentError>
Turbo bulk insert — minimal allocations per entity.
Optimizations vs normal insert:
- Skips cross-refs
- Resolves kind_index once per consecutive run of the same storage type
- Pre-allocates kind_index HashSet
- Skips contains_key check (caller guarantees unique IDs)
- Uses Relaxed ordering for sequence counter
Sourcepub fn force_delete(&mut self, id: EntityId) -> bool
pub fn force_delete(&mut self, id: EntityId) -> bool
Delete from this segment regardless of its seal state. Used to mutate sealed segments when DELETE touches bulk-inserted entities.
Sourcepub fn force_update_with_metadata(
&mut self,
entity: &UnifiedEntity,
modified_columns: &[String],
metadata: Option<&Metadata>,
) -> Result<(), SegmentError>
pub fn force_update_with_metadata( &mut self, entity: &UnifiedEntity, modified_columns: &[String], metadata: Option<&Metadata>, ) -> Result<(), SegmentError>
Update an entity in this segment regardless of its seal state. Used to mutate sealed segments when UPDATE touches bulk-inserted entities.
Trait Implementations§
Source§impl UnifiedSegment for GrowingSegment
impl UnifiedSegment for GrowingSegment
Source§fn state(&self) -> SegmentState
fn state(&self) -> SegmentState
Source§fn collection(&self) -> &str
fn collection(&self) -> &str
Source§fn stats(&self) -> SegmentStats
fn stats(&self) -> SegmentStats
Source§fn entity_count(&self) -> usize
fn entity_count(&self) -> usize
Source§fn get_mut(&mut self, id: EntityId) -> Option<&mut UnifiedEntity>
fn get_mut(&mut self, id: EntityId) -> Option<&mut UnifiedEntity>
Source§fn insert(&mut self, entity: UnifiedEntity) -> Result<EntityId, SegmentError>
fn insert(&mut self, entity: UnifiedEntity) -> Result<EntityId, SegmentError>
Source§fn update(&mut self, entity: UnifiedEntity) -> Result<(), SegmentError>
fn update(&mut self, entity: UnifiedEntity) -> Result<(), SegmentError>
Source§fn update_hot(
&mut self,
entity: UnifiedEntity,
modified_columns: &[String],
) -> Result<(), SegmentError>
fn update_hot( &mut self, entity: UnifiedEntity, modified_columns: &[String], ) -> Result<(), SegmentError>
Source§fn set_metadata(
&mut self,
id: EntityId,
metadata: Metadata,
) -> Result<(), SegmentError>
fn set_metadata( &mut self, id: EntityId, metadata: Metadata, ) -> Result<(), SegmentError>
Source§fn should_seal(&self, config: &SegmentConfig) -> bool
fn should_seal(&self, config: &SegmentConfig) -> bool
Source§fn iter_kind(
&self,
kind_filter: &str,
) -> Box<dyn Iterator<Item = &UnifiedEntity> + '_>
fn iter_kind( &self, kind_filter: &str, ) -> Box<dyn Iterator<Item = &UnifiedEntity> + '_>
Source§fn filter_metadata(&self, filters: &[(String, MetadataFilter)]) -> Vec<EntityId>
fn filter_metadata(&self, filters: &[(String, MetadataFilter)]) -> Vec<EntityId>
Auto Trait Implementations§
impl !Freeze for GrowingSegment
impl !RefUnwindSafe for GrowingSegment
impl Forget for GrowingSegment
impl Move for GrowingSegment
impl Send for GrowingSegmentwhere
RawVecInner: Send,
RawTable<(EntityId, UnifiedEntity)>: Send,
Arc<str>: Send,
BoxRaw<GraphNodeKind>: Send,
BoxRaw<GraphEdgeKind>: Send,
BoxRaw<TimeSeriesPointKind>: Send,
Arc<CronSchedule>: Send,
RawTable<(String, Value)>: Send,
Arc<Vec<String>>: Send,
RawTable<(String, String)>: Send,
BoxRaw<EntityAux>: Send,
RawTable<(EntityId, usize)>: Send,
NodeRef<Owned, (EntityId, String), bool, LeafOrInternal>: Send,
BoxRaw<((EntityId, String), bool)>: Send,
NodeRef<Owned, (EntityId, String), i64, LeafOrInternal>: Send,
BoxRaw<((EntityId, String), i64)>: Send,
NodeRef<Owned, (EntityId, String), f64, LeafOrInternal>: Send,
BoxRaw<((EntityId, String), f64)>: Send,
NodeRef<Owned, (EntityId, String), String, LeafOrInternal>: Send,
BoxRaw<((EntityId, String), String)>: Send,
NodeRef<Owned, (EntityId, String), Vec<u8>, LeafOrInternal>: Send,
BoxRaw<((EntityId, String), Vec<u8>)>: Send,
NodeRef<Owned, (EntityId, String), u64, LeafOrInternal>: Send,
BoxRaw<((EntityId, String), u64)>: Send,
RawTable<((EntityId, String), MetadataValue)>: Send,
RawTable<(EntityId, HashSet<String>)>: Send,
NodeRef<Owned, (String, String), EntityId, LeafOrInternal>: Send,
BoxRaw<((String, String), EntityId)>: Send,
RwLock<RawRwLock, Vec<SegmentUniqueKey>>: Send,
Atomic<u64>: Send,
RawTable<(u64, Vec<EntityId>)>: Send,
RawTable<(EntityId, ())>: Send,
NodeRef<Owned, (u64, u64, EntityId), SetValZST, LeafOrInternal>: Send,
BoxRaw<((u64, u64, EntityId), SetValZST)>: Send,
RawTable<(String, HashSet<EntityId>)>: Send,
RwLock<RawRwLock, Option<SegmentGraphIndex>>: Send,
RawTable<(EntityId, Vec<(EntityId, RefType)>)>: Send,
RawTable<(String, ColZone)>: Send,
RawTable<(String, MultiColZone)>: Send,
RawTable<(EntityId, u64)>: Send,
Atomic<usize>: Send,
impl Sync for GrowingSegmentwhere
RawVecInner: Sync,
RawTable<(EntityId, UnifiedEntity)>: Sync,
Arc<str>: Sync,
BoxRaw<GraphNodeKind>: Sync,
BoxRaw<GraphEdgeKind>: Sync,
BoxRaw<TimeSeriesPointKind>: Sync,
Arc<CronSchedule>: Sync,
RawTable<(String, Value)>: Sync,
Arc<Vec<String>>: Sync,
RawTable<(String, String)>: Sync,
BoxRaw<EntityAux>: Sync,
RawTable<(EntityId, usize)>: Sync,
NodeRef<Owned, (EntityId, String), bool, LeafOrInternal>: Sync,
BoxRaw<((EntityId, String), bool)>: Sync,
NodeRef<Owned, (EntityId, String), i64, LeafOrInternal>: Sync,
BoxRaw<((EntityId, String), i64)>: Sync,
NodeRef<Owned, (EntityId, String), f64, LeafOrInternal>: Sync,
BoxRaw<((EntityId, String), f64)>: Sync,
NodeRef<Owned, (EntityId, String), String, LeafOrInternal>: Sync,
BoxRaw<((EntityId, String), String)>: Sync,
NodeRef<Owned, (EntityId, String), Vec<u8>, LeafOrInternal>: Sync,
BoxRaw<((EntityId, String), Vec<u8>)>: Sync,
NodeRef<Owned, (EntityId, String), u64, LeafOrInternal>: Sync,
BoxRaw<((EntityId, String), u64)>: Sync,
RawTable<((EntityId, String), MetadataValue)>: Sync,
RawTable<(EntityId, HashSet<String>)>: Sync,
NodeRef<Owned, (String, String), EntityId, LeafOrInternal>: Sync,
BoxRaw<((String, String), EntityId)>: Sync,
RwLock<RawRwLock, Vec<SegmentUniqueKey>>: Sync,
Atomic<u64>: Sync,
RawTable<(u64, Vec<EntityId>)>: Sync,
RawTable<(EntityId, ())>: Sync,
NodeRef<Owned, (u64, u64, EntityId), SetValZST, LeafOrInternal>: Sync,
BoxRaw<((u64, u64, EntityId), SetValZST)>: Sync,
RawTable<(String, HashSet<EntityId>)>: Sync,
RwLock<RawRwLock, Option<SegmentGraphIndex>>: Sync,
RawTable<(EntityId, Vec<(EntityId, RefType)>)>: Sync,
RawTable<(String, ColZone)>: Sync,
RawTable<(String, MultiColZone)>: Sync,
RawTable<(EntityId, u64)>: Sync,
Atomic<usize>: Sync,
impl Unpin for GrowingSegmentwhere
*const u8 is !null: Unpin,
Arc<str>: Unpin,
Box<GraphNodeKind>: Unpin,
Box<GraphEdgeKind>: Unpin,
Box<TimeSeriesPointKind>: Unpin,
Arc<CronSchedule>: Unpin,
Arc<Vec<String>>: Unpin,
Box<EntityAux>: Unpin,
*const LeafNode<(EntityId, String), bool> is !null: Unpin,
Box<((EntityId, String), bool)>: Unpin,
*const LeafNode<(EntityId, String), i64> is !null: Unpin,
Box<((EntityId, String), i64)>: Unpin,
*const LeafNode<(EntityId, String), f64> is !null: Unpin,
Box<((EntityId, String), f64)>: Unpin,
*const LeafNode<(EntityId, String), String> is !null: Unpin,
Box<((EntityId, String), String)>: Unpin,
*const LeafNode<(EntityId, String), Vec<u8>> is !null: Unpin,
Box<((EntityId, String), Vec<u8>)>: Unpin,
*const LeafNode<(EntityId, String), u64> is !null: Unpin,
Box<((EntityId, String), u64)>: Unpin,
*const LeafNode<(String, String), EntityId> is !null: Unpin,
Box<((String, String), EntityId)>: Unpin,
Align8<usize>: Unpin,
Align8<u64>: Unpin,
*const LeafNode<(u64, u64, EntityId), SetValZST> is !null: Unpin,
Box<((u64, u64, EntityId), SetValZST)>: Unpin,
*const LeafNode<(EntityId, EntityId), SetValZST> is !null: Unpin,
Box<((EntityId, EntityId), SetValZST)>: Unpin,
impl UnsafeUnpin for GrowingSegmentwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<(EntityId, UnifiedEntity)>: UnsafeUnpin,
PhantomData<EntityId>: UnsafeUnpin,
PhantomData<UnifiedEntity>: UnsafeUnpin,
PhantomData<(EntityId, usize)>: UnsafeUnpin,
*const LeafNode<(EntityId, String), bool> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<((EntityId, String), bool)>>: UnsafeUnpin,
*const LeafNode<(EntityId, String), i64> is !null: UnsafeUnpin,
PhantomData<Box<((EntityId, String), i64)>>: UnsafeUnpin,
*const LeafNode<(EntityId, String), f64> is !null: UnsafeUnpin,
PhantomData<Box<((EntityId, String), f64)>>: UnsafeUnpin,
*const LeafNode<(EntityId, String), String> is !null: UnsafeUnpin,
PhantomData<Box<((EntityId, String), String)>>: UnsafeUnpin,
*const LeafNode<(EntityId, String), Vec<u8>> is !null: UnsafeUnpin,
PhantomData<Box<((EntityId, String), Vec<u8>)>>: UnsafeUnpin,
*const LeafNode<(EntityId, String), u64> is !null: UnsafeUnpin,
PhantomData<Box<((EntityId, String), u64)>>: UnsafeUnpin,
PhantomData<((EntityId, String), MetadataValue)>: UnsafeUnpin,
PhantomData<(EntityId, HashSet<String>)>: UnsafeUnpin,
*const LeafNode<(String, String), EntityId> is !null: UnsafeUnpin,
PhantomData<Box<((String, String), EntityId)>>: UnsafeUnpin,
Align8<usize>: UnsafeUnpin,
PhantomData<SegmentUniqueKey>: UnsafeUnpin,
Align8<u64>: UnsafeUnpin,
PhantomData<(u64, Vec<EntityId>)>: UnsafeUnpin,
PhantomData<(EntityId, ())>: UnsafeUnpin,
*const LeafNode<(u64, u64, EntityId), SetValZST> is !null: UnsafeUnpin,
PhantomData<Box<((u64, u64, EntityId), SetValZST)>>: UnsafeUnpin,
PhantomData<(String, HashSet<EntityId>)>: UnsafeUnpin,
*const LeafNode<(EntityId, EntityId), SetValZST> is !null: UnsafeUnpin,
PhantomData<Box<((EntityId, EntityId), SetValZST)>>: UnsafeUnpin,
PhantomData<(EntityId, Vec<(EntityId, RefType)>)>: UnsafeUnpin,
PhantomData<(String, ColZone)>: UnsafeUnpin,
PhantomData<(String, MultiColZone)>: UnsafeUnpin,
PhantomData<(u64, EntityId)>: UnsafeUnpin,
PhantomData<(EntityId, u64)>: UnsafeUnpin,
impl UnwindSafe for GrowingSegmentwhere
RawVecInner: UnwindSafe,
HashMap<EntityId, UnifiedEntity>: UnwindSafe,
Arc<str>: UnwindSafe,
BoxRaw<GraphNodeKind>: UnwindSafe,
BoxRaw<GraphEdgeKind>: UnwindSafe,
BoxRaw<TimeSeriesPointKind>: UnwindSafe,
Arc<CronSchedule>: UnwindSafe,
HashMap<String, Value>: UnwindSafe,
Arc<Vec<String>>: UnwindSafe,
HashMap<String, String>: UnwindSafe,
BoxRaw<EntityAux>: UnwindSafe,
HashMap<EntityId, usize>: UnwindSafe,
BTreeMap<(EntityId, String), bool>: UnwindSafe,
BTreeMap<(EntityId, String), i64>: UnwindSafe,
BTreeMap<(EntityId, String), f64>: UnwindSafe,
BTreeMap<(EntityId, String), String>: UnwindSafe,
BTreeMap<(EntityId, String), Vec<u8>>: UnwindSafe,
BTreeMap<(EntityId, String), u64>: UnwindSafe,
HashMap<(EntityId, String), MetadataValue>: UnwindSafe,
HashMap<EntityId, HashSet<String>>: UnwindSafe,
BTreeMap<(String, String), EntityId>: UnwindSafe,
Align8<usize>: UnwindSafe,
HashMap<u64, Vec<EntityId>>: UnwindSafe,
Align8<u64>: UnwindSafe,
NonNull<u8>: UnwindSafe,
BTreeMap<(u64, u64, EntityId), SetValZST>: UnwindSafe,
HashMap<String, HashSet<EntityId>>: UnwindSafe,
BTreeMap<(EntityId, EntityId), SetValZST>: UnwindSafe,
HashMap<EntityId, Vec<(EntityId, RefType)>>: UnwindSafe,
HashMap<String, ColZone>: UnwindSafe,
HashMap<String, MultiColZone>: UnwindSafe,
HashMap<EntityId, u64>: UnwindSafe,
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 more