Repository navigation
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 oldermigratesticks. Newrollback --to <release>
leaves a release whose catalog floor an older one can't read, and
uninstallremoves Trellis completely (#2299,
ADR-0023,
ADR-0024,
ADR-0025). WHEREon transforms. Every key space takes a totalWHERE: plain 1-1,
plain aggregates, 1-1JOINand star transforms, and join aggregates (one
filter per side). It is applied as rows are applied (#1991).IN,NOT IN,BETWEENandNOT BETWEENin calculated fields and
WHERE(#2172). An enum column=a string literal now defines (#2037).SUM/AVGoverreal,double precisionandinterval, 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 aGROUP BYkey (#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
enabledswitch, a read-only target guard,
refresh_target, metrics plugs, andmigratefromecto.migrateand
releases (#1986, #2306). - Capture never fails an application write when its re-read of a source
is refused. The readers halt with a reason, andRESUMErebuilds 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
-
Run 0.4.0's
migrate:trellis migrate,bin/rails db:migrateor
db:prepare(the gem now hooks them), ormix 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 runlogstrellis standing by: refusing to attach: the catalog floor is 0.4.0, …; run Trellis 0.4.0 or later. 0.3.x'sapplyexits 1, and the 0.3.x gem'sTrellis.migrate
raisesTrellis::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.
migratewaits up to 60 seconds, then fails with
T0256.
Run it again: it doesn't wait again for what has stood by. - It raises the catalog floor to 0.4.0. At their next poll, 0.3.x
-
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):
- 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 typerollback. 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. - Start 0.3.x. Its
trellis run(0.3.x has notrellis migrate) or its
client'smigraterestores 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.sqlrecords 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:
aWHEREother thanTRUE;IN,NOT IN,BETWEEN,NOT BETWEEN;
SUM/AVGoverreal,double precisionorinterval; an enum column
=a string literal; a string literal beside achar(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, andRESUMErefuses with T0233. OCTET_LENGTHover achar(n)GROUP BYkey
(T0246).
0.3.x gave values that differ from Postgres's (1, 2, 4 where Postgres
gives 4). It stayslivewith them, andself_checkdoesn't flag it. To
fix it, drop it and define it without that field.RESUMEafter aPAUSE
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
NULLin a key column recorded asNOT NULLpauses the table's
readers
(T0253).
Remove theNULLs or fix the partition, thenRESUME. - A key column that can hold
NULLafter aDROP NOT NULL, recorded
raw, pauses its readers when aNULLreaches the drain, and define refuses
a new reader
(T0254).
RESUMErecords the key again and rebuilds. To define a new reader first,
PAUSEandRESUMEone already running. - If the database ever ran 0.3.0: a 1-1 over a
KEY (…)on aUNIQUE … NULLS NOT DISTINCTindex with a nullable column may have been left wrong
(#2126, fixed in 0.3.1). The upgrade doesn't repair it (#2292). Run
self_checkon those definitions, andPAUSE/RESUMEany 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
migrateto 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 thechar(n)
definitions rebuilt. - The claim frees what the old release held: drain segment claims, build
chunk claims and runningself_checkjobs, 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 runno 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_periodin the library,claim_grace_period_msin the
bindings, #2317). Action: keep the grace period longer than your
deploy's gap betweenmigrateand 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 runsmigrateand owns the sources. - Forced row-level security halts a source's readers unless Trellis's role
hasBYPASSRLS(#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 roleBYPASSRLSwhere
sources force RLS. - New 1-1 targets over a
KEY (…)on aUNIQUE … NULLS NOT DISTINCT
index are keyedUNIQUE NULLS NOT DISTINCTwith 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, thenRESUME. - 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)
makeDROP TRANSFORM, a field drop and a 1-1RESUMErefuse
(T0242,
#1717). Trellis never cascades. - Disk-full and other resource errors retry as transient instead of
quarantining (#2131).transaction_timeoutand
idle_in_transaction_session_timeoutretry as connection errors (#2145). - Pooled connections are replaced after 30 minutes (#2222), so session
temp tables stop holding backdatfrozenxid. - 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 atdebugfor its first minute. - A refused maintenance step no longer stalls the leader.
status()
reports it inmaintenance_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 itsWHEREat
top-levelANDs, and each condition reads one table.MIN/MAXin a
filtered plain aggregate is refused, with a recipe. AWHEREreading a
paused upstream column reportscatching_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 to1,
unlike Postgres's order-dependentsum().AVG(interval)matchesavg()
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. rollbackanduninstallin the CLI, Rake, Mix and the Rust API, with
a_planform that lists what they change (#2304,
uninstalling).trellis migrateruns migrations and claims. It prints any source whose
capture functions it couldn't refresh (#2291).
Bugfixes
Correctness:
- A string literal beside
char(n)compared astext(ch = 'ab '
was false) (#2000). A field over achar(n)GROUP BYkey now reads it as
char(n)(#2053). - A
KEYcolumn'sNOT NULLset or dropped with changes in flight
decoded staged keys under the other encoding, a silently wrong target
(#2147, #2217). - PG 18: a
KEYcolumn underNOT NULL … NOT VALIDwas read as never
NULL, and itsNULLrows were dropped (#2148). - A nullable
KEYcolumn 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
USINGwas neither paused
nor re-read (#2254). - A same-type rewrite of a
GROUP BYcolumn with an insert in flight left
the old group in alivetarget (#2219). AGROUP BYcolumn dropped and
added again inside one capture pass left alivetarget 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
underREPEATABLE READ(#2205). A narrow residual is a documented gap. self_checkcould vouch for a key with no ledger entry (#2032).
ALTER TRANSFORMdidn'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
integerpoisoned 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
datfrozenxidfor 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_timeouthad 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
RESUMEnames the real status (#1848). AMIN/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 saytarget-table DDL error
(#2272).
Breaking and changed API
Rust (trellis-pg)
ErrorIdanderror_id()on every public error enum (#2013).Display
starts with the code.OtherVersionLivebecomesNotOwner(still T0220): the owner, whether a
rollback set it, its live processes, andclaims_at.other_versionsis
gone (#2303).ApplyError::ResumeRefusedgainsstatus(#1848). Code that matches it
without..must change.- New:
Trellis::migrate_with_report,rollback,rollback_plan,
uninstall,uninstall_plan(and theirBlockingTrellisforms),
LeavePlan,claim_grace_period,status().maintenance_refusals.
CLI (trellis)
- New
trellis migrate,trellis rollback [--to <release>],
trellis uninstall. trellis runruns no start-upmigrateand takes--claim-grace-period.
Clients
Ruby (trellis-pg)
- Rails database tasks run Trellis's
migrateafter their own work,
whether or not a migration was pending:db:migrateand 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 withconfig.trellis.task_hooks = false. trellis:release_checkis 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>andtrellis:uninstall
(CONFIRM=yeswithout a terminal) (#2304).- With Trellis off (
off_in,testby default), the migration helpers,
trellis:migrateand 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, andclaim_grace_period_ms.
Elixir (trellis_pg)
- Run Trellis's
migratewith your migrations (#2306). Ecto has no hook,
so add"ecto.migrate": ["ecto.migrate", "trellis.migrate"]to your
aliases, and callTrellis.Migration.migrate_repos!/1at the end of the
release'smigrate/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]andmix trellis.uninstall(#2304).config :trellis_pg, enabled: falseturns the runtime off. The
Trellis.Migrationhelpers still run (#2046, #2111).use Trellis.Target: writes to a target schema raise
Trellis.ReadOnlyTargetunlessallow_target_writes: true(#2047).Trellis.TestSupport.refresh_target/3(#2048), plusTrellis.Metrics.Plug
andTrellis.Metrics.Appender(#2049).- Supported versions, a test recipe and an aarch64-musl NIF (#2050). No Ecto
warnings withoutecto_sql(#2062). %Trellis.Error{error_id: …}andclaim_grace_period_ms.- Dependency updates for security advisories (#2157, #2279). CI runs
mix hex.audit, andbundle-auditfor 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 wheremigrateruns and the quiet
window (#2307). - Connect Trellis directly or through a session-mode pooler (#2122). A
logicalpg_dumpthat includes Trellis's schema stalls draining while it
runs (#2132). - Known correctness gaps:
- removed: the
KEYNOT NULLflip; - 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.
- removed: the
Known issues
- A source with a column of a
NOT NULLdomain type that no definition
reads:self_checkfails 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
migratewaited it
out. - Statement-trigger audits found 0 writes by the old release after the
claim. rollback --to 0.3.xand forward again were exact.- INFO: the candidate adds migrations V22–V24 and raises the catalog floor
to 0.4.0. Going back is therollbackcommand. - The
clientsstep, 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 Mixmigrate,rollbackanduninstalltasks work against a
0.3.1-owned database, round trip included. - A v0.3.1
structure.sqlin 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 anduninstall, 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 twomigrates at once. All were exact. - Every counted run ended with the SQL oracle at 0 and a strict
self_checkConverged, with 0 non-owner writes after a claim. - After the quiet window, catch-up ran at about 100k source rows/s with
writes continuing.
- 120 chaos runs
- 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):
62kill -9s with two racing workers under load, a Postgres restart,
backend kills, a 90 s TCP blackhole,max_connectionsexhaustion, 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.