ddl_strategy flags
ddl_strategy accepts flags in command line format. The flags can be vitess-specific, or, if unrecognized by Vitess, are passed on the underlying online schema change tools.
Vitess flags #
Vitess respects the following flags. They can be combined unless specifically indicated otherwise:
--allow-concurrent: allow a migration to run concurrently to other migrations, rather than queue sequentially. Some restrictions apply, see concurrent migrations.--allow-zero-in-date: normally Vitess operates with a strictsql_mode. If you have columns such asmy_datetime DATETIME DEFAULT '0000-00-00 00:00:00'and you wish to run DDL on these tables, Vitess will prevent the migration due to invalid values. Provide--allow-zero-in-dateto allow either a fully zero-date or a zero-in-date inyour schema. See also NO_ZERO_IN_DATE and NO_ZERO_DATE documentation for sql_mode.--analyze-table: forALTER TABLEoperation, and inonline/vitessstrategy, run anANALYZE NO_WRITE_TO_BINLOG TABLEjust before starting the migration process, to get better estimation of the number of rows on the migrated table.--cut-over-threshold="<duration>": set an explicit threshold and timeout for avitessALTER TABLEcut-over phase. The default cut-over threshold, if not specified, is10s. Avitessmigration will not attempt to cut-over if the vstream, or replication lag, is more than the cut-over threshold. Also, during cut-over, table locks will timeout after the same cut-over threshold (aborting the operation). The allowed range5s..30s. Too low and cut-over may never succeed because of the inherent async nature ofvitessmigrations. Too high and table locks will be placed for too long, effectively rendering the table inaccessible. Attempting to set a value outside the allowed range returns an error. A special case is when the user submits a0value, which subsequently presets the threshold to the default value of10s. The user may override this value later on viaALTER VITESS_MIGRATION '...' CUTOVER_THRESHOLD '...'--declarative: mark the migration as declarative. You will define a desired schema state by supplyingCREATEandDROPstatements, ad Vitess will infer how to achieve the desired schema. If need be, it will generate anALTERmigration to convert to the new schema. See declarative migrations.--fast-range-rotation: when the migration runs on a table partitioned byRANGE, and the migration either runs a singleDROP PARTITIONor a singleADD PARTITION, and nothing other than that, then this flags instructs Vitess to run theALTER TABLEstatement directly against MySQL, as opposed to running an Online DDL with a shadow table. ForDROP PARTITION, this flag is actually always desired, and will possibly become default/redundant in the future. If all conditions are indeed met, then the migration is not revertible.--force-cut-over-after=<duration>: applicable toALTER TABLEmigrations invitessstrategy and on MySQL8.0. The final step of the migration, the cut-over, involves acquiring locks on the migrated table. This operation can time out when the table is otherwise locked by the user or the app, in which case Vitess retries it later on, until successful. When--force-cut-over-afteris specified, then counting the time since the very first cut-over attempt, and for any further cut-over attempt, Vitess will aggressivelyKILLqueries and transactions that are using or locking the migrated table.For example, say
--force-cut-over-after=2h, and that the migration takes7hto run. Say there is constant workload/locking that prevents the migration from cutting over. The first cut-over attempt takes place at the end of the7hrun, and fails due to lock wait timeout. During the next 2 hours there will be multiple additional attempts to cut-over, and say they all continue to fail. At the2hmark (9hsince starting the migration), give or take, Vitess runs a cut-over thatKILLs existing queries and transactions on the table. This is likely to make the cut-over successful. Should this still fail, Vitess will continue to forcefullyKILLqueries and transactions in all additional cut-over attempts.See also forcing a migration cut-over
--in-order-completion: a migration that runs with this DDL strategy flag may only complete if no prior migrations are still pending (pending means eitherqueued,readyorrunningstates).--in-order-completionconsiders the order by which migrations were submitted. Note that--in-order-completionstill allows concurrency. In fact, it is designed to work with concurrent migrations. The idea is that while many migrations may run concurrently, they must complete in-order.- This lets the user submit multiple migrations which may have some dependencies (for example, introduce two views, one of which reads from the other). As long as the migrations are submitted in a valid order, the user can then expect
vitessto complete the migrations successfully (and in that order). - This strategy flag applies to any
CREATE|DROP TABLE|VIEWstatements, and toALTER TABLEwithvitess|onlinestrategy. - It does not apply to
ALTER TABLEwhen using themysql, ordirectstrategies.
- This lets the user submit multiple migrations which may have some dependencies (for example, introduce two views, one of which reads from the other). As long as the migrations are submitted in a valid order, the user can then expect
--postpone-completion: initiate a migration that will only cut-over per user command, i.e. will not auto-complete. This gives the user control over the time when the schema change takes effect. See postponed migrations.--declarativemigrations are only evaluated when scheduled to run. If a migrations is both--declarativeand--postpone-completionthen it will remain inqueuedstate until the user issues aALTER VITESS_MIGRATION ... COMPLETE. If it turns out that Vitess should run the migration as anALTERthen it is only at that time that the migration starts.--postpone-launch: initiate a migration that remainsqueuedand only launches per user command. See postponed migrations.--prefer-instant-ddl: where possible, applyALGORITHM=INSTANTto the migration. This is applicable toALTER TABLEmigrations withvitessstrategy. Vitess pre-computes whether the migration is eligible forINSTANTDDL. The MySQL documentation references an incomplete list of eligible changes. If applicable, vitess does not create a shadow table and the migration is not revertible.--retain-artifacts=<duration>: set an explicit artifact retention for this migration. If nonzero, this value overrides thevttablet --retain_online_ddl_tablesvalue.--singleton: only allow a single pending migration to be submitted at a time. From the moment the migration is queued, and until either completion, failure or cancellation, no other new--singletonmigration can be submitted. New requests will be rejected with error.--singletonworks as an exclusive lock for pending migrations. Note that this only affects migrations with--singletonflag. Migrations running without that flag are unaffected and unblocked.--singleton-context: only allow migrations submitted under same context to be pending at any given time. Migrations submitted with a different context are rejected for as long as at least one of the initially submitted migrations is pending.It does not make sense to combine
--singletonand--singleton-context.--singleton-table: reject a new submission for a table or view which already has a pending migration.
Notes #
For internal testing/CI purposes, the vitess strategy (formerly known as online) supports --vreplication-test-suite, and this flag must not be used in production as it can have destructive consequences.