diff --git a/go/vt/schema/ddl_strategy.go b/go/vt/schema/ddl_strategy.go index a05d5eabc5..dbc1f2d32b 100644 --- a/go/vt/schema/ddl_strategy.go +++ b/go/vt/schema/ddl_strategy.go @@ -28,10 +28,11 @@ var ( ) const ( - declarativeFlag = "declarative" - skipTopoFlag = "skip-topo" - singletonFlag = "singleton" - singletonContextFlag = "singleton-context" + declarativeFlag = "declarative" + skipTopoFlag = "skip-topo" + singletonFlag = "singleton" + singletonContextFlag = "singleton-context" + vreplicationTestSuite = "vreplication-test-suite" ) // DDLStrategy suggests how an ALTER TABLE should run (e.g. "direct", "online", "gh-ost" or "pt-osc") @@ -129,6 +130,11 @@ func (setting *DDLStrategySetting) IsSingletonContext() bool { return setting.hasFlag(singletonContextFlag) } +// IsVreplicationTestSuite checks if strategy options include -vreplicatoin-test-suite +func (setting *DDLStrategySetting) IsVreplicationTestSuite() bool { + return setting.hasFlag(vreplicationTestSuite) +} + // RuntimeOptions returns the options used as runtime flags for given strategy, removing any internal hint options func (setting *DDLStrategySetting) RuntimeOptions() []string { opts, _ := shlex.Split(setting.Options) @@ -139,6 +145,7 @@ func (setting *DDLStrategySetting) RuntimeOptions() []string { case isFlag(opt, skipTopoFlag): case isFlag(opt, singletonFlag): case isFlag(opt, singletonContextFlag): + case isFlag(opt, vreplicationTestSuite): default: validOpts = append(validOpts, opt) } diff --git a/go/vt/vttablet/onlineddl/executor.go b/go/vt/vttablet/onlineddl/executor.go index f407d90e95..672e3b0879 100644 --- a/go/vt/vttablet/onlineddl/executor.go +++ b/go/vt/vttablet/onlineddl/executor.go @@ -597,13 +597,27 @@ func (e *Executor) cutOverVReplMigration(ctx context.Context, s *VReplStream) er // rename tables atomically (remember, writes on source tables are stopped) { - parsed := sqlparser.BuildParsedQuery(sqlSwapTables, - onlineDDL.Table, swapTable, - vreplTable, onlineDDL.Table, - swapTable, vreplTable, - ) - if _, err = e.execQuery(ctx, parsed.Query); err != nil { - return err + if onlineDDL.StrategySetting().IsVreplicationTestSuite() { + // this is used in Vitess endtoend testing suite + beforeTableName := fmt.Sprintf("%s_before", onlineDDL.Table) + afterTableName := fmt.Sprintf("%s_after", onlineDDL.Table) + parsed := sqlparser.BuildParsedQuery(sqlRenameTwoTables, + onlineDDL.Table, beforeTableName, + vreplTable, afterTableName, + ) + if _, err = e.execQuery(ctx, parsed.Query); err != nil { + return err + } + } else { + // Normal (non-testing) alter table + parsed := sqlparser.BuildParsedQuery(sqlSwapTables, + onlineDDL.Table, swapTable, + vreplTable, onlineDDL.Table, + swapTable, vreplTable, + ) + if _, err = e.execQuery(ctx, parsed.Query); err != nil { + return err + } } } diff --git a/go/vt/vttablet/onlineddl/schema.go b/go/vt/vttablet/onlineddl/schema.go index 8ef3d87a98..0d069794bc 100644 --- a/go/vt/vttablet/onlineddl/schema.go +++ b/go/vt/vttablet/onlineddl/schema.go @@ -320,8 +320,9 @@ const ( _vt.copy_state WHERE vrepl_id=%a ` - sqlSwapTables = "RENAME TABLE `%a` TO `%a`, `%a` TO `%a`, `%a` TO `%a`" - sqlRenameTable = "RENAME TABLE `%a` TO `%a`" + sqlSwapTables = "RENAME TABLE `%a` TO `%a`, `%a` TO `%a`, `%a` TO `%a`" + sqlRenameTwoTables = "RENAME TABLE `%a` TO `%a`, `%a` TO `%a`" + sqlRenameTable = "RENAME TABLE `%a` TO `%a`" ) const (