From 8db8e127ebba537a5d86c5c7224fd7796597702c Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 21 Feb 2017 10:34:24 -0700 Subject: [PATCH] supporting --timestamp-old-table --- go/base/context.go | 12 +++++++----- go/cmd/gh-ost/main.go | 1 + localtests/test.sh | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/go/base/context.go b/go/base/context.go index 314a1d5..d6cd6ce 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -121,6 +121,7 @@ type MigrationContext struct { OkToDropTable bool InitiallyDropOldTable bool InitiallyDropGhostTable bool + TimestampOldTable bool // Should old table name include a timestamp CutOverType CutOver ReplicaServerId uint @@ -234,11 +235,12 @@ func (this *MigrationContext) GetGhostTableName() string { // GetOldTableName generates the name of the "old" table, into which the original table is renamed. func (this *MigrationContext) GetOldTableName() string { - if this.TestOnReplica { - return fmt.Sprintf("_%s_ght", this.OriginalTableName) - } - if this.MigrateOnReplica { - return fmt.Sprintf("_%s_ghr", this.OriginalTableName) + if this.TimestampOldTable { + t := this.StartTime + timestamp := fmt.Sprintf("%d%02d%02d%02d%02d%02d", + t.Year(), t.Month(), t.Day(), + t.Hour(), t.Minute(), t.Second()) + return fmt.Sprintf("_%s_%s_del", this.OriginalTableName, timestamp) } return fmt.Sprintf("_%s_del", this.OriginalTableName) } diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 8e5e20c..238dc81 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -77,6 +77,7 @@ func main() { 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?") 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") 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") + 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") cutOver := flag.String("cut-over", "atomic", "choose cut-over type (default|atomic, two-step)") flag.BoolVar(&migrationContext.ForceNamedCutOverCommand, "force-named-cut-over", false, "When true, the 'unpostpone|cut-over' interactive command must name the migrated table") diff --git a/localtests/test.sh b/localtests/test.sh index 8bbcf6f..12ec77b 100755 --- a/localtests/test.sh +++ b/localtests/test.sh @@ -85,6 +85,7 @@ test_single() { --switch-to-rbr \ --initially-drop-old-table \ --initially-drop-ghost-table \ + --timestamp-old-table \ --throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \ --serve-socket-file=/tmp/gh-ost.test.sock \ --initially-drop-socket-file \