From 5de8a010dfe5ed02d15296a22357e68cc9571547 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Mon, 10 Oct 2016 22:33:54 +0200 Subject: [PATCH] restoring original row_event code; tampering with applier time_zone based on global timze_zone --- go/cmd/gh-ost/main.go | 2 +- go/logic/inspect.go | 15 +++++++++++++++ localtests/test.sh | 8 ++++---- localtests/tz/extra_args | 1 - .../siddontang/go-mysql/replication/row_event.go | 12 +++++++----- 5 files changed, 27 insertions(+), 11 deletions(-) delete mode 100644 localtests/tz/extra_args diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 0ca18fa..ce11e2a 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", "+00:00", "assume timezone. Default: UTC. Set empty for system time zone") + flag.StringVar(&migrationContext.TimeZone, "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)") diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 28d1884..8976f51 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -56,6 +56,9 @@ func (this *Inspector) InitDBConnections() (err error) { if err := this.applyBinlogFormat(); err != nil { return err } + if err := this.validateAndReadTimeZone(); err != nil { + return err + } return nil } @@ -155,6 +158,18 @@ func (this *Inspector) validateConnection() error { return nil } +// validateAndReadTimeZone potentially reads server time-zone +func (this *Inspector) validateAndReadTimeZone() error { + if this.migrationContext.TimeZone == "" { + query := `select @@global.time_zone` + if err := this.db.QueryRow(query).Scan(&this.migrationContext.TimeZone); err != nil { + return err + } + } + log.Infof("will use %s timezone", this.migrationContext.TimeZone) + return nil +} + // validateGrants verifies the user by which we're executing has necessary grants // to do its thang. func (this *Inspector) validateGrants() error { diff --git a/localtests/test.sh b/localtests/test.sh index 1eea84b..f12b66f 100755 --- a/localtests/test.sh +++ b/localtests/test.sh @@ -102,15 +102,15 @@ test_single() { fi echo_dot - orig_checksum=$(gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set session time_zone='+00:00'; select ${orig_columns} from gh_ost_test" -ss | md5sum) - ghost_checksum=$(gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set session time_zone='+00:00'; select ${ghost_columns} from _gh_ost_test_gho" -ss | md5sum) + orig_checksum=$(gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${orig_columns} from gh_ost_test" -ss | md5sum) + ghost_checksum=$(gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${ghost_columns} from _gh_ost_test_gho" -ss | md5sum) if [ "$orig_checksum" != "$ghost_checksum" ] ; then echo "ERROR $test_name: checksum mismatch" echo "---" - gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set session time_zone='+00:00'; select ${orig_columns} from gh_ost_test" -ss + gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${orig_columns} from gh_ost_test" -ss echo "---" - gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set session time_zone='+00:00'; select ${ghost_columns} from _gh_ost_test_gho" -ss + gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${ghost_columns} from _gh_ost_test_gho" -ss return 1 fi } diff --git a/localtests/tz/extra_args b/localtests/tz/extra_args deleted file mode 100644 index 390a33c..0000000 --- a/localtests/tz/extra_args +++ /dev/null @@ -1 +0,0 @@ ---time-zone="+00:00" diff --git a/vendor/github.com/siddontang/go-mysql/replication/row_event.go b/vendor/github.com/siddontang/go-mysql/replication/row_event.go index 4ed093e..9d377af 100644 --- a/vendor/github.com/siddontang/go-mysql/replication/row_event.go +++ b/vendor/github.com/siddontang/go-mysql/replication/row_event.go @@ -611,8 +611,10 @@ func decodeTimestamp2(data []byte, dec uint16) (interface{}, int, error) { // t := time.Unix(sec, usec*1000).UTC() // .UTC() converted by shlomi-noach // return t.Format(TimeFormat), n, nil - t := time.Unix(sec, usec*1000).UTC() - return t, n, nil + //t := time.Unix(sec, usec*1000).UTC() + t := time.Unix(sec, usec*1000) + return t.Format(TimeFormat), n, nil + //return t, n, nil } const DATETIMEF_INT_OFS int64 = 0x8000000000 @@ -659,11 +661,11 @@ func decodeDatetime2(data []byte, dec uint16) (interface{}, int, error) { minute := int((hms >> 6) % (1 << 6)) hour := int((hms >> 12)) - t := time.Date(year, time.Month(month), day, hour, minute, second, 0, time.UTC) // added by Shlomi Noach + // t := time.Date(year, time.Month(month), day, hour, minute, second, 0, time.UTC) // added by Shlomi Noach //return t.Format(TimeFormat), n, nil // added by Shlomi Noach - return t, n, nil // added by Shlomi Noach + // return t, n, nil // added by Shlomi Noach - // return fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second), n, nil // commented by Shlomi Noach. Yes I know about `git blame` + return fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second), n, nil // commented by Shlomi Noach. Yes I know about `git blame` } const TIMEF_OFS int64 = 0x800000000000