diff --git a/go/base/context.go b/go/base/context.go index 5ef5e6e..a1cd6bf 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -112,7 +112,8 @@ type MigrationContext struct { Hostname string AssumeMasterHostname string - TimeZone string + InspectorTimeZone string + ApplierTimeZone string TableEngine string RowsEstimate int64 RowsDeltaEstimate int64 diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index ce11e2a..916d3eb 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -48,7 +48,7 @@ func main() { flag.IntVar(&migrationContext.InspectorConnectionConfig.Key.Port, "port", 3306, "MySQL port (preferably a replica, not the master)") flag.StringVar(&migrationContext.CliUser, "user", "", "MySQL user") flag.StringVar(&migrationContext.CliPassword, "password", "", "MySQL password") - flag.StringVar(&migrationContext.TimeZone, "time-zone", "", "assume timezone. Default: MySQL server global time zone.") + timeZone := flag.String("time-zone", "", "assume timezone. Default: MySQL server global time zone.") flag.StringVar(&migrationContext.ConfigFile, "conf", "", "Config file") flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)") @@ -203,6 +203,10 @@ func main() { if err := migrationContext.SetCutOverLockTimeoutSeconds(*cutOverLockTimeoutSeconds); err != nil { log.Errore(err) } + if *timeZone != "" { + migrationContext.InspectorTimeZone = *timeZone + migrationContext.ApplierTimeZone = *timeZone + } log.Infof("starting gh-ost %+v", AppVersion) acceptSignals(migrationContext) diff --git a/go/logic/applier.go b/go/logic/applier.go index 8976bf2..a45bfe0 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -59,6 +59,9 @@ func (this *Applier) InitDBConnections() (err error) { if err := this.validateConnection(this.singletonDB); err != nil { return err } + if err := this.validateAndReadTimeZone(); err != nil { + return err + } if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil { return err } else { @@ -81,6 +84,18 @@ func (this *Applier) validateConnection(db *gosql.DB) error { return nil } +// validateAndReadTimeZone potentially reads server time-zone +func (this *Applier) validateAndReadTimeZone() error { + if this.migrationContext.ApplierTimeZone == "" { + query := `select @@global.time_zone` + if err := this.db.QueryRow(query).Scan(&this.migrationContext.ApplierTimeZone); err != nil { + return err + } + } + log.Infof("will use time_zone='%s' on applier", this.migrationContext.ApplierTimeZone) + return nil +} + // showTableStatus returns the output of `show table status like '...'` command func (this *Applier) showTableStatus(tableName string) (rowMap sqlutils.RowMap) { rowMap = nil @@ -423,7 +438,7 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s', sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES') - `, this.migrationContext.TimeZone) + `, this.migrationContext.ApplierTimeZone) if _, err := tx.Exec(sessionQuery); err != nil { return nil, err } @@ -896,7 +911,7 @@ func (this *Applier) ApplyDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) error { sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s', sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES') - `, this.migrationContext.TimeZone) + `, this.migrationContext.ApplierTimeZone) if _, err := tx.Exec(sessionQuery); err != nil { return err } diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 8976f51..2c52780 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -160,13 +160,13 @@ func (this *Inspector) validateConnection() error { // validateAndReadTimeZone potentially reads server time-zone func (this *Inspector) validateAndReadTimeZone() error { - if this.migrationContext.TimeZone == "" { + if this.migrationContext.InspectorTimeZone == "" { query := `select @@global.time_zone` - if err := this.db.QueryRow(query).Scan(&this.migrationContext.TimeZone); err != nil { + if err := this.db.QueryRow(query).Scan(&this.migrationContext.InspectorTimeZone); err != nil { return err } } - log.Infof("will use %s timezone", this.migrationContext.TimeZone) + log.Infof("will use time_zone='%s' on inspector", this.migrationContext.InspectorTimeZone) return nil }