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 SERVING runs 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_SYNC row of SHOW SERVING STATUS is ERROR, 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:

FeatureQL
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
    )
;
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.HOOK_REF.PAY_ROWREPLACEDFeature was replaced

  1. CREATE OR REPLACE the feature, then RECOMPILE SERVING ( Recompile before serving ).
  2. Check that every replica shows the new datakey in SHOW SERVING STATUS. The datakey is the definition's name and a hash of its compiled version, such as FM.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:

FeatureQL
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
    )
;
Result
ERROR UE/REPLACE-FEATURE-TYPE-MISMATCH

Choose between a short stop and a side-by-side switch.

With a short stop

  1. Drop the features that change, and create them again under the same names. Between the drop and the create, the statement is not served.
  2. 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

  1. 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 START far enough back to fill the sink ( Start a new hook ).
  2. Wait until the new hook's lag is near zero on every partition.
  3. Move the readers to the new sink. Serving keeps the old statement until they have moved.
  4. 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:

  1. Add the new column, nullable.
  2. Change the definition, and RECOMPILE SERVING.
  3. Check that every hooks replica shows the new datakey in SHOW SERVING STATUS.
  4. 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:

  1. Stop what queues into it. Drop the event hook upstream (its group keeps its offsets), and RECOMPILE SERVING on every replica. In a chain, empty every queue upstream first, in order, since each drain queues the next.
  2. Wait for the queue to empty. Its depth must be zero at a last_drain later than step 1, on the replica that holds its lease. Zero due entries is not an empty queue, since entries due later count in depth, not in due ( A hook's details ).
  3. 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:

  1. Add the new columns to the table, nullable.
  2. CREATE OR REPLACE the view, then RECOMPILE SERVING.
  3. Check that every hooks replica shows the new datakey in SHOW SERVING STATUS, since a replica still on the old definition can run a slot with it. Then check that the watermark's datakey is the new one.
  4. 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.

  1. Roll the hooks pods one at a time. Each stops within shutdown_grace, finishing its batch and releasing its leases ( Shutdown ).
  2. Check that each new pod's hooks are RUNNING, and its REGISTRY_SYNC row OK, 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:

TaskGuide
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 datakey while replicas switched. Filter, or switch readers only once every replica shows the new datakey.
  • Buckets missing after a change: the change moved a queue and dropped its entries. entries_dropped counts them, and SHOW SERVING WRITES samples five as DROPPED rows.
  • A change that never arrives: the REGISTRY_SYNC row is ERROR, so no CREATE, DROP or RECOMPILE SERVING reaches that replica ( Monitor and recover ).

Related