Delivery and failures

Hooks deliver at least once: this page says which write lands, what a call sees, and what each failure does to a record, an entry and a value.

At least once

  • An event hook commits late. It commits a batch's offsets only after every sink of the batch is written, every queue entry it schedules is stored, and every hook ON its statement is done. A crash before the commit runs the batch's records again.
  • A drain deletes late. The hooks ON a drained statement run before its entries are deleted. When one fails, or featuremeshd stops before the delete, the entries stay and the drain runs again, its chain included: its sinks are written again and its references queued again.
  • A retry writes whole values. A retried record reads its sources again, so the value it writes can differ from the first attempt's. A value is exact for the record and for the reads at its compute_time.
  • Batches. featuremeshd computes records in batches, one per hook on each featuremeshd, across every partition it reads. A batch's size is a setting of featuremeshd ( Configure featuremeshd ).
  • A stop finishes the batch. A featuremeshd that is stopped finishes and commits the batch it runs, within a grace period. What it cannot finish runs again elsewhere, as after a crash ( Shutdown ).

Which write lands

A latest value lands only over an older or equal request_time: this is the fence. Out-of-order records therefore never bring back an older value.

CaseWhat lands
a record older than the stored valuenothing
a record as new as the stored valuethe record's value: the last written wins
several calls of one batch on one keythe newest of them, by request_time, then the higher offset within a partition, then the later in the batch across partitions. The writes counter counts those, so it is often below calls
a whole produce batch under LogAppendTimeequal times, so the last written wins
a key whose value or tombstone expired (RETENTION) or was deletedany record, an older one included: the fence lasts as long as the stored row
  • Time, not offsets. The fence orders by request_time, so a topic need not be partitioned by the sink's key.
  • Not the definition. The datakey takes no part in the fence. During a deployment, the old and the new definition both write, and the newest request_time wins.
  • No fence on an index. An append member with the same UNIQUE ON identity is replaced whatever its time.
  • A record without a Kafka timestamp takes the consumer's clock as its time. A replay gives it a new, later request_time, which wins over the values stored since.

What a call sees

  • One trigger row is one call: one record, or one queued reference. Calls run in batches, but each answers as if it ran alone. Two calls of one batch do not see each other's writes.
  • Writes are visible after the batch. A batch's sink writes land before the next batch is read, so a later record sees them.
  • A window read in the indexing statement misses its batch. A payment is in the index only once its hook wrote it, so a window read in the same statement misses that payment and its batch-mates. Read the window in a hook ON that statement, or at serving.
  • A hook ON a statement runs after the whole batch is written. It sees every sink write of the triggering batch, its batch-mates' included, those after its own trigger in the topic too. Records of later batches are not written yet. A decision exact for one event filters the index on that event's own time.
  • Hooks on one trigger run in no defined order. A statement that needs another hook's sink is ON that hook's statement, or reads the sink at request time, in serving.
  • Only complete runs fire. A trigger call that failed or came back PARTIAL fires no hook.
  • A guarded read never stores its fallback. In serving, a guarded read that does not answer gives its fallback. In a hook, the call is retried, then skipped ( Failures in a batch ), so a stored value never hides an outage.
  • A raise costs more in a hook. An operation the registry flags with PREPARED-STATEMENT-UNHANDLED-RUNTIME-ERROR also removes the key's latest value when it raises in a hook ( Tombstones ).
  • No call, no log. A record that does not decode, or whose USING or WHERE raises, makes no call: no logger sees it.

Failures in a batch

What failedThe batchThe valueOffset committed
a record does not decode (HOOK-RECORD-DECODE)goes onnothing written, nothing removedyes
a call raises: a division by zero, a failed cast, an error the statement raisesgoes onthe key's latest value becomes a tombstone , unless a newer one is storedyes
a source answers with an error for a key: a query it refuses, a value it cannot return, a key of the wrong typegoes on: a data error at the first attemptas a call that raisesyes
a source times out, is unreachable, or answers about its own state; or a call comes back PARTIALcomputed again, whole. Once it has failed for poison_after, if some calls succeed, the ones still failing become data errorsnothing written meanwhileno, until it is written
a sink or a queue does not answerwaits; the hook is STALLEDthe values computed are kept; only the sinks not yet written are retriedno, until it succeeds
  • Data errors are skipped. Each is counted (data_errors) and kept as an ERROR among the last recent_writes of SHOW SERVING WRITES, with its code, message, partition and offset. featuremeshd writes nothing to its own log for a data error. There are no dead letters ( Limits ).
  • Retries are unbounded while every call fails. When every call of a batch fails on an unavailable source or comes back PARTIAL, the batch is retried, with a growing backoff that featuremeshd's configuration bounds ( retry_backoff ). No record is skipped because a store is down.
  • poison_after breaks a partial failure. When some calls succeed and others keep failing, the failing ones become data errors once the batch has failed for poison_after, a featuremeshd setting counted from the batch's first failed attempt ( poison_after ): counted, skipped, their latest keys removed.
  • One record holds every partition. A batch whose every call fails keeps retrying, even when it is one record whose key always fails, and every partition of that replica waits. SHOW SERVING STATUS shows the hook STALLED, its retries climbing and the source's error in its message ( Monitor and recover ).

Store-state answers

A store answering about its own state, such as a failover, is unavailable, not a data error. These answers are retried as a timeout is, and never counted against the key:

StoreAnswers
RedisLOADING, READONLY, CLUSTERDOWN, TRYAGAIN, MASTERDOWN, MOVED, ASK
PostgreSQLSQLSTATE classes 08 (connection), 53 (insufficient resources, too many connections included), 57 (operator intervention: a server starting or stopping, a cancelled statement); 40001, 40P01 (serialization failure, deadlock); 55P03 (lock timeout)
MySQL, MariaDBclasses 08, 53, 57; 40001; codes 1040 (too many connections), 1053 (server shutting down), 1205 (lock wait timeout), 1290 and 1836 (read-only server)

A NULL field

A NULL field, missing or null, goes on as NULL. What it does depends on where it lands, and the record's offset is committed in every case:

A NULL inWhat happens
WHEREthe record does not fire, and is counted in no counter of its own
a USING value of an event hookthe call runs with a NULL input
a sink's KEY column or Redis KEY, UNIQUE ON, INDEXED ONHOOK-SINK-ROW, a data error: the call writes none of its sinks, removes nothing, and fires no hook ON its statement
ATHOOK-AT-NULL, a data error: nothing is queued
a scheduled hook's reference (USING)HOOK-USING-NULL, a data error: nothing is queued. A top-level NULL only: a ROW whose field is NULL is queued as it is

To skip such records rather than count them as errors, test the fields in WHERE: WHERE p[payment_id] IS NOT NULL AND p[amount] > 0.

Tombstones

A call that raises replaces its key's latest value with a tombstone, unless a newer value is stored. Serving then reads a miss rather than a value the record should have changed.

  • What it holds. The layout's fields, with request_time set to the record's and the rest NULL: no value, no compute_time, no datakey. A table keeps the row with NULL value columns. The printed reader returns NULL when compute_time is NULL ( Reading back ).
  • It fences. A record older than the failed one, arriving later, writes nothing. One at the same time or newer writes as usual.
  • Which key. The key is the sink's own, computed from the call's inputs: a table sink whose key columns are all inputs, or a Redis KEY over the inputs. When the key needs the output, or an input is NULL, nothing is removed.
  • Never an index member. A raising call never removes a member of an event index.
  • Counted. Each removal is counted (deletions) and kept in SHOW SERVING WRITES as a DELETE, with the tombstone's request_time. A definition that starts raising on every record removes every key its records reach ( Monitor and recover ).
  • How long it stays. Until the key is written again, its RETENTION passes, or you delete it. Without RETENTION, tombstones stay, one per removed key.

Failures in a drain

A drain reads the entries due at T, deletes the expired ones, computes the others as one batch at REQUEST_TIME() = T, writes the sinks, then deletes the entries it ran, each by the token it read. A failed batch is computed again whole, and its entries wait.

In the drainThe entryThe sinksHooks ON its statement
older than EXPIRE (T > due + EXPIRE)deleted unrun, counted entries_expirednothingnot fired
its call raisesdeleted; a data errorits latest keys removed where they derive from the inputsnot fired for it
its reference does not fit the statement (HOOK-QUEUE-REFERENCE), or a NULL sink key, UNIQUE ON or INDEXED ON (HOOK-SINK-ROW)deleted; a data errornothing written, nothing removednot fired for it
a source times out or is unreachable, or a call comes back PARTIALevery entry of the batch stays; the drain is retried with backoff, from the lease, at a new Tnothing writtennot fired
… once the drain has failed for poison_after, while some calls succeedthe failing ones deleted as data errors, the others as usualas a call that raisesfor the calls that succeeded
a sink failsevery entry stays; the retry computes the batch again at a new T and writes every sink againthe sinks written before the failure keep what they took; the fence keeps the newer valuenot fired
a hook ON its statement fails: a sink, a queue, a sourceevery entry stays; the retry runs the drain again, its chained hooks includedsinks outside the queue's database are written again; table sinks in the queue's database are not written yetfired again on the retry
the lease is lost before the deleteevery entry stays, for the next holdertable sinks in the queue's database not written; the others may bemay have fired; fired again by the next holder
queued again while the drain runs itthe new entry stays, and fires againas usualas usual
  • Entries keep expiring while a drain retries. Each attempt has a new T, so an outage longer than EXPIRE drops the entries it held up.
  • A chain is at least once. A drain's references queued again are folded by the queue, which keeps one entry per reference. An event hook's batch is the same: its offsets are committed once its chained hooks are done.
  • What the queue's transaction covers. Table sinks in the same database as the queue, named by the same URL, are written in the drain's transaction with the queue's updates. Redis sinks and tables in another database are written before that transaction, and the entries are removed after. A crash in between computes the bucket again whole and rewrites it.
  • Chained hooks see calls, not those tables. The hooks ON a drained statement see its calls. They do not see its table sinks in the queue's database, which land with the delete.

Leases

A queue is drained by one featuremeshd at a time, under a lease. A drain that loses its lease writes nothing more to the queue: its entries stay, and the next holder runs them again, so sinks outside the queue's database may be written twice, and the fence keeps the newer value. How leases are taken, renewed and released is in Leases . A view's run has a lease of its own ( Runs ).

Related