Skip to main content

Writer

Struct Writer 

Source
pub struct Writer<'s> { /* private fields */ }
Expand description

A handle’s writer; holds the handle’s writer mutex for its lifetime (so threads sharing one handle take turns). Stage mutations, then Writer::commit to make them durable and visible. Writers on other handles stage concurrently; commits take turns on the commit lock.

Implementations§

Source§

impl<'s> Writer<'s>

Source

pub fn upsert_node(&mut self, doc: &DocRecord<'_>) -> Result<()>

Stage a node create/replace.

Source

pub fn set_segments( &mut self, key: UrlKey, segs: &[SegmentRecord<'_>], ) -> Result<()>

Stage a whole-set segment replacement for key.

Source

pub fn set_edges(&mut self, key: UrlKey, edges: &[(UrlKey, EdgeType, u16)])

Stage a whole-set outbound-edge replacement for key. Edges are deduplicated by destination (first occurrence wins — document order is salience order) and stored sorted by destination key.

Source

pub fn set_edges_with_flags( &mut self, key: UrlKey, edges: &[(UrlKey, EdgeType, u16, u8)], )

Writer::set_edges with per-edge flags; only caller-settable ones are kept (eflags::EXACT: an unchanged copy along Derives).

Source

pub fn set_attrs(&mut self, key: UrlKey, attrs: &[(u8, &str)]) -> Result<()>

Stage a whole-set replacement of key’s attributes: small keyed values beside the node (a column’s type, a table’s producing SQL, a description’s provenance). Keys are the caller’s; a later key wins over an earlier duplicate. Values longer than MAX_ATTR_LEN, more than MAX_ATTRS keys, or a set whose encoding would not fit one log frame (MAX_ATTR_BYTES in total) are refused.

Source

pub fn set_named_attrs( &mut self, key: UrlKey, attrs: &[(&str, &str)], ) -> Result<()>

Writer::set_attrs with string names: a whole-set replacement of key’s attributes as name → value. Each record is stored as name NUL value under keys 0..n in name order, so crate::Snapshot::named_attrs reads names and values back as borrowed slices and any producer (Rust or a binding) agrees on the encoding. A later duplicate name wins. Names must be non-empty, at most MAX_ATTR_NAME bytes and free of NUL; each name NUL value must fit MAX_ATTR_LEN, and the whole set MAX_ATTR_BYTES.

Source

pub fn touch(&mut self, key: UrlKey, t: Touch<'_>) -> Result<bool>

Record a revalidation outcome. Freshness policy (interval growth/cut, counters) is computed here from the node’s current state and the store’s crate::TtlConfig, and the resulting op carries the node’s full effective state so replay never re-derives policy.

Returns false, staging nothing, when key is not a committed node. That is the important word: the state is read through a snapshot, which sees committed ops only, so a node staged earlier in this same batch is not yet visible. Commit the upsert before touching it — the link-r bridge already does.

The same rule means two touches of one key inside a single uncommitted batch do not accumulate: both are computed from the pre-batch state and the second wins under last-wins overlay folding. Commit between observations of the same document. Pinned by touch_requires_a_committed_node in tests/regression.rs.

Source

pub fn set_pinned(&mut self, key: UrlKey, pinned: bool) -> Result<bool>

Stage a pin/unpin. Returns false (staging nothing) when key is neither committed nor upserted earlier in this same batch — a pin on a document that does not exist must not lie in wait for a future upsert.

Source

pub fn remove(&mut self, key: UrlKey) -> Result<()>

Stage a hard delete.

Source

pub fn discard(&mut self)

Drop every op staged on this handle and not yet committed. Staged ops otherwise outlive a failed commit (a retry commits them) and a dropped writer (the handle’s next commit includes them); a transaction refused for good — larger than wal::MAX_RECORD — is discarded with this, then staged again in parts.

Source

pub fn commit(&mut self) -> Result<u64>

Make staged ops durable and visible: take the commit lock (waiting up to crate::Config::lock_wait, else Error::Locked with the ops still staged), catch up with other writers, seal the staged ops into one record, append it to the WAL in one write, fsync per the configured Durability, publish it to the overlay, auto-compact past thresholds, unlock. Returns the last committed sequence number.

Err means nothing was appended and nothing published, and the ops stay staged: a transaction larger than wal::MAX_RECORD is a typed Error::Format before anything is written. Ok means the whole transaction is durable (per policy) and visible at once. An inline compaction that cannot run leaves Store::compaction_due set instead of failing the commit.

Trait Implementations§

Source§

impl<'s> Debug for Writer<'s>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s> !Freeze for Writer<'s>

§

impl<'s> !RefUnwindSafe for Writer<'s>

§

impl<'s> !Send for Writer<'s>

§

impl<'s> !Sync for Writer<'s>

§

impl<'s> Unpin for Writer<'s>

§

impl<'s> UnsafeUnpin for Writer<'s>

§

impl<'s> UnwindSafe for Writer<'s>

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