Skip to content

Commit 5294ab6

Browse files
author
Arthur Nogueira Neves
authored
Merge pull request #457 from github/arthurnn/add_force_table_arg
Add a force-table-names command flag
2 parents b0ad600 + cba462a commit 5294ab6

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

go/base/context.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ type MigrationContext struct {
192192
Iteration int64
193193
MigrationIterationRangeMinValues *sql.ColumnValues
194194
MigrationIterationRangeMaxValues *sql.ColumnValues
195+
ForceTmpTableName string
195196

196197
recentBinlogCoordinates mysql.BinlogCoordinates
197198

@@ -253,25 +254,42 @@ func getSafeTableName(baseName string, suffix string) string {
253254
}
254255

255256
// GetGhostTableName generates the name of ghost table, based on original table name
257+
// or a given table name
256258
func (this *MigrationContext) GetGhostTableName() string {
257-
return getSafeTableName(this.OriginalTableName, "gho")
259+
if this.ForceTmpTableName != "" {
260+
return getSafeTableName(this.ForceTmpTableName, "gho")
261+
} else {
262+
return getSafeTableName(this.OriginalTableName, "gho")
263+
}
258264
}
259265

260266
// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
261267
func (this *MigrationContext) GetOldTableName() string {
268+
var tableName string
269+
if this.ForceTmpTableName != "" {
270+
tableName = this.ForceTmpTableName
271+
} else {
272+
tableName = this.OriginalTableName
273+
}
274+
262275
if this.TimestampOldTable {
263276
t := this.StartTime
264277
timestamp := fmt.Sprintf("%d%02d%02d%02d%02d%02d",
265278
t.Year(), t.Month(), t.Day(),
266279
t.Hour(), t.Minute(), t.Second())
267-
return getSafeTableName(this.OriginalTableName, fmt.Sprintf("%s_del", timestamp))
280+
return getSafeTableName(tableName, fmt.Sprintf("%s_del", timestamp))
268281
}
269-
return getSafeTableName(this.OriginalTableName, "del")
282+
return getSafeTableName(tableName, "del")
270283
}
271284

272285
// GetChangelogTableName generates the name of changelog table, based on original table name
286+
// or a given table name.
273287
func (this *MigrationContext) GetChangelogTableName() string {
274-
return getSafeTableName(this.OriginalTableName, "ghc")
288+
if this.ForceTmpTableName != "" {
289+
return getSafeTableName(this.ForceTmpTableName, "ghc")
290+
} else {
291+
return getSafeTableName(this.OriginalTableName, "ghc")
292+
}
275293
}
276294

277295
// GetVoluntaryLockName returns a name of a voluntary lock to be used throughout

go/base/context_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ func TestGetTableNames(t *testing.T) {
4444
oldTableName := context.GetOldTableName()
4545
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123_20130203195400_del")
4646
}
47+
{
48+
context.OriginalTableName = "foo_bar_baz"
49+
context.ForceTmpTableName = "tmp"
50+
context.TimestampOldTable = false
51+
test.S(t).ExpectEquals(context.GetOldTableName(), "_tmp_del")
52+
test.S(t).ExpectEquals(context.GetGhostTableName(), "_tmp_gho")
53+
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_tmp_ghc")
54+
}
4755
}

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func main() {
120120
help := flag.Bool("help", false, "Display usage")
121121
version := flag.Bool("version", false, "Print version & exit")
122122
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")
123+
flag.StringVar(&migrationContext.ForceTmpTableName, "force-table-names", "", "table name prefix to be used on the temporary tables")
123124

124125
flag.Parse()
125126

0 commit comments

Comments
 (0)