vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.42k stars 2.08k forks source link

Online DDL: tracking issue #6926

Open shlomi-noach opened 3 years ago

shlomi-noach commented 3 years ago

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:

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:

alter with 'gh-ost' table example modify id bigint not null;

alter with 'pt-osc' table example modify id bigint not null

or

$ vtctl -topo_implementation etcd2 -topo_global_server_address localhost:2379 -topo_global_root /vitess/global \
    ApplySchema -sql "alter with 'gh-ost' table example modify id bigint unsigned not null" commerce

$ vtctl -topo_implementation etcd2 -topo_global_server_address localhost:2379 -topo_global_root /vitess/global \
    ApplySchema -sql "alter with 'pt-osc' table example modify id bigint unsigned not null" commerce

(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; a ONLINE ALTER is only "online" on the master/primary, but is effectively blocking on replicas. Online schema change tools like pt-online-schema-change and gh-ost overcome these limitations by emulating an ALTER 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: with gh-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 into gh-ost and back into MySQL (as opposed to all-in MySQL in pt-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 to n 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:

  1. Design code
  2. Publish changes (pull request)
  3. Review
  4. Formalize migration command (the specific ALTER TABLE or pt-online-schema-change or gh-ost command)
  5. Locate: where in production should this migration run?
  6. Schedule
  7. Execute
  8. Audit/monitor
  9. Cut-over/complete
  10. Cleanup
  11. Notify user
  12. Deploy & merge

What we propose to address

Vitess's architecture uniquely positions it to be able to automate away much of the process. Specifically:


shlomi-noach commented 3 years ago

Logic for auto-retrying a migration: https://github.com/vitessio/vitess/pull/6901

Docs in https://github.com/vitessio/website/pull/571

shlomi-noach commented 3 years ago

https://github.com/vitessio/vitess/pull/7083 supports CREATE and DROP statements in ApplySchema to run as online DDL.

shlomi-noach commented 3 years ago

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:

shlomi-noach commented 3 years ago
shlomi-noach commented 3 years ago
shlomi-noach commented 3 years ago

Online DDL via VReplication

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:

Starting a vreplication schema migration

The flow for starting a vreplication based schema migration from tabletserver is:

tracking a running migration

cutting over a vreplication migration

The flow is:

More to come.

shlomi-noach commented 3 years ago

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.

shlomi-noach commented 3 years ago

Revert for Online DDL is now available (per PR review) via https://github.com/vitessio/vitess/pull/7478

shlomi-noach commented 3 years ago

Declarative schema changes via #7725

shlomi-noach commented 3 years ago

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:

shlomi-noach commented 2 years ago

Roadmap to replacing online strategy with vitess (better and unambiguous name):

shlomi-noach commented 2 years ago

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.

shlomi-noach commented 2 years ago

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

shlomi-noach commented 2 years ago

Design for fast REVERT of fast RANGE PARTITION operations: https://github.com/vitessio/vitess/issues/10317