ReactiveDag.CoordinationWriter behaviour (reactive_dag v0.16.0)

Copy Markdown View Source

The seam for WRITING a cell's coordination tuples — the third seam, alongside RecomputeStrategy (how a cell recomputes) and KeyRule (how a change propagates). An op, mid-recompute, records which of its keys are present / gone; this behaviour is where those writes land.

Why a seam and not just ReactiveDag.Tuple: the spine (cell_id, key, status, freshness) is shared, but each host's coordination write also touches its EXTENSION columns in the SAME atomic upsert — cascade stamps source_ref / last_seen_at and CLEARS tombstoned_at (retain-if-vanish revival); the portal stamps strength. That extension write is host policy, so the write can't be a pure spine call. The library provides the INTERFACE ops use (ReactiveDag.Op.put/tombstone/delete) and routes it here; the host supplies the writer via config :reactive_dag, coordination_writer: MyApp.Writer.

The default (ReactiveDag.Tuple.Writer) is spine-only — fine for a host with no extension columns; hosts that have them (cascade) configure their own.

Summary

Callbacks

Hard-delete keys of cell_id.

Mark key of cell_id present. opts may carry host fields (source_ref, strength, stale_after). May return :ok, or a boolean CHANGED signal (true iff the row's verdict actually changed) — a writer that upserts with a WHERE … IS DISTINCT FROM guard can report the flip, which an op uses as its changed-key signal. ReactiveDag.Op.put returns whatever the writer returns.

Tombstone keys of cell_id — vanished-but-retained (a host with a retain policy).

Functions

The configured writer module (default: the spine-only ReactiveDag.Tuple.Writer).

Types

key()

@type key() :: String.t()

Callbacks

delete(cell_id, keys)

@callback delete(cell_id :: key(), keys :: [key()]) :: :ok

Hard-delete keys of cell_id.

put(cell_id, key, opts)

@callback put(cell_id :: key(), key :: key(), opts :: keyword()) :: :ok | boolean()

Mark key of cell_id present. opts may carry host fields (source_ref, strength, stale_after). May return :ok, or a boolean CHANGED signal (true iff the row's verdict actually changed) — a writer that upserts with a WHERE … IS DISTINCT FROM guard can report the flip, which an op uses as its changed-key signal. ReactiveDag.Op.put returns whatever the writer returns.

tombstone(cell_id, keys)

(optional)
@callback tombstone(cell_id :: key(), keys :: [key()]) :: :ok

Tombstone keys of cell_id — vanished-but-retained (a host with a retain policy).

Functions

writer()

@spec writer() :: module()

The configured writer module (default: the spine-only ReactiveDag.Tuple.Writer).