Skip to main content

GrowingSegment

Struct GrowingSegment 

Source
pub struct GrowingSegment { /* private fields */ }
Expand description

Growing segment implementation (in-memory, writable)

Implementations§

Source§

impl GrowingSegment

Source

pub fn may_contain_graph_kind(&self, kind: GraphEntityKind) -> bool

Source

pub fn scan_cursor(&self) -> SegmentScanCursor

Source

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.

Source

pub fn for_each_fast<F>(&self, f: F) -> bool
where F: FnMut(&UnifiedEntity) -> bool,

Direct iteration without Box trait dispatch. Returns false to stop early. Uses concrete iterator types to avoid heap allocation per call.

Source

pub fn new(id: SegmentId, collection: impl Into<String>) -> Self

Create a new growing segment

Source

pub fn checkpoint_revision(&self) -> u64

Source

pub fn checkpoint_mutations_since(&self, revision: u64) -> Option<Vec<EntityId>>

Source

pub fn checkpoint_tracking_bytes(&self) -> usize

Source

pub fn update_hot_batch_with_metadata<'a, I>( &mut self, items: I, ) -> Result<(), SegmentError>
where I: IntoIterator<Item = (&'a UnifiedEntity, &'a [String], Option<&'a Metadata>)>,

Source

pub fn delete_batch( &mut self, ids: &[EntityId], ) -> Result<Vec<EntityId>, SegmentError>

Source

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.

Source

pub fn resident_entity_count(&self) -> usize

Entities physically present, live or tombstoned-but-resident.

Source

pub fn live_entity_count(&self) -> usize

Entities visible to readers.

Source

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.

Source

pub fn resident_bytes(&self) -> u64

Approximate bytes this segment holds: resident entity payloads plus the tombstone set.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn graph_index_cursor( &self, kind: GraphEntityKind, keys: &[EntityId], before_work: &mut impl FnMut() -> bool, ) -> Option<GraphIndexCursor>

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn may_contain_exact_key(&self, key: &[u8]) -> bool

Check whether an early-exit probe key exists in this segment.

Source

pub fn get_references_to(&self, id: EntityId) -> Vec<(EntityId, RefType)>

Get entities referencing the given entity

Source

pub fn get_references_from(&self, id: EntityId) -> Vec<(EntityId, RefType)>

Get entities referenced by the given entity

Source

pub fn age_secs(&self) -> u64

Get age in seconds

Source

pub fn idle_secs(&self) -> u64

Get time since last write

Source

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
Source

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.

Source

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

Source§

fn id(&self) -> SegmentId

Get segment ID
Source§

fn state(&self) -> SegmentState

Get current state
Source§

fn collection(&self) -> &str

Get collection/namespace name
Source§

fn stats(&self) -> SegmentStats

Get statistics
Source§

fn entity_count(&self) -> usize

O(1) live entity count (entities minus tombstones)
Source§

fn contains(&self, id: EntityId) -> bool

Check if entity exists
Source§

fn get(&self, id: EntityId) -> Option<&UnifiedEntity>

Get an entity by ID
Source§

fn get_mut(&mut self, id: EntityId) -> Option<&mut UnifiedEntity>

Get mutable reference to entity
Source§

fn insert(&mut self, entity: UnifiedEntity) -> Result<EntityId, SegmentError>

Insert a new entity
Source§

fn update(&mut self, entity: UnifiedEntity) -> Result<(), SegmentError>

Update an existing entity
Source§

fn update_hot( &mut self, entity: UnifiedEntity, modified_columns: &[String], ) -> Result<(), SegmentError>

HOT-update: like update but receives the set of field names that actually changed. Allows skipping index work when indexed columns are unaffected. Default: falls back to full update.
Source§

fn delete(&mut self, id: EntityId) -> Result<bool, SegmentError>

Delete an entity
Source§

fn get_metadata(&self, id: EntityId) -> Option<Metadata>

Get metadata for an entity
Source§

fn set_metadata( &mut self, id: EntityId, metadata: Metadata, ) -> Result<(), SegmentError>

Set metadata for an entity
Source§

fn seal(&mut self) -> Result<(), SegmentError>

Seal the segment (make immutable)
Source§

fn should_seal(&self, config: &SegmentConfig) -> bool

Check if should auto-seal based on config
Source§

fn iter(&self) -> Box<dyn Iterator<Item = &UnifiedEntity> + '_>

Iterate over all entities
Source§

fn iter_kind( &self, kind_filter: &str, ) -> Box<dyn Iterator<Item = &UnifiedEntity> + '_>

Iterate over entities of a specific kind
Source§

fn filter_metadata(&self, filters: &[(String, MetadataFilter)]) -> Vec<EntityId>

Search entities by metadata filter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.