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
ONits statement is done. A crash before the commit runs the batch's records again. - A drain deletes late. The hooks
ONa 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.
| Case | What lands |
|---|---|
| a record older than the stored value | nothing |
| a record as new as the stored value | the record's value: the last written wins |
| several calls of one batch on one key | the 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 LogAppendTime | equal times, so the last written wins |
a key whose value or tombstone expired (RETENTION) or was deleted | any 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
datakeytakes no part in the fence. During a deployment, the old and the new definition both write, and the newestrequest_timewins. - No fence on an index. An
appendmember with the sameUNIQUE ONidentity 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
ONthat statement, or at serving. - A hook
ONa 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
ONthat hook's statement, or reads the sink at request time, in serving. - Only complete runs fire. A trigger call that failed or came back
PARTIALfires 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-ERRORalso removes the key'slatestvalue when it raises in a hook ( Tombstones ). - No call, no log. A record that does not decode, or whose
USINGorWHEREraises, makes no call: no logger sees it.
Failures in a batch
| What failed | The batch | The value | Offset committed |
|---|---|---|---|
a record does not decode (HOOK-RECORD-DECODE) | goes on | nothing written, nothing removed | yes |
| a call raises: a division by zero, a failed cast, an error the statement raises | goes on | the key's latest value becomes a tombstone , unless a newer one is stored | yes |
| a source answers with an error for a key: a query it refuses, a value it cannot return, a key of the wrong type | goes on: a data error at the first attempt | as a call that raises | yes |
a source times out, is unreachable, or answers about its own state; or a call comes back PARTIAL | computed again, whole. Once it has failed for poison_after, if some calls succeed, the ones still failing become data errors | nothing written meanwhile | no, until it is written |
| a sink or a queue does not answer | waits; the hook is STALLED | the values computed are kept; only the sinks not yet written are retried | no, until it succeeds |
- Data errors are skipped. Each is counted (
data_errors) and kept as anERRORamong the lastrecent_writesofSHOW 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_afterbreaks a partial failure. When some calls succeed and others keep failing, the failing ones become data errors once the batch has failed forpoison_after, a featuremeshd setting counted from the batch's first failed attempt (poison_after): counted, skipped, theirlatestkeys 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 STATUSshows the hookSTALLED, itsretriesclimbing 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:
| Store | Answers |
|---|---|
| Redis | LOADING, READONLY, CLUSTERDOWN, TRYAGAIN, MASTERDOWN, MOVED, ASK |
| PostgreSQL | SQLSTATE 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, MariaDB | classes 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 in | What happens |
|---|---|
WHERE | the record does not fire, and is counted in no counter of its own |
a USING value of an event hook | the call runs with a NULL input |
a sink's KEY column or Redis KEY, UNIQUE ON, INDEXED ON | HOOK-SINK-ROW, a data error: the call writes none of its sinks, removes nothing, and fires no hook ON its statement |
AT | HOOK-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_timeset to the record's and the restNULL: no value, nocompute_time, nodatakey. A table keeps the row withNULLvalue columns. The printed reader returnsNULLwhencompute_timeisNULL( 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
KEYover the inputs. When the key needs the output, or an input isNULL, 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 inSHOW SERVING WRITESas aDELETE, with the tombstone'srequest_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
RETENTIONpasses, or you delete it. WithoutRETENTION, 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 drain | The entry | The sinks | Hooks ON its statement |
|---|---|---|---|
older than EXPIRE (T > due + EXPIRE) | deleted unrun, counted entries_expired | nothing | not fired |
| its call raises | deleted; a data error | its latest keys removed where they derive from the inputs | not 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 error | nothing written, nothing removed | not fired for it |
a source times out or is unreachable, or a call comes back PARTIAL | every entry of the batch stays; the drain is retried with backoff, from the lease, at a new T | nothing written | not fired |
… once the drain has failed for poison_after, while some calls succeed | the failing ones deleted as data errors, the others as usual | as a call that raises | for the calls that succeeded |
| a sink fails | every entry stays; the retry computes the batch again at a new T and writes every sink again | the sinks written before the failure keep what they took; the fence keeps the newer value | not fired |
a hook ON its statement fails: a sink, a queue, a source | every entry stays; the retry runs the drain again, its chained hooks included | sinks outside the queue's database are written again; table sinks in the queue's database are not written yet | fired again on the retry |
| the lease is lost before the delete | every entry stays, for the next holder | table sinks in the queue's database not written; the others may be | may have fired; fired again by the next holder |
| queued again while the drain runs it | the new entry stays, and fires again | as usual | as usual |
- Entries keep expiring while a drain retries. Each attempt has a new
T, so an outage longer thanEXPIREdrops 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
ONa 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
- Hooks : queues, drains and
EXPIRE. - Sinks and reading back : what a reader sees of a tombstone.
- Status and writes : the counters named here.
- Configure featuremeshd : leases, shutdown, and the settings named here.
- Limits : no exactly once, no dead letters.