Applying, auditing, and controlling Online DDL

Vitess provides two interfaces to interacting with Online DDL:

  • SQL commands, via VTGate
  • Command line interface, via vtctl

Supported interactions are:

Running migrations

To run a managed schema migration, you should:

  • Formulate your DDLs (CREATE, ALTER, DROP) queries
  • Choose a ddl_strategy

When the user submits an online DDL, Vitess responds with a UUID, a job Id used to later track or control the migration. The migration does not start immediately. It is queued at the tablets and executed at some point in the future.

Via VTGate/SQL

  1. mysql> set @@ddl_strategy='vitess';
  2. mysql> alter table corder add column ts timestamp not null default current_timestamp;
  3. +--------------------------------------+
  4. | uuid |
  5. +--------------------------------------+
  6. | bf4598ab_8d55_11eb_815f_f875a4d24e90 |
  7. +--------------------------------------+
  8. mysql> drop table customer;
  9. +--------------------------------------+
  10. | uuid |
  11. +--------------------------------------+
  12. | 6848c1a4_8d57_11eb_815f_f875a4d24e90 |
  13. +--------------------------------------+
  • @@ddl_strategy behaves like a MySQL session variable, though is only recognized by VTGate. Setting @@ddl_strategy only applies to that same connection and does not affect other connections. The strategy applies to all migrations executed in that session. You may subsequently set @@ddl_strategy to different value.
  • If you run vtgate without --ddl_strategy, then @@ddl_strategy defaults to 'direct', which implies schema migrations are synchronous. You will need to set @@ddl_strategy='vitess' to run followup ALTER TABLE statements via Vitess.
  • If you run vtgate --ddl_strategy "vitess", then @@ddl_strategy defaults to 'vitess' in each new session. Any ALTER TABLE will run via Vitess online DDL. You may set @@ddl_strategy='gh-ost' to make migrations run through gh-ost, or set @@ddl_strategy='direct' to run migrations synchronously.

Via vtctldclient

You may use vtctldclient to apply schema changes. The ApplySchema command supports both synchronous and online schema migrations. To run an online schema migration you will supply the --ddl-strategy command line flag:

  1. $ vtctldclient ApplySchema --ddl-strategy="vitess" --sql "alter table product add column ts_entry TIMESTAMP NOT NULL" commerce
  2. c26f3b5e_6b50_11ee_808b_0a43f95f28a3

You my run multiple migrations withing the same ApplySchema command:

  1. $ vtctldclient ApplySchema --ddl-strategy="vitess" --sql "alter table corder modify price bigint unsigned default null; create table sample (id int primary key); drop table if exists some_other_table" customer
  2. d729b47e_6b52_11ee_808b_0a43f95f28a3
  3. d72b644f_6b52_11ee_808b_0a43f95f28a3
  4. d72d230d_6b52_11ee_808b_0a43f95f28a3

ApplySchema accepts the following flags:

  • --ddl-strategy: by default migrations run directly via MySQL standard DDL (aka direct). This flag must be aupplied to indicate an online strategy. See also DDL strategies and ddl_strategy flags.
  • --migration-context <unique-value>: all migrations in a ApplySchema command are logically grouped via a unique context. A unique value will be supplied automatically. The user may choose to supply their own value, and it’s their responsibility to provide with a unique value. Any string format is accepted. The context can then be used to search for migrations, via SHOW VITESS_MIGRATIONS LIKE '<the-context>'. It is visible in SHOW VITESS_MIGRATIONS ... output as the migration_context column.

Tracking migrations

You may track the status of a single or of multiple migrations. Since migrations run asycnhronously, it is the user’s responsibility to audit the progress and state of submitted migrations. Users are likely to want to know when a migration is complete (or failed) so as to be able to deploy code changes or run other operations.

Common patterns are:

  • Show state of a specific migration
  • Show all running, complete or failed migrations
  • Show recent migrations
  • Show migrations ordered by most-recent first.
  • Show n number of migrations, skipping m rows.

Via VTGate/SQL

Examples for a single shard cluster:

  1. $ mysql commerce
  1. mysql> show vitess_migrations like 'c26f3b5e_6b50_11ee_808b_0a43f95f28a3' \G
  2. *************************** 1. row ***************************
  3. id: 1
  4. migration_uuid: c26f3b5e_6b50_11ee_808b_0a43f95f28a3
  5. keyspace: commerce
  6. shard: 0
  7. mysql_schema: vt_commerce
  8. mysql_table: product
  9. migration_statement: alter table product add column ts_entry TIMESTAMP not null
  10. strategy: vitess
  11. options:
  12. added_timestamp: 2023-10-15 11:48:29
  13. requested_timestamp: 2023-10-15 11:48:30
  14. ready_timestamp: NULL
  15. started_timestamp: 2023-10-15 11:48:31
  16. liveness_timestamp: 2023-10-15 11:48:37
  17. completed_timestamp: 2023-10-15 11:48:38.232430
  18. cleanup_timestamp: NULL
  19. migration_status: complete
  20. log_path:
  21. artifacts: _c26f3b5e_6b50_11ee_808b_0a43f95f28a3_20231015114830_vrepl,
  22. retries: 0
  23. tablet: zone1-0000000100
  24. tablet_failure: 0
  25. progress: 100
  26. migration_context: vtctl:c26e658d-6b50-11ee-808b-0a43f95f28a3
  27. ddl_action: alter
  28. message:
  29. eta_seconds: 0
  30. rows_copied: 0
  31. table_rows: 0
  32. added_unique_keys: 0
  33. removed_unique_keys: 0
  34. log_file:
  35. retain_artifacts_seconds: 86400
  36. postpone_completion: 0
  37. removed_unique_key_names:
  38. dropped_no_default_column_names:
  39. expanded_column_names:
  40. revertible_notes:
  41. allow_concurrent: 0
  42. reverted_uuid:
  43. is_view: 0
  44. ready_to_complete: 1
  45. vitess_liveness_indicator: 1697370514
  46. user_throttle_ratio: 0
  47. special_plan:
  48. last_throttled_timestamp: NULL
  49. component_throttled:
  50. cancelled_timestamp: NULL
  51. postpone_launch: 0
  52. stage: re-enabling writes
  53. cutover_attempts: 1
  54. is_immediate_operation: 0
  55. reviewed_timestamp: 2023-10-15 11:48:31
  56. ready_to_complete_timestamp: 2023-10-15 11:48:35
  1. mysql> show vitess_migrations like 'complete' \G
  2. -- same output as above
  3. mysql> show vitess_migrations like 'failed' \G
  4. Empty set (0.01 sec)

Examples for a multi sharded cluster:

  1. $ mysql customer
  1. mysql> show vitess_migrations like 'complete';
  2. +----+--------------------------------------+----------+-------+--------------+------------------+---------------------------------------------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+----------------------------+-------------------+------------------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+--------------------------+---------------------+--------------------------+---------------------------------+-----------------------+-------------------------------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  3. | id | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | migration_status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | retain_artifacts_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  4. +----+--------------------------------------+----------+-------+--------------+------------------+---------------------------------------------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+----------------------------+-------------------+------------------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+--------------------------+---------------------+--------------------------+---------------------------------+-----------------------+-------------------------------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  5. | 7 | d729b47e_6b52_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | corder | alter table corder modify column price bigint unsigned default null | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | NULL | 2023-10-15 12:03:25 | 2023-10-15 12:03:31 | 2023-10-15 12:03:32.012778 | NULL | complete | | _d729b47e_6b52_11ee_808b_0a43f95f28a3_20231015120324_vrepl, | 0 | zone1-0000000401 | 0 | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | 0 | | | `price` | column price: increased NUMERIC_PRECISION | 0 | | 0 | 1 | 1697371408 | 0 | | NULL | | NULL | 0 | re-enabling writes | 1 | 0 | 2023-10-15 12:03:25 | 2023-10-15 12:03:29 |
  6. | 8 | d72b644f_6b52_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | sample | create table sample (
  7. id int primary key
  8. ) | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | NULL | 2023-10-15 12:03:34 | 2023-10-15 12:03:34 | 2023-10-15 12:03:33.701212 | NULL | complete | | _vt_HOLD_dd2164646b5211eeba7c0a43f95f28a3_20231016120333, | 0 | zone1-0000000401 | 0 | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | create | | 0 | 0 | 0 | 0 | 0 | | 86400 | 0 | | | | | 0 | | 0 | 1 | 0 | 0 | | NULL | | NULL | 0 | | 0 | 1 | 2023-10-15 12:03:25 | 2023-10-15 12:03:25 |
  9. | 9 | d72d230d_6b52_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | some_other_table | drop table if exists some_other_table | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | NULL | 2023-10-15 12:03:35 | 2023-10-15 12:03:35 | 2023-10-15 12:03:34.710144 | NULL | complete | | | 0 | zone1-0000000401 | 0 | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | drop | | 0 | 0 | 0 | 0 | 0 | | 86400 | 0 | | | | | 0 | | 0 | 1 | 0 | 0 | | NULL | | NULL | 0 | | 0 | 1 | 2023-10-15 12:03:25 | 2023-10-15 12:03:25 |
  10. | 7 | d729b47e_6b52_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | corder | alter table corder modify column price bigint unsigned default null | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | NULL | 2023-10-15 12:03:25 | 2023-10-15 12:03:31 | 2023-10-15 12:03:32.034889 | NULL | complete | | _d729b47e_6b52_11ee_808b_0a43f95f28a3_20231015120324_vrepl, | 0 | zone1-0000000301 | 0 | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | 0 | | | `price` | column price: increased NUMERIC_PRECISION | 0 | | 0 | 1 | 1697371408 | 0 | | NULL | | NULL | 0 | re-enabling writes | 1 | 0 | 2023-10-15 12:03:25 | 2023-10-15 12:03:29 |
  11. | 8 | d72b644f_6b52_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | sample | create table sample (
  12. id int primary key
  13. ) | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | NULL | 2023-10-15 12:03:34 | 2023-10-15 12:03:34 | 2023-10-15 12:03:33.701214 | NULL | complete | | _vt_HOLD_dd21768e6b5211ee86cc0a43f95f28a3_20231016120333, | 0 | zone1-0000000301 | 0 | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | create | | 0 | 0 | 0 | 0 | 0 | | 86400 | 0 | | | | | 0 | | 0 | 1 | 0 | 0 | | NULL | | NULL | 0 | | 0 | 1 | 2023-10-15 12:03:25 | 2023-10-15 12:03:25 |
  14. | 9 | d72d230d_6b52_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | some_other_table | drop table if exists some_other_table | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | NULL | 2023-10-15 12:03:35 | 2023-10-15 12:03:35 | 2023-10-15 12:03:34.710280 | NULL | complete | | | 0 | zone1-0000000301 | 0 | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | drop | | 0 | 0 | 0 | 0 | 0 | | 86400 | 0 | | | | | 0 | | 0 | 1 | 0 | 0 | | NULL | | NULL | 0 | | 0 | 1 | 2023-10-15 12:03:25 | 2023-10-15 12:03:25 |
  15. +----+--------------------------------------+----------+-------+--------------+------------------+---------------------------------------------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+----------------------------+-------------------+------------------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+--------------------------+---------------------+--------------------------+---------------------------------+-----------------------+-------------------------------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  1. $ vtctldclient OnlineDDL show customer cancelled --limit 1
  2. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+-------------------+--------------------+---------------------+-------------------+-----------+----------+-----------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+--------------------+-----------------------------+
  3. | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | artifact_retention_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  4. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+-------------------+--------------------+---------------------+-------------------+-----------+----------+-----------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+--------------------+-----------------------------+
  5. | c919678a_6b50_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | product | alter table product modify | vitess | | 2023-10-15 11:48:41 | 2023-10-15 11:48:41 | | | | 2023-10-15 12:00:26 | | cancelled | | | 0 | zone1-0000000301 | | 0 | vtctl:c91857d2-6b50-11ee-808b-0a43f95f28a3 | alter | CANCEL ALL issued by user | -1 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 0 | 0 | | | | | | | 0 | | | |
  6. | | | | | | column price bigint unsigned | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  7. | | | | | | default null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  8. | c919678a_6b50_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | product | alter table product modify | vitess | | 2023-10-15 11:48:41 | 2023-10-15 11:48:41 | | | | 2023-10-15 12:00:26 | | cancelled | | | 0 | zone1-0000000401 | | 0 | vtctl:c91857d2-6b50-11ee-808b-0a43f95f28a3 | alter | CANCEL ALL issued by user | -1 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 0 | 0 | | | | | | | 0 | | | |
  9. | | | | | | column price bigint unsigned | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  10. | | | | | | default null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  11. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+-------------------+--------------------+---------------------+-------------------+-----------+----------+-----------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+--------------------+-----------------------------+

Note in the above each migration appears twice. For example, d729b47e_6b52_11ee_808b_0a43f95f28a3 appears once for shard -80 and once for shard 80-. The two migrations run independently on each shard. It is possible to coordinate a near-atomic cut-over, aka gated cut-over.

  • show vitess_migrations shows the entire history of migrations.
  • show vitess_migrations like ... filters migrations by migration_uuid, or migration_context, or migration_status.
  • show vitess_migrations where ... lets the user specify arbitrary conditions.
  • All commands return results for the keyspace (schema) in use.

Via vtctldclient

  1. $ vtctldclient OnlineDDL show customer d729b47e_6b52_11ee_808b_0a43f95f28a3
  2. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+--------------------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  3. | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | artifact_retention_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  4. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+--------------------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  5. | d729b47e_6b52_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | corder | alter table corder modify | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | | 2023-10-15 12:03:25 | 2023-10-15 12:03:31 | 2023-10-15 12:03:32 | | complete | | _d729b47e_6b52_11ee_808b_0a43f95f28a3_20231015120324_vrepl, | 0 | zone1-0000000401 | | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | `price` | column price: increased | | | | | 1697371408 | 0 | | | | | | re-enabling writes | 1 | | 2023-10-15 12:03:25 | 2023-10-15 12:03:29 |
  6. | | | | | | column price bigint unsigned | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NUMERIC_PRECISION | | | | | | | | | | | | | | | | |
  7. | | | | | | default null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  8. | d729b47e_6b52_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | corder | alter table corder modify | vitess | | 2023-10-15 12:03:23 | 2023-10-15 12:03:24 | | 2023-10-15 12:03:25 | 2023-10-15 12:03:31 | 2023-10-15 12:03:32 | | complete | | _d729b47e_6b52_11ee_808b_0a43f95f28a3_20231015120324_vrepl, | 0 | zone1-0000000301 | | 100 | vtctl:d7288b41-6b52-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | `price` | column price: increased | | | | | 1697371408 | 0 | | | | | | re-enabling writes | 1 | | 2023-10-15 12:03:25 | 2023-10-15 12:03:29 |
  9. | | | | | | column price bigint unsigned | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NUMERIC_PRECISION | | | | | | | | | | | | | | | | |
  10. | | | | | | default null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  11. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+--------------------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  12. $ vtctldclient OnlineDDL show commerce recent
  13. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  14. | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | artifact_retention_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  15. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  16. | c26f3b5e_6b50_11ee_808b_0a43f95f28a3 | commerce | 0 | vt_commerce | product | alter table product add column | vitess | | 2023-10-15 11:48:29 | 2023-10-15 11:48:30 | | 2023-10-15 11:48:31 | 2023-10-15 11:48:37 | 2023-10-15 11:48:38 | | complete | | _c26f3b5e_6b50_11ee_808b_0a43f95f28a3_20231015114830_vrepl, | 0 | zone1-0000000100 | | 100 | vtctl:c26e658d-6b50-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 1697370514 | 0 | | | | | | re-enabling writes | 1 | | 2023-10-15 11:48:31 | 2023-10-15 11:48:35 |
  17. | | | | | | ts_entry TIMESTAMP not null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  18. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+--------------------+------------------+------------------------+---------------------+-----------------------------+
  19. $ vtctldclient OnlineDDL show customer cancelled --limit 1
  20. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+-------------------+--------------------+---------------------+-------------------+-----------+----------+-----------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+--------------------+-----------------------------+
  21. | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | artifact_retention_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  22. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+-------------------+--------------------+---------------------+-------------------+-----------+----------+-----------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+--------------------+-----------------------------+
  23. | c919678a_6b50_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | product | alter table product modify | vitess | | 2023-10-15 11:48:41 | 2023-10-15 11:48:41 | | | | 2023-10-15 12:00:26 | | cancelled | | | 0 | zone1-0000000301 | | 0 | vtctl:c91857d2-6b50-11ee-808b-0a43f95f28a3 | alter | CANCEL ALL issued by user | -1 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 0 | 0 | | | | | | | 0 | | | |
  24. | | | | | | column price bigint unsigned | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  25. | | | | | | default null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  26. | c919678a_6b50_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | product | alter table product modify | vitess | | 2023-10-15 11:48:41 | 2023-10-15 11:48:41 | | | | 2023-10-15 12:00:26 | | cancelled | | | 0 | zone1-0000000401 | | 0 | vtctl:c91857d2-6b50-11ee-808b-0a43f95f28a3 | alter | CANCEL ALL issued by user | -1 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 0 | 0 | | | | | | | 0 | | | |
  27. | | | | | | column price bigint unsigned | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  28. | | | | | | default null | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  29. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+-------------------+--------------------+---------------------+-------------------+-----------+----------+-----------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+--------------------+-----------------------------+

The syntax for tracking migrations is:

  1. vtctldclient OnlineDDL show <keyspace> <all|recent|queued|ready|running|complete|failed|cancelled|<migration uuid>|<migration context>>

Launching a migration

Migrations submitted with --postpone-launch remain queued or ready until told to launch. The user may launch a specific migration or they may launch all postponed migrations:

Via VTGate/SQL

  1. mysql> alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' launch;
  2. Query OK, 1 row affected (0.01 sec)

or

  1. mysql> alter vitess_migration launch all;
  2. Query OK, 1 row affected (0.01 sec)

Via vtctldclient

Launch a specific migration:

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration '9e8a9249_3976_11ed_9442_0a43f95f28a3' launch" commerce

Or launch a specific migration on a specific shard:

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration '9e8a9249_3976_11ed_9442_0a43f95f28a3' launch vitess_shards '-40,40-80'" commerce

Or launch all:

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration launch all" commerce

Completing a migration

Migrations submitted with --postpone-completion remain ready or running until told to complete. The user may complete a specific migration or they may complete all postponed migrations:

Via VTGate/SQL

  1. mysql> alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' complete;
  2. Query OK, 1 row affected (0.01 sec)

or

  1. mysql> alter vitess_migration complete all;
  2. Query OK, 1 row affected (0.01 sec)

Via vtctldclient

Complete a specific migration:

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration '9e8a9249_3976_11ed_9442_0a43f95f28a3' complete" commerce

Or complete all:

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration complete all" commerce

Cancelling a migration

The user may cancel a migration, as follows:

  • If the migration hasn’t started yet (it is queued or ready), then it transitions into cancelled state and doesn’t get executed.
  • If the migration is running, then it is forcibly interrupted. The migration transitions to cancelled state.
  • In all other cases, cancelling a migration has no effect.

Via VTGate/SQL

In this illustrative flow we also glimpse into some further control over migrations.

  1. mysql> set @@ddl_strategy='vitess --postpone-completion';
  2. mysql> alter table product engine=innodb;
  3. +--------------------------------------+
  4. | uuid |
  5. +--------------------------------------+
  6. | f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3 |
  7. +--------------------------------------+
  8. mysql> show vitess_migrations like 'f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3' \G
  9. *************************** 1. row ***************************
  10. id: 3
  11. migration_uuid: f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3
  12. keyspace: commerce
  13. shard: 0
  14. mysql_schema: vt_commerce
  15. mysql_table: product
  16. migration_statement: alter table product engine innodb
  17. strategy: vitess
  18. options: --postpone-completion
  19. added_timestamp: 2023-10-15 12:18:40
  20. requested_timestamp: 2023-10-15 12:18:41
  21. ready_timestamp: NULL
  22. started_timestamp: 2023-10-15 12:18:42
  23. liveness_timestamp: 2023-10-15 12:18:52
  24. completed_timestamp: NULL
  25. cleanup_timestamp: NULL
  26. migration_status: running
  27. ...
  28. mysql> alter vitess_migration 'f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3' cancel;
  29. Query OK, 1 row affected (0.04 sec)
  30. mysql> show vitess_migrations like 'f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3' \G
  31. *************************** 1. row ***************************
  32. id: 3
  33. migration_uuid: f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3
  34. keyspace: commerce
  35. shard: 0
  36. mysql_schema: vt_commerce
  37. mysql_table: product
  38. migration_statement: alter table product engine innodb
  39. strategy: vitess
  40. options: --postpone-completion
  41. added_timestamp: 2023-10-15 12:18:40
  42. requested_timestamp: 2023-10-15 12:18:41
  43. ready_timestamp: NULL
  44. started_timestamp: 2023-10-15 12:18:42
  45. liveness_timestamp: 2023-10-15 12:19:02
  46. completed_timestamp: 2023-10-15 12:19:42.347196
  47. cleanup_timestamp: NULL
  48. migration_status: cancelled
  49. log_path:
  50. artifacts: _f9e4dbaa_6b54_11ee_b0cf_0a43f95f28a3_20231015121841_vrepl,
  51. retries: 0
  52. tablet: zone1-0000000100
  53. tablet_failure: 0
  54. progress: 100
  55. migration_context: vtgate:cc06e24a-6b54-11ee-b0cf-0a43f95f28a3
  56. ddl_action: alter
  57. message: CANCEL issued by user
  58. ...
  • alter vitess_migration ... cancel takes exactly one migration’s UUID.
  • alter vitess_migration cancel all takes no arguments and affects all pending migrations.
  • alter vitess_migration ... cancel or alter vitess_migration cancel all respond with number of affected migrations across all shards.

Via vtctldclient

Illustrating yet another flow where we can control the progress of migrations:

  1. $ vtctldclient UpdateThrottlerConfig --enable customer
  2. $ vtctldclient ApplySchema --sql "alter vitess_migration throttle all" customer
  3. $ vtctldclient ApplySchema --ddl-strategy="vitess" --sql "alter table corder engine=innodb" customer
  4. 075088b9_6b56_11ee_808b_0a43f95f28a3
  5. $ vtctldclient OnlineDDL show customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  6. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+---------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+---------------------+-----------------------------+
  7. | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | artifact_retention_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  8. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+---------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+---------------------+-----------------------------+
  9. | 075088b9_6b56_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | corder | alter table corder engine | vitess | | 2023-10-15 12:26:12 | 2023-10-15 12:26:13 | | 2023-10-15 12:26:14 | 2023-10-15 12:26:23 | | | running | | _075088b9_6b56_11ee_808b_0a43f95f28a3_20231015122613_vrepl, | 0 | zone1-0000000301 | | 100 | vtctl:074f5fd7-6b56-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 1697372782 | 1 | | 2023-10-15 12:26:22 | vcopier | | | | 0 | | 2023-10-15 12:26:14 | |
  10. | | | | | | innodb | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  11. | 075088b9_6b56_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | corder | alter table corder engine | vitess | | 2023-10-15 12:26:12 | 2023-10-15 12:26:13 | | 2023-10-15 12:26:14 | 2023-10-15 12:26:23 | | | running | | _075088b9_6b56_11ee_808b_0a43f95f28a3_20231015122613_vrepl, | 0 | zone1-0000000401 | | 100 | vtctl:074f5fd7-6b56-11ee-808b-0a43f95f28a3 | alter | | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 1697372782 | 1 | | 2023-10-15 12:26:22 | vcopier | | | | 0 | | 2023-10-15 12:26:14 | |
  12. | | | | | | innodb | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  13. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+---------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+---------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+---------------------+-----------------------------+
  14. $ vtctldclient OnlineDDL cancel customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  15. {
  16. "rows_affected_by_shard": {
  17. "-80": "1",
  18. "80-": "1"
  19. }
  20. }
  21. $ vtctldclient OnlineDDL show customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  22. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+-----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+-----------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+---------------------+-----------------------------+
  23. | migration_uuid | keyspace | shard | mysql_schema | mysql_table | migration_statement | strategy | options | added_timestamp | requested_timestamp | ready_timestamp | started_timestamp | liveness_timestamp | completed_timestamp | cleanup_timestamp | status | log_path | artifacts | retries | tablet | tablet_failure | progress | migration_context | ddl_action | message | eta_seconds | rows_copied | table_rows | added_unique_keys | removed_unique_keys | log_file | artifact_retention_seconds | postpone_completion | removed_unique_key_names | dropped_no_default_column_names | expanded_column_names | revertible_notes | allow_concurrent | reverted_uuid | is_view | ready_to_complete | vitess_liveness_indicator | user_throttle_ratio | special_plan | last_throttled_timestamp | component_throttled | cancelled_timestamp | postpone_launch | stage | cutover_attempts | is_immediate_operation | reviewed_timestamp | ready_to_complete_timestamp |
  24. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+-----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+-----------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+---------------------+-----------------------------+
  25. | 075088b9_6b56_11ee_808b_0a43f95f28a3 | customer | -80 | vt_customer | corder | alter table corder engine | vitess | | 2023-10-15 12:26:12 | 2023-10-15 12:26:13 | | 2023-10-15 12:26:14 | 2023-10-15 12:26:34 | 2023-10-15 12:26:54 | | cancelled | | _075088b9_6b56_11ee_808b_0a43f95f28a3_20231015122613_vrepl, | 0 | zone1-0000000301 | | 100 | vtctl:074f5fd7-6b56-11ee-808b-0a43f95f28a3 | alter | CANCEL issued by user | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 1697372793 | 1 | | 2023-10-15 12:26:33 | vcopier | | | | 0 | | 2023-10-15 12:26:14 | |
  26. | | | | | | innodb | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  27. | 075088b9_6b56_11ee_808b_0a43f95f28a3 | customer | 80- | vt_customer | corder | alter table corder engine | vitess | | 2023-10-15 12:26:12 | 2023-10-15 12:26:13 | | 2023-10-15 12:26:14 | 2023-10-15 12:26:34 | 2023-10-15 12:26:54 | | cancelled | | _075088b9_6b56_11ee_808b_0a43f95f28a3_20231015122613_vrepl, | 0 | zone1-0000000401 | | 100 | vtctl:074f5fd7-6b56-11ee-808b-0a43f95f28a3 | alter | CANCEL issued by user | 0 | 0 | 0 | 0 | 0 | | 86400 | | | | | | | | | | 1697372793 | 1 | | 2023-10-15 12:26:33 | vcopier | | | | 0 | | 2023-10-15 12:26:14 | |
  28. | | | | | | innodb | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  29. +--------------------------------------+----------+-------+--------------+-------------+--------------------------------+----------+---------+---------------------+---------------------+-----------------+---------------------+---------------------+---------------------+-------------------+-----------+----------+-------------------------------------------------------------+---------+------------------+----------------+----------+--------------------------------------------+------------+-----------------------+-------------+-------------+------------+-------------------+---------------------+----------+----------------------------+---------------------+--------------------------+---------------------------------+-----------------------+------------------+------------------+---------------+---------+-------------------+---------------------------+---------------------+--------------+--------------------------+---------------------+---------------------+-----------------+-------+------------------+------------------------+---------------------+-----------------------------+

Cancelling all keyspace migrations

The user may cancel all migrations in a keyspace. A migration is cancellable if it is in queued, ready or running states, as described previously. It is a high impact operation and should be used with care.

Via VTGate/SQL

Examples for a single shard cluster:

  1. mysql> alter vitess_migration cancel all;
  2. Query OK, 1 row affected (0.02 sec)

Via vtctldclient

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration cancel all" commerce

Also available via vtctldclient OnlineDDL command:

  1. $ vtctldclient OnlineDDL cancel commerce all
  2. {
  3. "rows_affected_by_shard": {
  4. "0": "0"
  5. }
  6. }

Retrying a migration

The user may retry running a migration. If the migration is in failed or in cancelled state, Vitess will re-run the migration, with exact same arguments as previously intended. If the migration is in any other state, retry does nothing.

It is not possible to retry a migration with different options. e.g. if the user initially runs ALTER TABLE demo MODIFY id BIGINT with @@ddl_strategy='gh-ost --max-load Threads_running=200' and the migration fails, retrying it will use exact same options. It is not possible to retry with @@ddl_strategy='gh-ost --max-load Threads_running=500'.

Via VTGate/SQL

  1. mysql> alter vitess_migration '075088b9_6b56_11ee_808b_0a43f95f28a3' retry;
  2. Query OK, 2 rows affected (0.01 sec)
  3. mysql> show vitess_migrations like '075088b9_6b56_11ee_808b_0a43f95f28a3' \G
  4. *************************** 1. row ***************************
  5. id: 12
  6. migration_uuid: 075088b9_6b56_11ee_808b_0a43f95f28a3
  7. keyspace: customer
  8. shard: -80
  9. mysql_schema: vt_customer
  10. mysql_table: corder
  11. migration_statement: alter table corder engine innodb
  12. strategy: vitess
  13. options:
  14. added_timestamp: 2023-10-15 12:26:12
  15. requested_timestamp: 2023-10-15 12:26:13
  16. ready_timestamp: NULL
  17. started_timestamp: 2023-10-15 12:30:09
  18. liveness_timestamp: 2023-10-15 12:30:18
  19. completed_timestamp: NULL
  20. cleanup_timestamp: NULL
  21. migration_status: running
  22. ...
  23. *************************** 2. row ***************************
  24. id: 12
  25. migration_uuid: 075088b9_6b56_11ee_808b_0a43f95f28a3
  26. keyspace: customer
  27. shard: 80-
  28. mysql_schema: vt_customer
  29. mysql_table: corder
  30. migration_statement: alter table corder engine innodb
  31. strategy: vitess
  32. options:
  33. added_timestamp: 2023-10-15 12:26:12
  34. requested_timestamp: 2023-10-15 12:26:13
  35. ready_timestamp: NULL
  36. started_timestamp: 2023-10-15 12:30:09
  37. liveness_timestamp: 2023-10-15 12:30:18
  38. completed_timestamp: NULL
  39. cleanup_timestamp: NULL
  40. migration_status: running
  41. ...

Via vtctldclient

The above migrations are running again, but still throttled. By way of illustration, let’s cancel and retry them yet again:

  1. $ vtctldclient ApplySchema --sql "alter vitess_migration '075088b9_6b56_11ee_808b_0a43f95f28a3' cancel" customer
  2. $ vtctldclient ApplySchema --sql "alter vitess_migration '075088b9_6b56_11ee_808b_0a43f95f28a3' retry" customer

Also available via vtctldclient OnlineDDL command:

  1. $ vtctldclient OnlineDDL cancel customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  2. {
  3. "rows_affected_by_shard": {
  4. "-80": "1",
  5. "80-": "1"
  6. }
  7. }
  8. $ vtctldclient OnlineDDL retry customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  9. {
  10. "rows_affected_by_shard": {
  11. "-80": "1",
  12. "80-": "1"
  13. }
  14. }

Cleaning migration artifacts

Migrations yield artifacts: these are leftover tables, such as the ghost or shadow tables in an ALTER DDL. These tables are audited and collected as part of table lifecycle.

The artifacts are essential to Reverting a migration, and are kept intact for a while before destroyed.

However, the artifacts also consume disk space. If the user is convinced they will not need the artifacts, they may explicitly request that the artifacts are dropped sooner.

Once cleanup is requested, the migration cannot be reverted.

The artifact tables are not purged immediately. Rather, they are sent for processing into the lifecycle mechanism.

Via VTGate/SQL

Per migration, request artifact cleanup via:

  1. mysql> alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' cleanup;
  2. Query OK, 1 row affected (0.00 sec)

Via vtctldclient

Execute via vtctldclient ApplySchema --sql "..." <keyspace> like previous commands, or use OnlineDDL command:

  1. $ $ vtctldclient OnlineDDL cancel customer all
  2. {
  3. "rows_affected_by_shard": {
  4. "-80": "1",
  5. "80-": "1"
  6. }
  7. }
  8. $ vtctldclient OnlineDDL cleanup customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  9. {
  10. "rows_affected_by_shard": {
  11. "-80": "1",
  12. "80-": "1"
  13. }
  14. }

Reverting a migration

Vitess offers lossless revert for online schema migrations: the user may regret a table migration after completion, and roll back the table’s schema to previous state without loss of data. See Revertible Migrations.

Via VTGate/SQL

Examples for a single shard cluster:

  1. mysql> show create table corder\G
  2. Create Table: CREATE TABLE `corder` (
  3. `order_id` bigint(20) NOT NULL AUTO_INCREMENT,
  4. `customer_id` bigint(20) DEFAULT NULL,
  5. `sku` varbinary(128) DEFAULT NULL,
  6. `price` bigint(20) DEFAULT NULL,
  7. `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  8. PRIMARY KEY (`order_id`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  10. 1 row in set (0.01 sec)
  11. mysql> set @@ddl_strategy='vitess';
  12. mysql> alter table corder drop column ts, add key customer_idx(customer_id);
  13. +--------------------------------------+
  14. | uuid |
  15. +--------------------------------------+
  16. | 1a689113_8d77_11eb_815f_f875a4d24e90 |
  17. +--------------------------------------+
  18. mysql> show create table corder\G
  19. Create Table: CREATE TABLE `corder` (
  20. `order_id` bigint(20) NOT NULL AUTO_INCREMENT,
  21. `customer_id` bigint(20) DEFAULT NULL,
  22. `sku` varbinary(128) DEFAULT NULL,
  23. `price` bigint(20) DEFAULT NULL,
  24. PRIMARY KEY (`order_id`),
  25. KEY `customer_idx` (`customer_id`)
  26. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  27. 1 row in set (0.00 sec)
  28. mysql> revert vitess_migration '1a689113_8d77_11eb_815f_f875a4d24e90';
  29. +--------------------------------------+
  30. | uuid |
  31. +--------------------------------------+
  32. | a02e6612_8d79_11eb_815f_f875a4d24e90 |
  33. +--------------------------------------+
  34. mysql> show create table corder\G
  35. Create Table: CREATE TABLE `corder` (
  36. `order_id` bigint(20) NOT NULL AUTO_INCREMENT,
  37. `customer_id` bigint(20) DEFAULT NULL,
  38. `sku` varbinary(128) DEFAULT NULL,
  39. `price` bigint(20) DEFAULT NULL,
  40. `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  41. PRIMARY KEY (`order_id`)
  42. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  • A revert is its own migration, hence has its own UUID

Via vtctldclient

  1. $ vtctldclient ApplySchema --ddl-strategy "vitess" --sql "revert vitess_migration '1a689113_8d77_11eb_815f_f875a4d24e90'" commerce

Controlling throttling

Managed migrations use the tablet throttler to ensure a sustainable impact to the MySQL servers and replication stream. Normally, the user doesn’t need to get involved, as the throttler auto-identifies load scenarios, and pushes back on migration progress. However, Vitess makes available these commands for additional control over migration throttling:

  1. alter vitess_migration '<uuid>' throttle [expire '<duration>'] [ratio <ratio>];
  2. alter vitess_migration throttle all [expire '<duration>'] [ratio <ratio>];
  3. alter vitess_migration '<uuid>' unthrottle;
  4. alter vitess_migration unthrottle all;
  5. show vitess_throttled_apps;

Note: the tablet throttler must be enabled for these command to run.

Throttling a migration

To fully throttle a migration, run:

  1. mysql> alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' throttle;
  2. Query OK, 1 row affected (0.00 sec)

From this point on, the migration will not make row copy progress and will not apply binary logs. By default, this command does not expire, and it takes an explicit unthrottle command to resume migration progress. Because MySQL binary logs are rotated, a migration may only survive a full throttling up to the point where the binary log it last processed is purged.

You may supply either or both these options: expire, ratio:

  • alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' throttle expire '2h' will fully throttle the migration for the next 2 hours, after which the migration resumes normal work. You may specify these units: s (seconds), m (minutes), h (hours) or combinations. Example values: 90s, 30m, 1h, 1h30m, etc.
  • alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' throttle ratio 0.7 will partially throttle the migration. This instructs the throttler to reject, on average, 7 migration throttling check requests out of 10. Any value between 0 (no throttling at all) and 1.0 (fully throttled) are allowed. This is a fine tune way to slow down a migration.

Throttling all migrations

It’s likely that you will want to throttle migrations in general, and not a specific migration. Use:

  • alter vitess_migration throttle all to fully throttle any and all migrations from this point on
  • alter vitess_migration throttle all expire '90m' to fully throttle any and all migrations from this point on and for the next 90 minutes.
  • alter vitess_migration throttle all ratio 0.8 to severely slow down all migrations from this point on (4 out of 5 migrations requests to the throttler are denied)
  • alter vitess_migration throttle all duration '10m' ratio 0.2 to lightly slow down all migrations from this point on (1 out of 5 migrations requests to the throttler are denied) for the next 10 minutes.

Unthrottling

Use:

  • alter vitess_migration 'aa89f255_8d68_11eb_815f_f875a4d24e90' unthrottle to allow the specified migration to resume working as normal
  • alter vitess_migration unthrottle all to unthrottle all migrations.

Note that this does not disable throttling altogether. If, for example, replication lag grows on replicas, the throttler may still throttle the migration until replication is caught up. Unthrottling only cancels an explicit throttling request as described above.

Showing throttled apps

The command show vitess_throttled_apps is a general purpose throttler command, and shows all apps for which there are throttling rules. It will list any specific or general migration throttling status.

Via vtctldclient

Execute via vtctldclient ApplySchema --sql "..." <keyspace> like previous commands, or use OnlineDDL commands:

  1. $ vtctldclient OnlineDDL throttle customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  2. $ vtctldclient OnlineDDL throttle customer all
  3. $ vtctldclient OnlineDDL unthrottle customer 075088b9_6b56_11ee_808b_0a43f95f28a3
  4. $ vtctldclient OnlineDDL unthrottle customer all