зеркало из https://github.com/github/vitess-gh.git
support for ddl_strategy '-vreplication-test-suite', which renames both tables on cut-over to names inaccessible to the app, paving the way for a reliable test suite
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
This commit is contained in:
Родитель
dff8d63290
Коммит
705a8d0ff3
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 (
|
||||
|
|
Загрузка…
Ссылка в новой задаче