Skip to content

Trellis 0.4.0

Latest

Choose a tag to compare

@mmmries mmmries released this 02 Dec 05:50
f1c4f2e

Trellis 0.4.0

0.4.0 is the fourth minor release. The main changes:

  • The instance belongs to the release that last ran migrate. migrate
    claims at once. Old processes stand by within 5 seconds and refuse changes
    with T0220.
    A rollback by an older migrate sticks. New rollback --to <release>
    leaves a release whose catalog floor an older one can't read, and
    uninstall removes Trellis completely (#2299,
    ADR-0023,
    ADR-0024,
    ADR-0025).
  • WHERE on transforms. Every key space takes a total WHERE: plain 1-1,
    plain aggregates, 1-1 JOIN and star transforms, and join aggregates (one
    filter per side). It is applied as rows are applied (#1991).
  • IN, NOT IN, BETWEEN and NOT BETWEEN in calculated fields and
    WHERE (#2172). An enum column = a string literal now defines (#2037).
  • SUM/AVG over real, double precision and interval, as exact
    sums that don't depend on row order (#1119).
  • char(n) follows Postgres's blank-padding rules beside a string literal
    and as a GROUP BY key (#2000, #2053).
  • Every error has a stable code (T0042: …) in Rust, Ruby and Elixir.
    docs/errors.md
    documents each code once, with its remedy (#2011).
  • Elixir parity with Ruby: an enabled switch, a read-only target guard,
    refresh_target, metrics plugs, and migrate from ecto.migrate and
    releases (#1986, #2306).
  • Capture never fails an application write when its re-read of a source
    is refused. The readers halt with a reason, and RESUME rebuilds them
    (#2154, #2227).

The upgrade raises the catalog floor to 0.4.0. Once 0.4.0 claims a
database, 0.3.x stands by. Rolling back is rollback --to 0.3.1, which empties
every target for 0.3.x to rebuild (Upgrading).

0.4.0 includes the fix in 0.3.1. 151 pull requests merged since v0.3.0
(changelog).

Validation beyond CI: 201 logged runs, 134.6 hours and about 2.40 billion
source rows. That covers generative sweeps, a 15.5-hour generative soak,
chaos and load soaks, benchmarks, repro loops, and the
upgrade battery from v0.3.0 and v0.3.1. Six series of takeover and rollback
runs on release builds found no write by a non-owner after a claim and no
inexact target (Validation).

Upgrading from 0.3.x

Bump Trellis in a deploy of its own, so nothing else in that deploy can stop
it halfway. The full procedure is in
upgrading.

Procedure

  1. Run 0.4.0's migrate: trellis migrate, bin/rails db:migrate or
    db:prepare (the gem now hooks them), or mix trellis.migrate /
    Trellis.Migration.migrate_repos!/1 (Elixir needs two setup edits,
    below). From 0.3.x it takes the instance over once:

    • It raises the catalog floor to 0.4.0. At their next poll, 0.3.x
      processes stand by and stay up. trellis run logs trellis standing by: refusing to attach: the catalog floor is 0.4.0, …; run Trellis 0.4.0 or later. 0.3.x's apply exits 1, and the 0.3.x gem's Trellis.migrate
      raises Trellis::VersionFloorError. 0.3.x prints no T-code.
    • It waits until 0.3.x's processes stand by and their drains and
      transactions in flight end. That is about 30 seconds (26–30 s in the
      battery), or longer when 0.3.x is draining a large share. With a 5M-row
      share in flight, it waited minutes.
    • It runs migrations V22–V24 and records 0.4.0 as the owner.

    migrate waits up to 60 seconds, then fails with
    T0256.
    Run it again: it doesn't wait again for what has stood by.

  2. Roll out 0.4.0. Its first background process drains what was staged
    meanwhile. Capture never stops. Between the claim and that process, nothing
    drains (the quiet window).
    A deploy step that waits for convergence must run after the new workers
    start.

A deploy with no migrate step still works: 0.4.0's first background process
takes over by itself and waits as long as the takeover takes.

Raising the floor is the point of no return. From then on 0.3.x drains
nothing. If the deploy stops there, finish it forward, or leave with
rollback.

Rolling back to 0.3.x

0.3.x can't read the catalog 0.4.0 migrated, so its migrate refuses
(below the catalog floor):

  1. Stop every 0.4.0 process. Run trellis rollback --to 0.3.1
    (mix trellis.rollback --to 0.3.1, bin/rails trellis:rollback TO=0.3.1).
    It lists what it drops and asks you to type rollback. It drops Trellis's
    schema and capture triggers, empties every target, and leaves the
    definitions queued plus a hold that keeps 0.4.0 workers standing by.
  2. Start 0.3.x. Its trellis run (0.3.x has no trellis migrate) or its
    client's migrate restores the queue and rebuilds every target.
    Definitions with floor 0.4.0 (below) are stored
    paused with empty targets.

Targets are empty, then partial, until the rebuild ends: about 1 minute per
1M source rows. Pauses, held keys and self_check history are lost. After
rolling forward, RESUME each definition 0.3.x stored paused. A 1-1 one can't
be resumed: drop it and define it again. In the battery, rolling back to each
of 0.3.0 and 0.3.1 and forward again left every target exact.

Compatibility floors

  • Catalog floor 0.4.0. V22__definition_key_encoding.sql records each
    table's key encoding (#2217). 0.3.x reads key encodings from the live
    catalog, so it would decode 0.4.0's keys differently.
  • Definition floor 0.4.0 is recorded by a define, alter or rebuild using:
    a WHERE other than TRUE; IN, NOT IN, BETWEEN, NOT BETWEEN;
    SUM/AVG over real, double precision or interval; an enum column
    = a string literal; a string literal beside a char(n) value
    (floors).

Definitions 0.4.0 refuses that 0.3.x accepted

No definition 0.3.x accepted fails to parse under 0.4.0, so none pauses for
its text. Two fail a new define-time check. The takeover leaves each as 0.3.x
left it, and a fresh define refuses it:

  • A text comparison between columns of two collations, neither the
    default

    (T0233).
    Under 0.3.x its build retried forever on Postgres's error. Under 0.4.0 it
    pauses once the retries run out, and RESUME refuses with T0233.
  • OCTET_LENGTH over a char(n) GROUP BY key
    (T0246).
    0.3.x gave values that differ from Postgres's (1, 2, 4 where Postgres
    gives 4). It stays live with them, and self_check doesn't flag it. To
    fix it, drop it and define it without that field. RESUME after a PAUSE
    refuses.

What new text means differently

There is no grammar version bump: 0.4.0 still writes grammar 2
(ADR-0018).
One reading changes, for stored definitions too: a string literal beside a
char(n) value
(an operand of =, <>, IS [NOT] DISTINCT FROM, an
argument of COALESCE or NULLIF, a CASE result) now compares as
char(n), as Postgres does. So ch = 'ab ' ignores trailing blanks. Beside
name, only a literal over 63 bytes changes. Every other new construct was a
refusal in 0.3.x.

Definitions that pause because 0.4.0 keys a table differently

Existing definitions keep their keying. V22 records each table's key from
today's catalog and rewrites no stored key.

  • A NULL in a key column recorded as NOT NULL pauses the table's
    readers
    (T0253).
    Remove the NULLs or fix the partition, then RESUME.
  • A key column that can hold NULL after a DROP NOT NULL, recorded
    raw, pauses its readers when a NULL reaches the drain, and define refuses
    a new reader
    (T0254).
    RESUME records the key again and rebuilds. To define a new reader first,
    PAUSE and RESUME one already running.
  • If the database ever ran 0.3.0: a 1-1 over a KEY (…) on a UNIQUE … NULLS NOT DISTINCT index with a nullable column may have been left wrong
    (#2126, fixed in 0.3.1). The upgrade doesn't repair it (#2292). Run
    self_check on those definitions, and PAUSE/RESUME any that diverge.

Changes the upgrade makes that you don't see

  • Definitions comparing a string literal with char(n) rebuild once, in
    place, at the takeover (above).
  • Capture functions are re-created by migrate to add
    row_security = off (#2227) and this release's capture fixes (#2154,
    #2205). Capture doesn't stop. A source the role doesn't own keeps 0.3.x's
    functions and is reported as
    T0255
    (#2291).
  • V22–V24 record key encodings, the owner and the owner's last heartbeat.
    On an earlier candidate no table was rewritten and only the char(n)
    definitions rebuilt.
  • The claim frees what the old release held: drain segment claims, build
    chunk claims and running self_check jobs, which are re-queued (#2324).

Schema dumps

A structure.sql that 0.3.x wrote with dump_definitions_sql loads and
builds under 0.4.0 (battery structure step). A restore queue now runs as
part of the claim (ADR-0025).

Behaviour changes

  • trellis run no longer migrates at start-up (#2321). It claims like
    any background process. It claims at once if it is newer than the owner and
    no explicit rollback set that owner. Otherwise it claims once the owner has
    been silent for --claim-grace-period (600 s by default;
    claim_grace_period in the library, claim_grace_period_ms in the
    bindings, #2317). Action: keep the grace period longer than your
    deploy's gap between migrate and its first worker.
  • One role runs everything Trellis does
    (one Trellis role).
    Split DDL and DML roles are no longer documented or supported. A claim
    whose role can't alter Trellis's tables logs why, reports it in
    migrations_pending.cannot_run, and retries every 5 seconds. Action:
    run workers as the role that runs migrate and owns the sources.
  • Forced row-level security halts a source's readers unless Trellis's role
    has BYPASSRLS
    (#2227). Capture's re-read runs with
    row_security = off, so a policy that applies to the role now refuses the
    read instead of hiding rows. Action: give the role BYPASSRLS where
    sources force RLS.
  • New 1-1 targets over a KEY (…) on a UNIQUE … NULLS NOT DISTINCT
    index
    are keyed UNIQUE NULLS NOT DISTINCT with nullable key columns, not
    PRIMARY KEY (#2217, #2147). Existing targets are unchanged.
  • Every non-widening key retype rebuilds the table's readers (#2254),
    value-preserving narrowings included.
  • A source the drain can't find pauses its readers
    (T0172,
    #2270). Put the table back, then RESUME.
  • A page that fails only for one definition pauses that definition
    (T0247,
    #2130). Before, a drain holdup stopped every target.
  • Objects outside Trellis that depend on a target (a foreign key, a view)
    make DROP TRANSFORM, a field drop and a 1-1 RESUME refuse
    (T0242,
    #1717). Trellis never cascades.
  • Disk-full and other resource errors retry as transient instead of
    quarantining (#2131). transaction_timeout and
    idle_in_transaction_session_timeout retry as connection errors (#2145).
  • Pooled connections are replaced after 30 minutes (#2222), so session
    temp tables stop holding back datfrozenxid.
  • Error messages start with their code (#2013). Action: code that
    matches message text from the start of the string should match the code.
  • Quieter logs during outages (#2156): drain failures warn once, then
    once a minute. A full ring (T0185) logs at debug for its first minute.
  • A refused maintenance step no longer stalls the leader. status()
    reports it in maintenance_refusals, and a refused build start halts that
    definition (#2025).
  • While another version owns the instance, status() names the owner and
    when this release claims. The ring gauges keep reporting while processes
    stand by
    (observability,
    #2303).

What's new

  • WHERE (expressions,
    #2038, #2039, #2041, #2042). A join aggregate splits its WHERE at
    top-level ANDs, and each condition reads one table. MIN/MAX in a
    filtered plain aggregate is refused, with a recipe. A WHERE reading a
    paused upstream column reports catching_up (#2105). Refusals: T0234–T0237,
    T0239, T0243–T0245.
  • Expressions: IN (…), NOT IN (…), BETWEEN, NOT BETWEEN (#2172).
    Subquery lists, SYMMETRIC, = ANY (…) and row constructors get named
    refusals (T0248–T0251), and so does a list Postgres reads at a surprising
    common type (T0252). An enum column = a string literal (#2037; T0241 for a
    non-label). COUNT(DISTINCT x) gets a named refusal with a two-transform
    recipe (T0240, #1739).
  • Exact float and interval sums (#1119). {1e20, 1, -1e20} sums to 1,
    unlike Postgres's order-dependent sum(). AVG(interval) matches avg()
    exactly.
  • A define accepts an upstream that hasn't built yet (#2111), so a chain
    of transforms migrates into a database with no worker running.
  • rollback and uninstall in the CLI, Rake, Mix and the Rust API, with
    a _plan form that lists what they change (#2304,
    uninstalling).
  • trellis migrate runs migrations and claims. It prints any source whose
    capture functions it couldn't refresh (#2291).

Bugfixes

Correctness:

  • A string literal beside char(n) compared as text (ch = 'ab '
    was false) (#2000). A field over a char(n) GROUP BY key now reads it as
    char(n) (#2053).
  • A KEY column's NOT NULL set or dropped with changes in flight
    decoded staged keys under the other encoding, a silently wrong target
    (#2147, #2217).
  • PG 18: a KEY column under NOT NULL … NOT VALID was read as never
    NULL, and its NULL rows were dropped (#2148).
  • A nullable KEY column was keyed differently by capture and the build
    (#2126; in 0.3.1 already).
  • Row-level security hiding rows from capture's re-read left a target
    silently wrong (#2227).
  • A key column narrowed with a value-changing USING was neither paused
    nor re-read (#2254).
  • A same-type rewrite of a GROUP BY column with an insert in flight left
    the old group in a live target (#2219). A GROUP BY column dropped and
    added again inside one capture pass
    left a live target silently wrong
    (#2312).
  • A source renamed away and back within one interval lost its staged
    changes. Its readers now pause. A partitioned source remains a
    documented gap (#2270).
  • A frozen row older than 2^31 transaction ids could win capture's re-read
    under REPEATABLE READ (#2205). A narrow residual is a documented gap.
  • self_check could vouch for a key with no ledger entry (#2032).
    ALTER TRANSFORM didn't re-check collation reads of unedited fields
    that read an edited one (#2114).

Availability and operations:

  • Capture failed application writes after an ownership change or revoked
    grant (#2154). The readers now halt instead.
  • A column narrowed to integer poisoned a key of every aggregate on the
    table,
    including ones that don't read it, and the run never converged
    (#2313).
  • Session temp tables pinned datfrozenxid for a pooled connection's life
    (#2222).
  • Lock-order inversions that could deadlock: version fences, the drift
    check, pauses, halts and the restore response now lock in one sorted
    statement (#2020, #2023, #2026, #2094, #2095).
  • After a Postgres outage over 30 s, a worker stood by for a phantom
    pre-0.2.0 staging worker, itself (#2155).
  • A DML-only worker missing a privilege retried forever, logging about two
    lines a second (#2025).
  • A disk-full target quarantined its transform (#2131). A long apply under
    transaction_timeout had its keys evicted (#2145).
  • A retryable lock timeout during a RESUME's revalidation ended the
    resume request as if it were a refusal (#2315).
  • Messages: a refused RESUME names the real status (#1848). A MIN/MAX
    refusal names the declared type (#1895). A retype pause names only remedies
    that work (#2090). A source renamed away mid-drain no longer halts with a
    wrong T0121 (#2293). Drain errors no longer say target-table DDL error
    (#2272).

Breaking and changed API

Rust (trellis-pg)

  • ErrorId and error_id() on every public error enum (#2013). Display
    starts with the code.
  • OtherVersionLive becomes NotOwner (still T0220): the owner, whether a
    rollback set it, its live processes, and claims_at. other_versions is
    gone (#2303).
  • ApplyError::ResumeRefused gains status (#1848). Code that matches it
    without .. must change.
  • New: Trellis::migrate_with_report, rollback, rollback_plan,
    uninstall, uninstall_plan (and their BlockingTrellis forms),
    LeavePlan, claim_grace_period, status().maintenance_refusals.

CLI (trellis)

  • New trellis migrate, trellis rollback [--to <release>],
    trellis uninstall.
  • trellis run runs no start-up migrate and takes --claim-grace-period.

Clients

Ruby (trellis-pg)

  • Rails database tasks run Trellis's migrate after their own work,
    whether or not a migration was pending: db:migrate and its variants,
    db:rollback, db:prepare, db:schema:load, db:test:prepare (#2305).
    So a gem-only bump claims the instance, and so does Kamal's boot-time
    db:prepare. Opt out with config.trellis.task_hooks = false.
  • trellis:release_check is removed (#2305). A release may now bump the
    gem and add Trellis migrations together. Action: remove it from CI.
  • bin/rails trellis:rollback TO=<release> and trellis:uninstall
    (CONFIRM=yes without a terminal) (#2304).
  • With Trellis off (off_in, test by default), the migration helpers,
    trellis:migrate and the schema hooks run; only the runtime is off
    (#2124). Action: a suite that relied on the helpers raising there now
    sees them run.
  • Migration helpers connect to the database being migrated (#1967).
  • Trellis::Error#error_id, and claim_grace_period_ms.

Elixir (trellis_pg)

  • Run Trellis's migrate with your migrations (#2306). Ecto has no hook,
    so add "ecto.migrate": ["ecto.migrate", "trellis.migrate"] to your
    aliases, and call Trellis.Migration.migrate_repos!/1 at the end of the
    release's migrate/0
    (setup).
    Action: make both edits before deploying 0.4.0. Without them only a
    worker's own claim moves the instance.
  • mix trellis.rollback [--to RELEASE] and mix trellis.uninstall (#2304).
  • config :trellis_pg, enabled: false turns the runtime off. The
    Trellis.Migration helpers still run (#2046, #2111).
  • use Trellis.Target: writes to a target schema raise
    Trellis.ReadOnlyTarget unless allow_target_writes: true (#2047).
  • Trellis.TestSupport.refresh_target/3 (#2048), plus Trellis.Metrics.Plug
    and Trellis.Metrics.Appender (#2049).
  • Supported versions, a test recipe and an aarch64-musl NIF (#2050). No Ecto
    warnings without ecto_sql (#2062).
  • %Trellis.Error{error_id: …} and claim_grace_period_ms.
  • Dependency updates for security advisories (#2157, #2279). CI runs
    mix hex.audit, and bundle-audit for Ruby (#2158).

Docs

  • Errors
    is the one reference for every code. The refusal tables are gone (#2014,
    #2118).
  • Upgrading and rolling back
    is rewritten around the claim. It covers where migrate runs and the quiet
    window (#2307).
  • Connect Trellis directly or through a session-mode pooler (#2122). A
    logical pg_dump that includes Trellis's schema stalls draining while it
    runs (#2132).
  • Known correctness gaps:
    • removed: the KEY NOT NULL flip;
    • narrowed: rename-and-back, now partitioned sources only;
    • added: a transaction-mode pooler, an old key re-created under
      REPEATABLE READ, an old release's build chunk after the claim (0.3.x
      takeover only), and the one-role precondition.

Known issues

  • A source with a column of a NOT NULL domain type that no definition
    reads: self_check fails with T0197 (23502) while changes are pending.
    Drains are correct. On 0.3.x every aggregate drain of such a source
    quarantines its keys; 0.4.0 fixes that (#2333).

Validation

The figures come from the maintainers' validation logbook: runs started after
the v0.3.0 tag and finished by 1 December, excluding the 0.3.1 canary and
work for the next release. Most row counts are the runs' own
estimates.

Kind Runs Hours Source rows Outcomes
Generative sweeps 92 43.1 74,006,488 79 ok, 8 fail, 5 miss
Soak and chaos 39 52.0 85,344,873 37 ok, 1 miss, 1 aborted
Benchmarks 15 8.9 1,820,150,600 14 ok, 1 miss
Repro loops 29 9.3 35,162,964 27 ok, 1 fail, 1 miss
Acceptance 26 21.3 382,101,389 20 ok, 3 miss, 3 aborted
Total 201 134.6 2,396,766,314

Each fail and miss was one of: a finding fixed in this release, a harness
bug, or a contended box. Since the project began, the logbook
records 986 runs, 633.7 hours and about 23.8 billion rows.

Release gate

  • Upgrade battery (candidate fea4a09, PG 17.11), from v0.3.0
    (20261201T105853-c-acceptance) and v0.3.1
    (20261201T111020-c-acceptance): PASS=73, FAIL=0, INFO=7, MANUAL=2 each.
    • Takeovers claimed 26–27 s after start.
    • A 500,000-row old drain share spanned the yield, and migrate waited it
      out.
    • Statement-trigger audits found 0 writes by the old release after the
      claim.
    • rollback --to 0.3.x and forward again were exact.
    • INFO: the candidate adds migrations V22–V24 and raises the catalog floor
      to 0.4.0. Going back is the rollback command.
    • The clients step, run separately on main 8741902 from v0.3.1
      (20261201T183934-a-acceptance): the 0.3.1 gem, the candidate gem and
      the candidate Elixir package open the same database alike, and the Rake
      and Mix migrate, rollback and uninstall tasks work against a
      0.3.1-owned database, round trip included.
    • A v0.3.1 structure.sql in the current dump format loads under 0.4.0,
      and its 12 definitions build identically to v0.3.1's (same run).
    • The manual grammar cases were not re-run on this candidate. On an
      earlier candidate (a71188c, 20261126T075103-d-acceptance) they found
      only the two
      define-check refusals.
  • Takeover and rollback on release builds (#2308), six series, PG 15.19,
    17.11 and 18.7: deploy shapes, the takeover from v0.3.1, rollback below
    the floor and uninstall, chaos, and the quiet window
    (20261201T103448, 124706, 131345, 143236, 143936, 162648, all
    -g-acceptance).
    • 120 chaos runs kill -9ed processes at the claim, mid-drain, mid-seal
      and mid-build, or ran two migrates at once. All were exact.
    • Every counted run ended with the SQL oracle at 0 and a strict
      self_check Converged, with 0 non-owner writes after a claim.
    • After the quiet window, catch-up ran at about 100k source rows/s with
      writes continuing.
  • Benchmark, v0.3.1 against 0.4.0 (20261201T070301-d-bench): applied
    throughput at saturation and at about 60% of the knee, on tmpfs and disk.
    The ownership fence costs nothing beyond run-to-run noise. At tmpfs
    saturation it measured 191.8k rows/s for 0.3.1 and 206.7k for 0.4.0, not
    significant.
  • Generative soak (20261125T085210-a-soak, 15.5 h at d3aba75): all 40
    properties, fresh seeds, PG 15.19–18.7. It ran about 56.5k engine cases and
    1.27M expression-conformance cases with no oracle mismatch. Its 8 failures
    were harness bugs, all fixed (#2283–#2286).
  • Standing canary (#2191): started on 0.3.1 on 25 November, never reset,
    under rotating load. Its three stops were latency gates on a loaded box,
    not correctness faults. Its gates are now trends (#2343). It is upgraded in
    place at the tag.

Soak and chaos

  • Mid-cycle generative soak (20261118T113212-a-soak, 16.4 h): about
    89k engine cases and 1.2M expression cases. Its 6 failures were harness
    bugs, all fixed.
  • Chaos (20261118T102243-f, 20261119T071355-f, 20261119T074047-f):
    62 kill -9s with two racing workers under load, a Postgres restart,
    backend kills, a 90 s TCP blackhole, max_connections exhaustion, and a
    15-minute worker outage at 1,000 tps that caught up in 70 s. The oracle
    found 0 diffs.
  • Sustained load (20261119T091335-f-soak): 3 h at 1,000 tps, 10.7M
    operations, 0 errors, flat worker RSS. A nightly rotation of load profiles
    has run since 22 November with 0 oracle diffs.
  • The generative suite grew (#2180): transaction shapes, a non-superuser
    role with privilege changes, definition changes and source DDL under load,
    liveness properties, epoch chaining, and transaction-id and clock aging.
    Its findings are fixed in this release.