reading time_zone settings for Inspector and Applier separately.

--time-zone overrides both of them, if given
This commit is contained in:
Shlomi Noach 2016-10-11 16:00:26 +02:00
parent 5de8a010df
commit dbf50afbc7
4 changed files with 27 additions and 7 deletions

View File

@ -112,7 +112,8 @@ type MigrationContext struct {
Hostname string
AssumeMasterHostname string
TimeZone string
InspectorTimeZone string
ApplierTimeZone string
TableEngine string
RowsEstimate int64
RowsDeltaEstimate int64

View File

@ -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)

View File

@ -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
}

View File

@ -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
}