From aca288e88dcc82fe404a95dafeb9092cef36ffd4 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 7 May 2017 14:58:18 +0300 Subject: [PATCH] -postpone-cut-over-flag-file implies touching indicated file --- go/base/utils.go | 9 +++++++++ go/logic/migrator.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/go/base/utils.go b/go/base/utils.go index 2721742..71c6c3a 100644 --- a/go/base/utils.go +++ b/go/base/utils.go @@ -33,6 +33,15 @@ func FileExists(fileName string) bool { return false } +func TouchFile(fileName string) error { + f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE, 0755) + if err != nil { + return (err) + } + defer f.Close() + return nil +} + // StringContainsAll returns true if `s` contains all non empty given `substrings` // The function returns `false` if no non-empty arguments are given. func StringContainsAll(s string, substrings ...string) bool { diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 8720991..7e96cda 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -281,6 +281,18 @@ func (this *Migrator) countTableRows() (err error) { return countRowsFunc() } +func (this *Migrator) createFlagFiles() (err error) { + if this.migrationContext.PostponeCutOverFlagFile != "" { + if !base.FileExists(this.migrationContext.PostponeCutOverFlagFile) { + if err := base.TouchFile(this.migrationContext.PostponeCutOverFlagFile); err != nil { + return err + } + log.Infof("Created postpone-cut-over-flag-file: %s", this.migrationContext.PostponeCutOverFlagFile) + } + } + return nil +} + // Migrate executes the complete migration logic. This is *the* major gh-ost function. func (this *Migrator) Migrate() (err error) { log.Infof("Migrating %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName)) @@ -312,6 +324,9 @@ func (this *Migrator) Migrate() (err error) { if err := this.initiateApplier(); err != nil { return err } + if err := this.createFlagFiles(); err != nil { + return err + } initialLag, _ := this.inspector.getReplicationLag() log.Infof("Waiting for ghost table to be migrated. Current lag is %+v", initialLag)