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 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.