Open shlomi-noach opened 4 years ago
Logic for auto-retrying a migration: https://github.com/vitessio/vitess/pull/6901
https://github.com/vitessio/vitess/pull/7083 supports CREATE
and DROP
statements in ApplySchema
to run as online DDL.
ddl_type
(CREATE
, ALTER
, DROP
) and which should show up on vtctl OnlineDDL show
Once https://github.com/vitessio/vitess/pull/7083 and https://github.com/vitessio/vitess/pull/7097 are merged:
when ddl_strategy
is an online strategy, analyze a DROP TABLE
statement to:
DROP TABLE
statement can indicate multiple tables)RENAME TABLE
statement, renaming into a HOLD
gc state with 48 hour ETAHOLD
even if ETA is unmet, if table_gc_lifecycle
does not include HOLD
vtctl OnlineDDL <keyspace> show <context>
, to fetch status of migrations wit ha specific context, as added in #7082
Edit: see https://github.com/vitessio/vitess/pull/7145 for suggested solutionCREATE INDEX
statements as online DDL, and convert them to ALTER TABLE
syntax -- required by gh-ost
.At this time I have clarity as for how this will look like.
On one hand, we will go full native and reuse Vitess existing mechanisms. On the other hand, we break apart from the existing flow in multiple ways.
POC is in #7419 . It is just the beginning of what online DDL via vreplication will look like -- but already has the initial implementation running.
Some design bulletpoints:
gh-ost
and pt-osc
, a shard's primary table has the independece to schedule the next migration, run that migration, potentially cancel or retry it, and follow it to completion. This means no vtctl
, no wrangler
MoveTables
we can go as far as set routing rules for new queries to route to the target
tables. In a schema migration, we want to replace the original table (via RENAME TABLE
). We will do this underneath the feet of VReplication.gh-ost
or pt-osc
, vreplication migrations can natively survive a failover (in fact, this will be one of the more important advantages of migrations/vreplication); this calls for some redesign in onlineddl.Executor
gh-ost
. Some of it is redundant, and will be cleaned up. Some of it overlaps with Vitess functionality (parsing) and will be replaces. But for now we know it's stable and working.The flow for starting a vreplication based schema migration from tabletserver is:
LIKE
the original tableALTER TABLE
statement onto the empty tablesource
filter query that only selects relevant columns, and takes care of column renames and of generated columns.onlineddl.Executor
to keep track of vreplication stream liveness by looking at _vt.vreplication
entry.The flow is:
Tablet
ShardInfo
onlineddl.Executor
)More to come.
It should be possible to ReloadTable
, like ReloadSchema
but for a single table. This is desired for online DDL. Reloading an entire schema takes time and we cannot expect to accomplish it within the timeframe of a cut-over. But reloading a single table should be just fine.
ReloadTable
Revert for Online DDL is now available (per PR review) via https://github.com/vitessio/vitess/pull/7478
Declarative schema changes via #7725
https://github.com/vitessio/vitess/pull/7785 begins the work to move away from topo
in online DDL. Meaning DDLs, coming from either VTGate
or vtctl
, are sent directly to the relevant shards (primary tablets on those shards).
This has to be backwards compatible. The timeline is as follows:
v10
RC is already out and #7785 is unmerged yetv11
will have the new code, and default to use of topo
vtctl OnlineDDL revert
(replaced by ApplySchema -sql 'revert vitess_migration ...
)vtctl VExec
v12
will default to bypass topo
, and in fact not allow sending requests to topo
v13
removes all topo
related and VExec
related codeRoadmap to replacing online
strategy with vitess
(better and unambiguous name):
vitess
strategy. This PR is created in v13
RConline
submission into vitess
online
in the backend (the text online
will just not exist there anymore)online
submission (though we can also keep it supported forever)https://github.com/vitessio/vitess/pull/9755 offers query buffering for vitess
migration cut-over phase. Still a known race condition, to be handled by a different PR.
We consider Online DDL to be production ready and generally available, and remove the "Experimental" notice. See https://github.com/vitessio/vitess/pull/10310 and https://github.com/vitessio/website/pull/1020
Design for fast REVERT
of fast RANGE PARTITION
operations: https://github.com/vitessio/vitess/issues/10317
This issue will be the tracking space for all things vitess Online DDL. Note that this issue is created after some substantial work is done:
release-8.0
6547 served as a long running tracking point; pasting some of #6547 content here for background, purpose and intentions.
TL;DR
Automate away all the complexity of schema migrations. Users issue:
or
(syntax subject to change, see #6782 )
and vitess will schedule an online schema change operation to run on all relevant shards, then proceed to apply the change via
gh-ost
on all shards.The ALTER TABLE problem
First, to iterate the problem: schema changes have always been a problem with MySQL; a straight
ALTER
is a blocking operation; aONLINE ALTER
is only "online" on the master/primary, but is effectively blocking on replicas. Online schema change tools likept-online-schema-change
andgh-ost
overcome these limitations by emulating anALTER
on a "ghost" table, which is populated from the original table, then swapped in its space.Traditionally, online schema changes are considered to be "risky". Trigger based migrations add significant load onto the master server, and their cut-over phase is known to be a dangerous point.
gh-ost
was created at GitHub to address these concerns, and successfully eliminated concerns for operational risks: withgh-ost
the load on the master is low, and well controlled, and the cut-over phase is known to cause no locking issues.gh-ost
comes with different risks: it applies data changes programmatically, thus the issue of data integrity is of utmost importance. Another note of concern is data traffic: going out from MySQL intogh-ost
and back into MySQL (as opposed to all-in MySQL inpt-online-schema-change
).This way or the other, running an online schema change is typically a manual operation. A human being will schedule the migration, kick it running, monitor it, possibly cut-over. In a sharded environment, a developer's request to
ALTER TABLE
explodes ton
different migrations, each needs to be scheduled, kicked, monitored & tracked.Sharded environments are obviously common for
vitess
users and so these users feel the pain more than others.Schema migration cycle & steps
Schema management is a process that begins with the user designing a schema change, and ends with the schema being applied in production. This is a breakdown of schema management steps as I know them:
ALTER TABLE
orpt-online-schema-change
orgh-ost
command)What we propose to address
Vitess's architecture uniquely positions it to be able to automate away much of the process. Specifically:
ALTER TABLE
statement into agh-ost
/pt-osc
invocation is super useful if done by vitess, since vitess can not only validate schema/params, but also can provide credentials, apply throttling logic, can instructgh-ost
on how to communicate progress via hooks, etc.vitess
just knows where the table is located. It knows if the schema is sharded. It knows who the shards are, who the shards masters are. It knows where to rungh-ost
. Last,vitess
can tell us which replicas we can use for throttling.vttablet
is the ideal entity to run a migration; can read instructions fromtopo
server and can write progress totopo
server.vitess
is aware of possible master failovers and can request a re-execute is a migration is so interrupted mid process.vtctld
API can offer endpoints to track status of a migration (e.g. "in progress on-80
, in queue on80-
"). It may offer progress pct and ETA.gh-ost
, the cut-over phase is safe to automate away. If running a migration during a resharding operation, then we may need to coordinate cut-over between upstream and downstream migrations.vttablet
runs a table lifecycle service (aka garbage collector) to clean up those tables.