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>
impl<'s> Writer<'s>
Sourcepub fn upsert_node(&mut self, doc: &DocRecord<'_>) -> Result<()>
pub fn upsert_node(&mut self, doc: &DocRecord<'_>) -> Result<()>
Stage a node create/replace.
Sourcepub fn set_segments(
&mut self,
key: UrlKey,
segs: &[SegmentRecord<'_>],
) -> Result<()>
pub fn set_segments( &mut self, key: UrlKey, segs: &[SegmentRecord<'_>], ) -> Result<()>
Stage a whole-set segment replacement for key.
Sourcepub fn set_edges(&mut self, key: UrlKey, edges: &[(UrlKey, EdgeType, u16)])
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.
Sourcepub fn set_edges_with_flags(
&mut self,
key: UrlKey,
edges: &[(UrlKey, EdgeType, u16, u8)],
)
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).
Sourcepub fn set_attrs(&mut self, key: UrlKey, attrs: &[(u8, &str)]) -> Result<()>
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.
Sourcepub fn set_named_attrs(
&mut self,
key: UrlKey,
attrs: &[(&str, &str)],
) -> Result<()>
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.
Sourcepub fn touch(&mut self, key: UrlKey, t: Touch<'_>) -> Result<bool>
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.
Sourcepub fn set_pinned(&mut self, key: UrlKey, pinned: bool) -> Result<bool>
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.
Sourcepub fn discard(&mut self)
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.
Sourcepub fn commit(&mut self) -> Result<u64>
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.