Skip to content

Commit 8db8e12

Browse files
author
Shlomi Noach
committed
supporting --timestamp-old-table
1 parent 8605463 commit 8db8e12

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

go/base/context.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type MigrationContext struct {
121121
OkToDropTable bool
122122
InitiallyDropOldTable bool
123123
InitiallyDropGhostTable bool
124+
TimestampOldTable bool // Should old table name include a timestamp
124125
CutOverType CutOver
125126
ReplicaServerId uint
126127

@@ -234,11 +235,12 @@ func (this *MigrationContext) GetGhostTableName() string {
234235

235236
// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
236237
func (this *MigrationContext) GetOldTableName() string {
237-
if this.TestOnReplica {
238-
return fmt.Sprintf("_%s_ght", this.OriginalTableName)
239-
}
240-
if this.MigrateOnReplica {
241-
return fmt.Sprintf("_%s_ghr", this.OriginalTableName)
238+
if this.TimestampOldTable {
239+
t := this.StartTime
240+
timestamp := fmt.Sprintf("%d%02d%02d%02d%02d%02d",
241+
t.Year(), t.Month(), t.Day(),
242+
t.Hour(), t.Minute(), t.Second())
243+
return fmt.Sprintf("_%s_%s_del", this.OriginalTableName, timestamp)
242244
}
243245
return fmt.Sprintf("_%s_del", this.OriginalTableName)
244246
}

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func main() {
7777
flag.BoolVar(&migrationContext.OkToDropTable, "ok-to-drop-table", false, "Shall the tool drop the old table at end of operation. DROPping tables can be a long locking operation, which is why I'm not doing it by default. I'm an online tool, yes?")
7878
flag.BoolVar(&migrationContext.InitiallyDropOldTable, "initially-drop-old-table", false, "Drop a possibly existing OLD table (remains from a previous run?) before beginning operation. Default is to panic and abort if such table exists")
7979
flag.BoolVar(&migrationContext.InitiallyDropGhostTable, "initially-drop-ghost-table", false, "Drop a possibly existing Ghost table (remains from a previous run?) before beginning operation. Default is to panic and abort if such table exists")
80+
flag.BoolVar(&migrationContext.TimestampOldTable, "timestamp-old-table", false, "Use a timestamp in old table name. This makes old table names unique and non conflicting cross migrations")
8081
cutOver := flag.String("cut-over", "atomic", "choose cut-over type (default|atomic, two-step)")
8182
flag.BoolVar(&migrationContext.ForceNamedCutOverCommand, "force-named-cut-over", false, "When true, the 'unpostpone|cut-over' interactive command must name the migrated table")
8283

localtests/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ test_single() {
8585
--switch-to-rbr \
8686
--initially-drop-old-table \
8787
--initially-drop-ghost-table \
88+
--timestamp-old-table \
8889
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
8990
--serve-socket-file=/tmp/gh-ost.test.sock \
9091
--initially-drop-socket-file \

0 commit comments

Comments
 (0)