Change and replay
This guide changes a served statement, a hook's output, a table's columns, a queue or a view, and upgrades featuremeshd, without losing values or queued work. To read a topic again, backfill a hook or erase an event, see Replay, backfill or erase .
How a change loads
A CREATE, CREATE OR REPLACE or DROP changes the registry, not what featuremeshd runs. Each featuremeshd loads the definitions that exist at its own RECOMPILE SERVING, or at its next registry sync.
- The sync runs every
serving.sources.poll_interval, 60 seconds by default ( Configure featuremeshd ). A definition created after a sync waits for the next one. RECOMPILE SERVINGruns a sync at once, on the pod that receives it. Send it to each pod ( Reach a pod ). It answers with the status of every definition ( SHOW SERVING STATUS ).- Replicas switch one by one. Until every replica has loaded the change, the old and new definitions run side by side. A changed hook resumes from its group's committed offsets ( Consumer groups ).
- A failed sync loads nothing. When the
REGISTRY_SYNCrow ofSHOW SERVING STATUSisERROR, no change reaches that pod, and what it loaded keeps running.
So each step below ends by checking every replica.
Change a formula, same fields
A change that keeps the statement's output type, such as a new formula, replaces the feature in place:
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.HOOK_REF AS
PERSIST
pay_row := ROW(
event_time AS event_time,
payment_id AS payment_id,
ROUND(amount, 2) AS amount
)
;| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.HOOK_REF.PAY_ROW | REPLACED | Feature was replaced |
CREATE OR REPLACEthe feature, thenRECOMPILE SERVING( Recompile before serving ).- Check that every replica shows the new
datakeyinSHOW SERVING STATUS. Thedatakeyis the definition's name and a hash of its compiled version, such asFM.SHOP.ON_PAYMENT@78667480d51269c7.
What a hook or view writes next carries the new datakey. Values already stored are not rewritten, and keys that no record writes again keep their old datakey until they expire. A reader that must not mix the two filters on datakey. A served statement keeps its id, so callers do not change.
Change the fields of a hook's output
A field added, renamed or retyped in the statement's ROW changes its type, and the replace is refused:
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.HOOK_REF AS
PERSIST
pay_row := ROW(
event_time AS event_time,
payment_id AS payment_id,
amount AS amount,
merchant_id AS merchant_id
)
;Choose between a short stop and a side-by-side switch.
With a short stop
- Drop the features that change, and create them again under the same names. Between the drop and the create, the statement is not served.
RECOMPILE SERVING. The hook resumes from its committed offsets.
Old values keep the old layout. A reader declared for the new layout reads an added or renamed field of an old Redis value as NULL (a renamed field's old name is ignored). A retyped field fails to decode on every old value until it is written again.
Without downtime
- Create the new statement, its sink (a new Redis key prefix or a new table) and its hook, under new names. Give the hook a
STARTfar enough back to fill the sink ( Start a new hook ). - Wait until the new hook's
lagis near zero on every partition. - Move the readers to the new sink. Serving keeps the old statement until they have moved.
- Drop the old hook, statement and sink.
Change a table's columns
Each replica writes with the definition it loaded until its next sync, so the table takes both layouts for a while:
- Add the new column, nullable.
- Change the definition, and
RECOMPILE SERVING. - Check that every hooks replica shows the new
datakeyinSHOW SERVING STATUS. - Only then drop or rename the old column.
Rows that no record writes again keep NULL in the new column.
Move a queue
A recompile that names another QUEUE, or changes the hook's USING text or its reference's types, moves the queue and drops its entries ( Queues and drains ). To change one without losing work, empty it first:
- Stop what queues into it. Drop the event hook upstream (its group keeps its offsets), and
RECOMPILE SERVINGon every replica. In a chain, empty every queue upstream first, in order, since each drain queues the next. - Wait for the queue to empty. Its
depthmust be zero at alast_drainlater than step 1, on the replica that holds its lease. Zero due entries is not an empty queue, since entries due later count indepth, not indue( A hook's details ). - Change the hook, create the upstream hook again under its own name, and
RECOMPILE SERVING. It resumes from its group's offsets.
Entries due too far ahead to wait for are dropped by the change. Rebuild them by replaying the upstream topic from before the oldest event that queued them, with EXPIRE raised ( Backfill a hook that feeds scheduled hooks ).
Check: entries_dropped did not move.
Change a view
A view is compiled when it is created. After changing a feature it reads, compile it again and load it ( Lifecycle ): RECOMPILE MATERIALIZED VIEW, then RECOMPILE SERVING. featuremeshd runs its latest slot again under the new datakey.
To change its columns:
- Add the new columns to the table, nullable.
CREATE OR REPLACEthe view, thenRECOMPILE SERVING.- Check that every hooks replica shows the new
datakeyinSHOW SERVING STATUS, since a replica still on the old definition can run a slot with it. Then check that the watermark'sdatakeyis the new one. - Switch the readers, and drop the old columns.
To roll back, recompile the previous definition. Its next run publishes it.
Upgrade featuremeshd
Replicas of two featuremeshd versions can share a hook during a rolling upgrade. The queue's table and keys carry no version and keep their columns. A view's datakey holds no engine version, so an upgrade runs no view again and keeps the counters. A change of the definition, or of how the registry compiles it, does run it again. Read the release notes first, since a version that changes a queue's or a sink's layout says so there.
- Roll the hooks pods one at a time. Each stops within
shutdown_grace, finishing its batch and releasing its leases ( Shutdown ). - Check that each new pod's hooks are
RUNNING, and itsREGISTRY_SYNCrowOK, before rolling the next.
Replay, backfill or erase
A change of definition does not rewrite what a hook already wrote. These guides rewrite or remove it:
| Task | Guide |
|---|---|
| Start a hook on history, backfill a hook that feeds scheduled hooks, replay a topic after a bug fix, seed rows yourself | Start, backfill and replay |
| Erase one event from an index and from the values computed from it, for an erasure request | Remove an event |
Common failures
- Old and new values mixed in a sink: readers did not filter on
datakeywhile replicas switched. Filter, or switch readers only once every replica shows the newdatakey. - Buckets missing after a change: the change moved a queue and dropped its entries.
entries_droppedcounts them, andSHOW SERVING WRITESsamples five asDROPPEDrows. - A change that never arrives: the
REGISTRY_SYNCrow isERROR, so noCREATE,DROPorRECOMPILE SERVINGreaches that replica ( Monitor and recover ).
Related
- Port a batch feature : roll a changed rule out to part of the traffic first.
- Sinks and reading back :
datakeyand the write layout.