Macaw.Data.Source.Manager (macaw_data v0.21.1)
View SourceA source manager, as a value (dco-tek/macaw/macaw#108, spec/01 §6.4.3): the one owner of a
source's chunks on a host. It holds them in a Macaw.Data.Source.Push, knows every
reader's window through its Macaw.Data.Source.Subscriptions, applies every change to
its chunks, and publishes them: readers read what it published, never calling it.
It is not a process. Its owner (macaw_live) holds it in a process's state, hands it the
source's messages (receive/2), drains them each turn (drain/2), and puts what
take/1 publishes where readers read it (ETS). A reader reads its window with read/3
from a published index and a lookup of the chunks put under it.
- What it holds is what it knows:
held/1is the slot ranges whose rows it holds as the source has them. A snapshot holds the slots wholly inside its served window, everything for none; a change landing outside them is applied and its chunks dropped (Source.Push.drop/2), so nothing it publishes is partial. - A publication is everything changed since the last: the chunk index, the chunks
put at their routing versions (
{id, write_seq}, spec/01 §1.1.3), the versions they superseded, the ids dropped, and the readers whose windows those changes concern.
Errors are values: every function answers its faults, nothing raised.
Summary
Types
What one take/1 publishes (spec/01 §6.4.3).
A read the owner runs: its id, the slots it covers, their window, and whether it is a
snapshot read, its answer handed in as Source.Push.snapshot/2.
Functions
A read's answer taken (spec/01 §6.4.4): {:ok, delivery}, applied at the next drain as
a range replacement of the slots the read covered, or {:error, reason}, recorded as
{:read, id, reason}, its slots planned again. measured: is what the read cost, in
the owner's unit, observed with its rows into the cost model. A pushing source's answer
stating no position is {:read, id, :no_position}. A snapshot read's answer is handed in
as Source.Push.snapshot/2 at its stated position at the next drain, so a gap or a
resolution change it answers closes and the increments held behind it apply; an answer
of another read from before a snapshot's position is superseded by it, its slots read
again where it holds none. An id not in flight is {:error, [{[:read], :unknown}]}.
Every sliding window moved to now (Subscriptions.at/2).
A field's distinct values in a window (nil for everything) from what the manager holds
(spec/01 §6.4.5): {:ok, values}, in no set order, nil among them where a row lacks
one; {:error, {:not_held, ranges}} for the window's slots not held; {:error, [{[:field], {:unknown_field, field}}]}. A dictionary column is read by its codes.
Everything buffered applied (Source.Push.drain/2, describe its describe function): a
snapshot holds the slots wholly inside its served window, and the chunks a change made
outside what is held are dropped.
The holding under bytes where it can (spec/01 §6.4.5): the chunks no reader covers
evicted, oldest uncovered first, weighted by their re-read cost, until the holding
fits; the open chunk and every covered chunk pinned. An evicted chunk leaves the held
slots and the next publication. A budget that is no non-negative integer is
{:error, [{[:bytes], {:type, :non_neg_integer}}]}.
The slot ranges whose rows the manager holds as the source has them.
What the manager holds and what eviction cost (spec/01 §6.4.5): %{chunks, bytes, held, stale, in_flight, evicted, reread}, bytes its chunks' sizes as the BEAM sees them,
evicted the chunks evicted so far, reread the reads that read an evicted slot again.
reader's window and budget moved (Subscriptions.move/4).
A manager of the source named name, described by description, holding nothing yet.
Options: resolution: the resolution its relation is held at (nil); ref: its push
subscription's reference (a new one); now: the instant sliding windows are resolved
at; params: and viewer: what every read asks. A viewer: given to a
viewer_independent source is {[:viewer], :viewer_independent}: it is read as the
anonymous viewer. Every fault at once, by path.
A change notice applied (spec/01 §5.1, §6.4.4): exactly what it names due a read, a
range's slots, the chunks holding an identity (a whole source, everything), or
everything, each where it is held or in flight. A notice for another source changes
nothing; a term that is no Change is {:error, [{[:change], {:type, :change}}]}.
What a poll can have changed, due a read (spec/01 §6.4.4): an ordered source's open
chunk and later, the open chunk the first slot not settled by its complete_until, else
the last held; an unordered source whole; each where it is demanded and held or in
flight.
The holding, a Source.Push, for a reader of what the manager holds itself.
A reader's window from a published index alone (spec/01 §6.4.3): lookup answers the
view put under {id, write_seq}, or nil. The chunks whose slots the request's window
covers (every chunk for a window of nil or a source demanded whole) as one table,
finished for the request as a source that honors none of it, capped: true when a slot it
reads was capped and reduced_by: :source when the source reduced one, as a direct fetch
of the same answer states them (spec/01 §6.4.3): {:ok, delivery},
{:error, {:missing, id, write_seq}} for a version the lookup lacks, or finishing's
faults.
A message of the source's push subscription (spec/01 §4), buffered: {:ok, manager}, or
:ignore for one not under its reference.
A read's request (spec/01 §2.3) at now: its window, the manager's params: and
viewer:, and for a pushing source its subscription, so the answer states its position.
The slots held but due a read: a poll's, a notice's, or a failed read's.
reader subscribed to window with budget (Subscriptions.subscribe/4).
The readers' subscriptions.
Everything changed since the last take, published (spec/01 §6.4.3): {publication, manager}, the chunk index, the chunks put at their routing versions, the versions
superseded (by a put or a drop), the ids dropped, and the readers whose windows cover a
chunk put or dropped.
The faults recorded since they were last taken, as Source.Push.take_errors/1 answers
them, but for those about rows the manager does not hold, and the manager holding none.
The reads to run now (spec/01 §6.4.4): {reads, manager}, the read planner's for the
demand, avoiding what is held and fresh and what is in flight, at the measured cost; one
whole read for a source that doesn't name :window or is demanded whole; a pushing
source's read reaching the demand's top open-ended. Each is in flight until answered.
reader unsubscribed (Subscriptions.unsubscribe/2).
Types
@type publication() :: %{ index: Macaw.Data.Source.Manager.Index.t(), put: [{term(), pos_integer(), Macaw.Data.Table.view()}], superseded: [{term(), pos_integer()}], dropped: [term()], readers: [term()] }
What one take/1 publishes (spec/01 §6.4.3).
@type read() :: %{ id: pos_integer(), range: Macaw.Data.Source.Ranges.range(), window: [term()] | nil, snapshot: boolean() }
A read the owner runs: its id, the slots it covers, their window, and whether it is a
snapshot read, its answer handed in as Source.Push.snapshot/2.
@opaque t()
Functions
@spec answer( t(), pos_integer(), {:ok, Macaw.Data.Delivery.t()} | {:error, term()}, keyword() ) :: {:ok, t()} | {:error, [fault(), ...]}
A read's answer taken (spec/01 §6.4.4): {:ok, delivery}, applied at the next drain as
a range replacement of the slots the read covered, or {:error, reason}, recorded as
{:read, id, reason}, its slots planned again. measured: is what the read cost, in
the owner's unit, observed with its rows into the cost model. A pushing source's answer
stating no position is {:read, id, :no_position}. A snapshot read's answer is handed in
as Source.Push.snapshot/2 at its stated position at the next drain, so a gap or a
resolution change it answers closes and the increments held behind it apply; an answer
of another read from before a snapshot's position is superseded by it, its slots read
again where it holds none. An id not in flight is {:error, [{[:read], :unknown}]}.
Every sliding window moved to now (Subscriptions.at/2).
@spec distinct(t(), Macaw.Data.Table.name(), Macaw.Data.Source.Subscriptions.window()) :: {:ok, [term()]} | {:error, term()}
A field's distinct values in a window (nil for everything) from what the manager holds
(spec/01 §6.4.5): {:ok, values}, in no set order, nil among them where a row lacks
one; {:error, {:not_held, ranges}} for the window's slots not held; {:error, [{[:field], {:unknown_field, field}}]}. A dictionary column is read by its codes.
@spec drain(t(), Macaw.Data.Schema.Cache.describe()) :: t()
Everything buffered applied (Source.Push.drain/2, describe its describe function): a
snapshot holds the slots wholly inside its served window, and the chunks a change made
outside what is held are dropped.
@spec evict(t(), non_neg_integer()) :: {:ok, t()} | {:error, [fault(), ...]}
The holding under bytes where it can (spec/01 §6.4.5): the chunks no reader covers
evicted, oldest uncovered first, weighted by their re-read cost, until the holding
fits; the open chunk and every covered chunk pinned. An evicted chunk leaves the held
slots and the next publication. A budget that is no non-negative integer is
{:error, [{[:bytes], {:type, :non_neg_integer}}]}.
@spec held(t()) :: [Macaw.Data.Source.Ranges.range()]
The slot ranges whose rows the manager holds as the source has them.
What the manager holds and what eviction cost (spec/01 §6.4.5): %{chunks, bytes, held, stale, in_flight, evicted, reread}, bytes its chunks' sizes as the BEAM sees them,
evicted the chunks evicted so far, reread the reads that read an evicted slot again.
@spec move(t(), term(), Macaw.Data.Source.Subscriptions.window(), pos_integer() | nil) :: {:ok, t()} | {:error, [fault(), ...]}
reader's window and budget moved (Subscriptions.move/4).
@spec new(term(), Macaw.Data.Source.Description.t(), keyword()) :: {:ok, t()} | {:error, [fault(), ...]}
A manager of the source named name, described by description, holding nothing yet.
Options: resolution: the resolution its relation is held at (nil); ref: its push
subscription's reference (a new one); now: the instant sliding windows are resolved
at; params: and viewer: what every read asks. A viewer: given to a
viewer_independent source is {[:viewer], :viewer_independent}: it is read as the
anonymous viewer. Every fault at once, by path.
@spec notify(t(), Macaw.Data.Source.Change.t()) :: {:ok, t()} | {:error, [fault(), ...]}
A change notice applied (spec/01 §5.1, §6.4.4): exactly what it names due a read, a
range's slots, the chunks holding an identity (a whole source, everything), or
everything, each where it is held or in flight. A notice for another source changes
nothing; a term that is no Change is {:error, [{[:change], {:type, :change}}]}.
What a poll can have changed, due a read (spec/01 §6.4.4): an ordered source's open
chunk and later, the open chunk the first slot not settled by its complete_until, else
the last held; an unordered source whole; each where it is demanded and held or in
flight.
@spec push(t()) :: Macaw.Data.Source.Push.t()
The holding, a Source.Push, for a reader of what the manager holds itself.
@spec read( Macaw.Data.Source.Manager.Index.t(), ({term(), pos_integer()} -> Macaw.Data.Table.view() | nil), Macaw.Data.Source.Request.t() ) :: {:ok, Macaw.Data.Delivery.t()} | {:error, term()}
A reader's window from a published index alone (spec/01 §6.4.3): lookup answers the
view put under {id, write_seq}, or nil. The chunks whose slots the request's window
covers (every chunk for a window of nil or a source demanded whole) as one table,
finished for the request as a source that honors none of it, capped: true when a slot it
reads was capped and reduced_by: :source when the source reduced one, as a direct fetch
of the same answer states them (spec/01 §6.4.3): {:ok, delivery},
{:error, {:missing, id, write_seq}} for a version the lookup lacks, or finishing's
faults.
A message of the source's push subscription (spec/01 §4), buffered: {:ok, manager}, or
:ignore for one not under its reference.
@spec request(t(), read(), DateTime.t()) :: {:ok, Macaw.Data.Source.Request.t()} | {:error, [fault(), ...]}
A read's request (spec/01 §2.3) at now: its window, the manager's params: and
viewer:, and for a pushing source its subscription, so the answer states its position.
@spec stale(t()) :: [Macaw.Data.Source.Ranges.range()]
The slots held but due a read: a poll's, a notice's, or a failed read's.
@spec subscribe( t(), term(), Macaw.Data.Source.Subscriptions.window(), pos_integer() | nil ) :: {:ok, t()} | {:error, [fault(), ...]}
reader subscribed to window with budget (Subscriptions.subscribe/4).
@spec subscriptions(t()) :: Macaw.Data.Source.Subscriptions.t()
The readers' subscriptions.
@spec take(t()) :: {publication(), t()}
Everything changed since the last take, published (spec/01 §6.4.3): {publication, manager}, the chunk index, the chunks put at their routing versions, the versions
superseded (by a put or a drop), the ids dropped, and the readers whose windows cover a
chunk put or dropped.
The faults recorded since they were last taken, as Source.Push.take_errors/1 answers
them, but for those about rows the manager does not hold, and the manager holding none.
The reads to run now (spec/01 §6.4.4): {reads, manager}, the read planner's for the
demand, avoiding what is held and fresh and what is in flight, at the measured cost; one
whole read for a source that doesn't name :window or is demanded whole; a pushing
source's read reaching the demand's top open-ended. Each is in flight until answered.
A pushing source whose holding asks a snapshot (Source.Push.refetch/1: a gap, or an
increment at another resolution) is answered one read marked snapshot: true, over
everything demanded or held from its first slot on, and no other read, once: not again
while it is out, and again only once it has landed or failed and the holding still
asks one.
reader unsubscribed (Subscriptions.unsubscribe/2).