Merge pull request #457 from github/arthurnn/add_force_table_arg
Add a force-table-names command flag
This commit is contained in:
commit
5294ab6bd1
@ -192,6 +192,7 @@ type MigrationContext struct {
|
|||||||
Iteration int64
|
Iteration int64
|
||||||
MigrationIterationRangeMinValues *sql.ColumnValues
|
MigrationIterationRangeMinValues *sql.ColumnValues
|
||||||
MigrationIterationRangeMaxValues *sql.ColumnValues
|
MigrationIterationRangeMaxValues *sql.ColumnValues
|
||||||
|
ForceTmpTableName string
|
||||||
|
|
||||||
recentBinlogCoordinates mysql.BinlogCoordinates
|
recentBinlogCoordinates mysql.BinlogCoordinates
|
||||||
|
|
||||||
@ -253,26 +254,43 @@ func getSafeTableName(baseName string, suffix string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGhostTableName generates the name of ghost table, based on original table name
|
// GetGhostTableName generates the name of ghost table, based on original table name
|
||||||
|
// or a given table name
|
||||||
func (this *MigrationContext) GetGhostTableName() string {
|
func (this *MigrationContext) GetGhostTableName() string {
|
||||||
|
if this.ForceTmpTableName != "" {
|
||||||
|
return getSafeTableName(this.ForceTmpTableName, "gho")
|
||||||
|
} else {
|
||||||
return getSafeTableName(this.OriginalTableName, "gho")
|
return getSafeTableName(this.OriginalTableName, "gho")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
|
// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
|
||||||
func (this *MigrationContext) GetOldTableName() string {
|
func (this *MigrationContext) GetOldTableName() string {
|
||||||
|
var tableName string
|
||||||
|
if this.ForceTmpTableName != "" {
|
||||||
|
tableName = this.ForceTmpTableName
|
||||||
|
} else {
|
||||||
|
tableName = this.OriginalTableName
|
||||||
|
}
|
||||||
|
|
||||||
if this.TimestampOldTable {
|
if this.TimestampOldTable {
|
||||||
t := this.StartTime
|
t := this.StartTime
|
||||||
timestamp := fmt.Sprintf("%d%02d%02d%02d%02d%02d",
|
timestamp := fmt.Sprintf("%d%02d%02d%02d%02d%02d",
|
||||||
t.Year(), t.Month(), t.Day(),
|
t.Year(), t.Month(), t.Day(),
|
||||||
t.Hour(), t.Minute(), t.Second())
|
t.Hour(), t.Minute(), t.Second())
|
||||||
return getSafeTableName(this.OriginalTableName, fmt.Sprintf("%s_del", timestamp))
|
return getSafeTableName(tableName, fmt.Sprintf("%s_del", timestamp))
|
||||||
}
|
}
|
||||||
return getSafeTableName(this.OriginalTableName, "del")
|
return getSafeTableName(tableName, "del")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChangelogTableName generates the name of changelog table, based on original table name
|
// GetChangelogTableName generates the name of changelog table, based on original table name
|
||||||
|
// or a given table name.
|
||||||
func (this *MigrationContext) GetChangelogTableName() string {
|
func (this *MigrationContext) GetChangelogTableName() string {
|
||||||
|
if this.ForceTmpTableName != "" {
|
||||||
|
return getSafeTableName(this.ForceTmpTableName, "ghc")
|
||||||
|
} else {
|
||||||
return getSafeTableName(this.OriginalTableName, "ghc")
|
return getSafeTableName(this.OriginalTableName, "ghc")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetVoluntaryLockName returns a name of a voluntary lock to be used throughout
|
// GetVoluntaryLockName returns a name of a voluntary lock to be used throughout
|
||||||
// the swap-tables process.
|
// the swap-tables process.
|
||||||
|
@ -44,4 +44,12 @@ func TestGetTableNames(t *testing.T) {
|
|||||||
oldTableName := context.GetOldTableName()
|
oldTableName := context.GetOldTableName()
|
||||||
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123_20130203195400_del")
|
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123_20130203195400_del")
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
context.OriginalTableName = "foo_bar_baz"
|
||||||
|
context.ForceTmpTableName = "tmp"
|
||||||
|
context.TimestampOldTable = false
|
||||||
|
test.S(t).ExpectEquals(context.GetOldTableName(), "_tmp_del")
|
||||||
|
test.S(t).ExpectEquals(context.GetGhostTableName(), "_tmp_gho")
|
||||||
|
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_tmp_ghc")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ func main() {
|
|||||||
help := flag.Bool("help", false, "Display usage")
|
help := flag.Bool("help", false, "Display usage")
|
||||||
version := flag.Bool("version", false, "Print version & exit")
|
version := flag.Bool("version", false, "Print version & exit")
|
||||||
checkFlag := flag.Bool("check-flag", false, "Check if another flag exists/supported. This allows for cross-version scripting. Exits with 0 when all additional provided flags exist, nonzero otherwise. You must provide (dummy) values for flags that require a value. Example: gh-ost --check-flag --cut-over-lock-timeout-seconds --nice-ratio 0")
|
checkFlag := flag.Bool("check-flag", false, "Check if another flag exists/supported. This allows for cross-version scripting. Exits with 0 when all additional provided flags exist, nonzero otherwise. You must provide (dummy) values for flags that require a value. Example: gh-ost --check-flag --cut-over-lock-timeout-seconds --nice-ratio 0")
|
||||||
|
flag.StringVar(&migrationContext.ForceTmpTableName, "force-table-names", "", "table name prefix to be used on the temporary tables")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user