Skip to content

Latest commit

 

History

History
431 lines (353 loc) · 27.8 KB

engines.md

File metadata and controls

431 lines (353 loc) · 27.8 KB

Engines

Table of Contents

SchemaBot runs your schema change through an engine: the part of it that knows how to make a change safely on one kind of database. Everything else is the same whichever engine is involved. SchemaBot plans the change, gates it on review, drives it to a conclusion, and reports on it; the engine is what touches your tables.

Engine Target Built on
Spirit MySQL Spirit
PlanetScale Vitess PlanetScale deploy requests
pg-sprite PostgreSQL pg-sprite

For primary key choices and online copy progress, see the MySQL guide.

Engines are adapters rather than implementations. None of them reimplements online schema change; each one drives existing machinery and translates between it and the rest of SchemaBot. In every case the work itself lands in the target database: your MySQL, Vitess, or PostgreSQL server is what copies the rows and runs the DDL, whichever engine asked it to.

What differs is where the thing driving that work runs. Spirit and pg-sprite are libraries, so the loop that issues statements and decides what happens next runs inside the SchemaBot process holding the apply. A PlanetScale deploy request is Vitess Online DDL wrapped in PlanetScale's API and branching model, and Vitess drives it from inside the cluster, so SchemaBot submits the change and then watches it rather than running it. The copy, the cutover, the revert window, and the throttle are all Vitess features on that path. The difference comes up several times below.

Engines differ, and this is where those differences are written down. It is the companion to invariants.md, and the two answer different questions. That document is about SchemaBot's orchestration, and most of it holds no matter which engine executes a change. Only a few of its entries reach the engine boundary at all, and it names which ones. It is also meant to stay put, where this page moves as engines gain features.

Capability matrix

Spirit (MySQL) PlanetScale (Vitess) pg-sprite (PostgreSQL)
Cheap native path tried first yes, instant DDL yes, instant DDL yes, attempted under budgets that cancel a rewrite
Online DDL (copy and swap) yes, when instant is not possible yes, when instant is not possible planned; meanwhile a predicted rewrite is blocked at plan, and a mispredicted one is cancelled by its budget
Escape hatch for refused statements direct execution: on by default, size-bounded none, excluded by design none, native execution is already the only path
stop yes no planned
start yes deferred deploys only planned
Deferred cutover yes yes planned
cancel yes yes index builds, a step waiting for its lock, and steps not yet started
revert / skip-revert no yes no
Throttling automatic, on live target signals automatic, on live cluster signals; plus an operator-set rate on a running change planned, on replica and slot lag; meanwhile a statement is cancelled at its budget rather than slowed
Adaptive pacing yes no planned
Dropped-table recovery opt-in quarantine, expires inside the revert window, expires no
Who reports progress the process driving the change the cluster, so any instance can read it the process driving the change

A cell that says planned means the engine does not do this yet but is expected to. A plain no means it does not do this today.

Either way, asking for something an engine does not support is safe rather than surprising, and it resolves one of two ways. When the answer is known before any work starts, the request is refused on the spot and nothing durable is recorded, so there is no pending command left against an engine that will never service it. When the engine is the one that declines, the request was already recorded durably before it was acknowledged, and the decline is a typed "unsupported operation" that settles it terminally rather than retrying against an answer that cannot change. Neither shape hangs, gets dropped silently, or reports a success that did not happen. That is CO-1 and CO-2 in invariants.md, and it is what keeps a narrower engine a safe one.

stop on Vitess is the first shape, and it declines with a pointer rather than just a refusal: a deploy request cannot be paused, so the message names cancel as the operation that will take the load off the database, and says plainly that it is permanent. SchemaBot will not quietly carry out the stop as a cancel, because someone asking to pause has said they intend to resume. That is CO-8 in invariants.md, and the next section covers why the engine cannot pause.

What the terms mean

Every row of the matrix, in a line each.

Term Meaning
Instant DDL A change the database makes by editing metadata alone, without touching the rows. Done in milliseconds, with no copy and nothing to control while it runs.
Copy and swap Building a new version of the table, backfilling it, keeping it in step with ongoing writes, and swapping it in. Also called online DDL. It is what lets a large table change without a long lock.
Cutover The swap: moving traffic from the original table to the new one. It is the shortest phase of a copy, but it is a phase and not an instant, and it is the part that takes a lock.
Deferred cutover Holding a finished copy at that point until an operator asks for the swap, instead of swapping as soon as the copy is ready.
Revert window A period after cutover in which the original table still exists, so the change can be undone.
Direct execution Running a statement as ordinary DDL against the database, with no copy. Two separate bounds apply: a configured timeout caps how long it waits to acquire the lock, and the transactions blocking it are killed before that timeout runs out; a table size limit in the policy bounds how long writes are blocked once it has the lock.
Throttling Holding the copy back while the database is under pressure.
Adaptive pacing Continuously adjusting how hard the copy pushes based on how the database is responding, rather than only starting and stopping it.
Quarantine Renaming a dropped table aside and keeping it for a while instead of dropping it outright.

A copy runs long enough to be worth steering, which is what the control operations are for. Here is where each one acts:

                    stop                      cutover           revert
                   (start                    (deferred          skip-revert
                   resumes)                   only)
                      |                          |                  |
                      v                          v                  v
   plan ---> [ copying rows ] ---> [ waiting ] ---> swap ---> [ revert window ] ---> done
                      |
                      +--- cancel ends the change outright, from anywhere before the swap
Does
stop Pause the change, keeping the work done so far.
start Resume a stopped change from where it left off.
cancel End the change for good. Nothing resumes it.
cutover Trigger the swap for a change held at a deferred cutover.
revert Undo a completed change while its revert window is open, putting the original table back.
skip-revert Close the revert window early and finalize the change.
release Let a multi-deployment rollout continue after it paused on a failure.

Not every engine has every phase, which is what the matrix above is for: a change with no copy never reaches most of that line, and only Vitess holds a revert window at the end of it.

rollback is deliberately not in the table. It is a fresh plan and apply that returns the schema to an earlier state, so it happens after a change is over rather than to one that is running. revert is the in-flight counterpart, and it exists only while the window is open.

Why the differences exist

The first two rows drive most of the rest of the table, so start there.

   ALTER TABLE ...
        |
        +-- metadata only? ----------> done in milliseconds, nothing to control
        |
        +-- needs to rewrite rows? --> copy and swap, minutes to weeks, controllable

The cheap native path

Every engine tries this first. Some changes are metadata-only: adding a column at the end of a table does not have to touch the existing rows, so the server can make the change without rewriting them. When that works the change is done in milliseconds, and none of the control operations apply, because there is nothing in flight to control. What differs is how an engine finds out whether it will work.

On MySQL the server can be asked. Spirit runs the statement with ALGORITHM=INSTANT and lets the server decide, rather than keeping a list of qualifying operations of its own, because eligibility changes between MySQL minor versions and can even depend on the table. That is instant DDL, and Vitess makes the same attempt for a deploy request.

PostgreSQL has no equivalent flag, so pg-sprite gambles instead of asking. It runs the statement once, under a lock timeout and a statement timeout it sets for that statement alone. If the change really was metadata-only it commits in milliseconds; if it turns out to rewrite the table, the server cancels it at the timeout and PostgreSQL's transactional DDL rolls it back cleanly, leaving nothing behind. The refusal is reported as a budget error rather than a failed change. Its planner classification is a prediction, not a promise, so even a statement it expects to be metadata-only gets a budget rather than an exemption. Above a configured table size the attempt is refused outright, before any DDL runs, since a rewrite there is likely enough that gambling is not worth the lock. That refusal becomes the routing signal into copy and swap when pg-sprite gains it.

Copy and swap

This is what happens when the cheap path is not possible. The engine builds a new table, backfills it, keeps it in sync with ongoing writes, and swaps it in. That is what lets a large table change without a long lock, and it is why the change becomes a long-running process with phases: something is in flight, so there is something to pause, something to slow down, and a cutover to run when you choose. Every control operation in the matrix exists because of it.

What drives the copy decides who can report on it:

   Spirit and pg-sprite                    PlanetScale

   +---------------------+                 +---------------------+
   |  SchemaBot          |                 |  SchemaBot          |
   |   driver loop  -----|--- statements   |   watcher      -----|--- submit, then poll
   +---------------------+           |     +---------------------+          |
                                     v                                      v
                              +-------------+                    +---------------------+
                              |  database   |                    |  Vitess cluster     |
                              +-------------+                    |   driver loop  ---+ |
                                                                 |                   v |
                                                                 |    +-------------+  |
                                                                 |    |  database   |  |
                                                                 |    +-------------+  |
                                                                 +---------------------+

A Spirit copy is driven by the process holding the apply, so only that process knows how far along it is, and if it dies its replacement picks up from a checkpoint. A deploy request outlives the process that submitted it, and any instance can ask the cluster for its progress and get the same answer.

Pausing

stop and start are ordinary control operations, no more tied to one database technology than cancel is. What varies is whether the engine behind them can suspend a change and pick it back up. Spirit can: a stop checkpoints the copy and settles the apply as stopped, and start resumes from that checkpoint. The PlanetScale engine cannot, because a deploy request runs or it ends. So there the way to take the load off a database is cancel, which ends the change for good.

SchemaBot could quietly carry out a stop as that cancel, and it does not. Asking to pause says you mean to come back, and a cancel gives you nothing to come back to, so the stop is refused and the refusal names cancel and says it is permanent. The choice to end the change stays the operator's. That is CO-8 in invariants.md.

start follows stop. On the PlanetScale engine it exists only to launch a deploy request that was created and deliberately left undeployed, which is how a change waits for an operator before it begins. It never resumes anything.

The revert window

It is a separate decision, and does not follow from where the copy ran. Both engines reach cutover holding two tables: the new one, about to take traffic, and the original, renamed aside. Spirit drops the original as soon as the swap lands, so by the time the apply reports success there is nothing to go back to. Vitess keeps it for a set period and offers an operation that swaps it back. That period is the revert window, and skip-revert ends it early. What separates the two is which table the engine chooses to keep, not where the change ran.

Direct execution

This is a third path, MySQL only, and it is deliberately bounded. Some statements can never run through a copy: dropping a primary key and adding a foreign key are the usual examples. By default they run as ordinary MySQL DDL when the table holds at most 100MiB of data and indexes, and block the apply above that. An operator can replace that policy server-wide or per environment, bounding it by row count or by bytes instead, or turn it off so those statements always block. The plan comment discloses each statement that will run this way.

What runs then is not an online change. It is synchronous, it blocks writes to the table for its full duration, nothing throttles it, and nothing checkpoints it. The size bound in the policy is what bounds that outage, since how long the table is blocked scales with its size. The other bound is on the way in: native DDL queues on the table's metadata lock behind any open transaction that has touched it, and everything arriving after queues behind the DDL, so a statement that cannot take the lock quickly stalls all traffic to the table rather than just waiting. Direct statements run with a short lock acquisition timeout and kill the transactions blocking the lock, as Spirit does for its own DDL; a blocker that is unsafe to kill (an explicit LOCK TABLES, or a very large transaction) fails the apply fast instead. What the policy replaces is worse: someone running the same statement by hand against the database, with no plan, no audit trail, and no size limit. Vitess is excluded by design, because raw DDL sent to vtgate would bypass the online DDL machinery that engine exists to use. direct-execution.md covers the gate in full.

PostgreSQL today

pg-sprite does not copy yet. Copy and swap is on its roadmap, and it will arrive from there rather than from SchemaBot: SchemaBot executes the statement shapes the pinned pg-sprite supports, so its plan and apply gates widen when the pin moves. Until then, every statement runs as its own PostgreSQL transaction that either commits or fails.

Most of what the PostgreSQL column is missing follows from that, rather than from anything permanent about the engine. The control operations arrive with the copy rather than before it, because with no long-running copy there is nothing to pause and no cutover to run. revert is the exception: it needs the engine to keep the pre-cutover table, which is the retention decision described above, and it is not on the PostgreSQL roadmap today.

Until the copy lands, a PostgreSQL change is kept safe by bounding work rather than pacing it. Only a small set of statement shapes is allowed at all, which is why a DROP TABLE never reaches the database. A statement the planner predicts will rewrite the table is blocked at plan time, whatever the table's size, and any other ALTER TABLE is refused above the configured table size limit unless it changes only the catalog (see Catalog-only changes). Below it, the bounded attempt described above is what stands in for a copy: the change is tried once, and if the prediction was wrong and it does rewrite, its own budget cancels it rather than letting it hold a lock. Some statements skip the gamble because PostgreSQL has a genuinely online form of them, and the planner substitutes it: an index build becomes CREATE INDEX CONCURRENTLY, and a constraint is added NOT VALID and then validated. The constraint steps still sit under the size limit, which is checked once at plan time and again in the session that executes, so a table that grew past the limit in between is refused rather than run. CREATE INDEX CONCURRENTLY is exempt from the size limit and is bounded by its own duration budget instead. postgresql.md has the full boundary and is worth reading before you point SchemaBot at a PostgreSQL database; it tracks the engine more closely than this page does.

What GA, beta, and alpha mean

Every engine in the README carries a badge: GA, beta, or alpha. The badge tells you how much of your schema that engine can change today. It is not a safety rating. At every level, an engine refuses a change it cannot run safely and tells you why, rather than running it anyway.

  • GA engines can change any table, however large, and keep you in control while a change runs. The two requirements below spell out what that takes.
  • Beta engines handle a clear, documented set of changes. Anything outside that set is refused with the reason, and most of it is blocked when you plan it, so you find out on the pull request rather than in production. The engine's guide lists what is not GA yet, including the checks that can only run once the change does.
  • Alpha engines are experimental and still being built. Expect significant changes between releases, both in what they can do and in how they work. Their guide may not list every gap yet, so read it before you rely on one.

Below GA, an engine is narrower, not looser. It runs fewer kinds of change and offers fewer controls once a change is running, but whatever it does run follows the same safety rules as every other engine. Those rules live in invariants.md, and most of them have nothing to do with engines.

Online DDL. An engine that can only run what the database does natively cannot change a large table at all, so the harder half of a real schema gets blocked instead of applied. Falling back to a copy is what lets an engine handle a whole schema rather than the easy parts of one.

A lever over a change that is already in flight. A copy on a large table can run for days or weeks, and an engine that can begin one but not act on one leaves the operator with a process they can only wait out. At minimum they must be able to take the load off the database, hold the change short of its swap and trigger that swap when they choose (deferred cutover), and abandon the change (cancel).

Which verbs deliver that varies, and the bar is the ability rather than a particular verb. Spirit pauses and resumes; the PlanetScale engine cannot pause at all, so cancel is how a change gets off a database there. What GA requires is that the lever exists and that the operator is told plainly what it did, never that every engine implements the same verbs the same way.

revert and skip-revert are deliberately not on the list. They depend on the engine keeping the pre-cutover table, which is a choice about retention rather than a measure of maturity. The MySQL engine is GA without them.

Everything else in the matrix is a difference rather than a gap. Adaptive pacing and a drop quarantine each make an engine better in their own way, and an engine without one is not below the bar. Direct execution says nothing about maturity in either direction: it is a size-bounded escape hatch for statements no copy can run, and the engine that lacks it lacks it on purpose.

Load management

Only a copy has a rate to manage. The two engines that copy both watch live signals from the target and back off on their own; the third has no copy and bounds its statements instead. In every case the mechanism belongs to the engine, not to SchemaBot.

What differs between the two that copy is what backing off does. Put the same pressure on the database and each answers differently:

                             pressure        pressure
                              starts           eases
                                 v               v
   Spirit          ##############=======---------=======##############
   (paces)                       slows its own copy down, then speeds it back up

   PlanetScale     ############## # # #   #  #  # # # # ##############
   (gates)                       same speed, allowed through less often

   pg-sprite       ##############X
   (budget)                      cancelled at its budget and rolled back

   Time runs left to right. # is copying, = and - are copying more
   slowly, blank is waiting, X is the change ending.

Spirit changes the size of the work. Vitess keeps the work the same size and changes how often it is let through. Averaged over a minute the two look similar, which is the point: neither is the crude one. pg-sprite is the one that is genuinely different, because it has no copy to hold back and stops the change instead.

Spirit throttles automatically. It watches live signals from the target database, backs off when they show pressure, and reports both the throttle and its reason through progress, so a throttled change reads as throttled in the PR comment and the CLI rather than just as slow. On Aurora it also has signals that are continuous rather than a simple stop or go, and it steers on those: it adjusts its own chunk sizes and write concurrency to match how the database is responding, easing off under load and taking more headroom when there is some. Not every signal suits that. Replication lag deliberately does not, because lag is a budget to stay inside rather than a dial to optimize, and steering on it would leave replicas permanently behind.

Vitess gates rather than paces. Its throttler also watches live signals: replication lag by default, and, where configured, running threads, load average, InnoDB history list length, or a custom query. Each is a threshold, and a metric over its threshold makes the throttler unsatisfied.

The copy consults it constantly. VReplication asks before each batch, and an unsatisfied answer means that batch does not go: it waits a fraction of a second and asks again, over and over, until the answer comes back yes. So the copy is not slowed down so much as let through less often, and the rate an operator observes is the fraction of those checks that pass. It also asks as a declared background workload, which is what puts it behind production traffic and alongside the cluster's other background work rather than in competition with it.

Sitting over that is a throttle ratio an operator can set on a running deploy request, and it works the way the gate does: the ratio is the probability that any given check is refused, so a ratio held at three quarters lets roughly one batch in four through. That is the lever to reach for when a deploy request is competing with live traffic, and unlike the signal thresholds it is a deliberate choice rather than a reaction. Both the signal thresholds and the ratio live on the PlanetScale side, and SchemaBot neither sets them nor surfaces them: Vitess publishes a throttle ratio, a last-throttled time, and a throttle reason per shard, and SchemaBot's progress reads none of them. So a throttled deploy request reads in SchemaBot as a copy that is going slowly, and the reason for it is in PlanetScale. That is the one place a Spirit change is better instrumented than a Vitess one, since Spirit surfaces both the throttle and its cause. PlanetScale documents the controls in Throttling deploy requests.

pg-sprite has nothing to pace yet. A throttle governs a copy, and there is no copy. What stands in its place is the budget on each statement: a lock timeout and a statement timeout, with bounded retries when it hits contention. A statement that runs past its budget is cancelled and rolled back rather than slowed down, so a change that turns out to be expensive is stopped instead of allowed to drag on holding a lock. That is a harder edge than a throttle, and deliberately so while the only thing a PostgreSQL change can do is run to completion. Throttling arrives with the copy, watching read-replica lag and replication slot lag.

None of this is a promise about your workload. Capacity you are already using is capacity the change will compete for, and the protection you get is the engine's, not SchemaBot's. For MySQL, throttling explains each Spirit throttle signal and what a sustained one means.

Dropped tables

Where a DROP TABLE can run at all, it needs explicit approval first, and that part always holds (RV-3). What happens to the data afterwards depends on the engine.

  • Spirit can quarantine the table instead of dropping it, renaming it into a holding area with a timestamp. This is opt-in and off unless someone enables it in server config, so on an unconfigured deployment the drop runs and the data is gone immediately. Where it is enabled, the table is held until it ages out and is then dropped for real. See pending-drops.md.
  • PlanetScale has no separate mechanism. A dropped table is recoverable because the drop can be reverted like any other deploy request, so the recovery window is the revert window, and it ends the same way: once the window expires, the table is purged.
  • pg-sprite does not run drops at all. DROP TABLE is outside the statement shapes it accepts, so the plan is blocked and the table stays where it is. That is a narrow engine rather than a safety feature, and it will stop being true once the shape is accepted.

So two of the three give you a window, and both windows close. None of this is a backup system. The approval gate is the protection to rely on. The window is a chance to notice a mistake, not a place to keep data.

Reading further

  • invariants.md for what holds regardless of engine, including what SchemaBot's guarantees deliberately do not cover.
  • postgresql.md for the full PostgreSQL support envelope: which plans are blocked, which statements are admitted, and how each refusal is reported.
  • vitess.md for the PlanetScale service token permissions the Vitess engine needs.
  • mysql.md for what each Spirit throttle signal means when you see one.
  • pending-drops.md for the quarantine lifecycle.
  • direct-execution.md for when a change runs directly instead of through a copy.