pub struct WriteTransaction<'db> { /* private fields */ }Expand description
Single writer transaction.
Mutations accumulate into a private write overlay layered over the parent
snapshot; reads fall through the overlay then the base. commit appends the
overlay’s mutation log to the WAL (when dirty) and publishes a fresh snapshot;
rollback drops the overlay and appends nothing.
§Performance
Creating and moving a writer is O(1); each mutation is O(log change).
Implementations§
Source§impl WriteTransaction<'_>
impl WriteTransaction<'_>
Sourcepub fn register_relation_type(
&mut self,
name: impl Into<String>,
) -> Result<RelationTypeId, DbError>
pub fn register_relation_type( &mut self, name: impl Into<String>, ) -> Result<RelationTypeId, DbError>
Sourcepub fn register_property_key(
&mut self,
name: impl Into<String>,
family: PropertyFamily,
value_type: PropertyType,
) -> Result<PropertyKeyId, DbError>
pub fn register_property_key( &mut self, name: impl Into<String>, family: PropertyFamily, value_type: PropertyType, ) -> Result<PropertyKeyId, DbError>
Sourcepub fn define_projection(
&mut self,
definition: ProjectionDefinition,
) -> Result<ProjectionId, DbError>
pub fn define_projection( &mut self, definition: ProjectionDefinition, ) -> Result<ProjectionId, DbError>
Sourcepub fn define_index(
&mut self,
name: impl Into<String>,
definition: IndexDefinition,
) -> Result<IndexId, DbError>
pub fn define_index( &mut self, name: impl Into<String>, definition: IndexDefinition, ) -> Result<IndexId, DbError>
Sourcepub fn create_element(&mut self) -> Result<ElementId, DbError>
pub fn create_element(&mut self) -> Result<ElementId, DbError>
Creates a canonical element.
§Errors
Returns DbError::IdOverflow when element IDs are exhausted.
§Performance
This method is O(log element change).
Sourcepub fn create_relation(&mut self) -> Result<RelationId, DbError>
pub fn create_relation(&mut self) -> Result<RelationId, DbError>
Creates a canonical relation.
§Errors
Returns DbError::IdOverflow when relation IDs are exhausted.
§Performance
This method is O(log relation change).
Sourcepub fn create_incidence(
&mut self,
relation: RelationId,
element: ElementId,
role: RoleId,
) -> Result<IncidenceId, DbError>
pub fn create_incidence( &mut self, relation: RelationId, element: ElementId, role: RoleId, ) -> Result<IncidenceId, DbError>
Sourcepub fn tombstone_element(&mut self, id: ElementId) -> Result<(), DbError>
pub fn tombstone_element(&mut self, id: ElementId) -> Result<(), DbError>
Tombstones a canonical element and its incidences.
§Errors
Returns DbError::UnknownElement when the element is not visible.
§Performance
This method is O(incidence count).
Sourcepub fn tombstone_relation(&mut self, id: RelationId) -> Result<(), DbError>
pub fn tombstone_relation(&mut self, id: RelationId) -> Result<(), DbError>
Tombstones a canonical relation and its incidences.
§Errors
Returns DbError::UnknownRelation when the relation is not visible.
§Performance
This method is O(incidence count).
Sourcepub fn tombstone_incidence(&mut self, id: IncidenceId) -> Result<(), DbError>
pub fn tombstone_incidence(&mut self, id: IncidenceId) -> Result<(), DbError>
Tombstones a canonical incidence.
§Errors
Returns DbError::UnknownIncidence when the incidence is not visible.
§Performance
This method is O(log incidence change).
Sourcepub fn add_element_label(
&mut self,
element: ElementId,
label: LabelId,
) -> Result<(), DbError>
pub fn add_element_label( &mut self, element: ElementId, label: LabelId, ) -> Result<(), DbError>
Sourcepub fn add_relation_label(
&mut self,
relation: RelationId,
label: LabelId,
) -> Result<(), DbError>
pub fn add_relation_label( &mut self, relation: RelationId, label: LabelId, ) -> Result<(), DbError>
Sourcepub fn set_relation_type(
&mut self,
relation: RelationId,
relation_type: RelationTypeId,
) -> Result<(), DbError>
pub fn set_relation_type( &mut self, relation: RelationId, relation_type: RelationTypeId, ) -> Result<(), DbError>
Sourcepub fn set_property(
&mut self,
subject: PropertySubject,
key: PropertyKeyId,
value: PropertyValue,
) -> Result<(), DbError>
pub fn set_property( &mut self, subject: PropertySubject, key: PropertyKeyId, value: PropertyValue, ) -> Result<(), DbError>
Sourcepub fn remove_property(
&mut self,
subject: PropertySubject,
key: PropertyKeyId,
) -> Result<(), DbError>
pub fn remove_property( &mut self, subject: PropertySubject, key: PropertyKeyId, ) -> Result<(), DbError>
Sourcepub fn commit(self) -> Result<CommitSeq, DbError>
pub fn commit(self) -> Result<CommitSeq, DbError>
Commits this write transaction durably.
A non-dirty commit returns the parent’s commit sequence without appending
to the WAL or publishing. A dirty commit encodes the overlay’s mutation
log into one WAL frame (with the watermark op last), appends it with an
fsync (truncating back to the captured EOF on any write error so no
interior torn record survives), THEN folds the delta into a fresh
Arc<Overlay> and publishes a new Arc<Snapshot>.
After publishing, a dirty commit consults the configured
CheckpointPolicy: it releases the writer lock FIRST (so the fold can
re-acquire it), then folds when the delta-log has outgrown the base. The
committed frame is already durable, so an auto-fold failure does not lose
data; it is surfaced to the caller.
§Errors
Returns DbError when commit-sequence allocation, frame encoding, the
durable append, or a triggered auto-checkpoint fold fails.
§Performance
This method is O(change) for the dirty path — flat as the base grows.
The publish step shares the parent snapshot’s already-materialized
[crate::overlay::BaseRecords] and derived index by Arc (a commit never
folds, so the base is byte-identical within the generation), so it neither
re-decodes the base nor rebuilds the index. A triggered fold adds
O(visible state bytes) on top.