From a8699f664eede7f89445ec501cd64eef3526c1c8 Mon Sep 17 00:00:00 2001 From: Rustin Date: Sat, 15 Feb 2020 20:52:58 +0800 Subject: [PATCH 1/3] cherry pick #14572 to release-3.0 Signed-off-by: sre-bot --- server/util.go | 15 ++++++++------- server/util_test.go | 15 ++++++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/server/util.go b/server/util.go index c80289c1b741e..0e7da3e6133d5 100644 --- a/server/util.go +++ b/server/util.go @@ -43,7 +43,6 @@ import ( "strconv" "time" - "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/types" @@ -201,6 +200,7 @@ func dumpBinaryTime(dur time.Duration) (data []byte) { return } +<<<<<<< HEAD func dumpBinaryDateTime(data []byte, t types.Time, loc *time.Location) ([]byte, error) { if t.Type == mysql.TypeTimestamp && loc != nil { // TODO: Consider time_zone variable. @@ -213,6 +213,11 @@ func dumpBinaryDateTime(data []byte, t types.Time, loc *time.Location) ([]byte, year, mon, day := t.Time.Year(), t.Time.Month(), t.Time.Day() switch t.Type { +======= +func dumpBinaryDateTime(data []byte, t types.Time) []byte { + year, mon, day := t.Year(), t.Month(), t.Day() + switch t.Type() { +>>>>>>> efa179c... server: fix potential timezone related bugs caused by `time.Local` (#14572) case mysql.TypeTimestamp, mysql.TypeDatetime: data = append(data, 11) data = dumpUint16(data, uint16(year)) @@ -223,7 +228,7 @@ func dumpBinaryDateTime(data []byte, t types.Time, loc *time.Location) ([]byte, data = dumpUint16(data, uint16(year)) //year data = append(data, byte(mon), byte(day)) } - return data, nil + return data } func dumpBinaryRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, error) { @@ -259,11 +264,7 @@ func dumpBinaryRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob: buffer = dumpLengthEncodedString(buffer, row.GetBytes(i)) case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp: - var err error - buffer, err = dumpBinaryDateTime(buffer, row.GetTime(i), nil) - if err != nil { - return buffer, err - } + buffer = dumpBinaryDateTime(buffer, row.GetTime(i)) case mysql.TypeDuration: buffer = append(buffer, dumpBinaryTime(row.GetDuration(i, 0).Duration)...) case mysql.TypeEnum: diff --git a/server/util_test.go b/server/util_test.go index c7eba5959fbc0..cc541f90bbbff 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -61,21 +61,26 @@ func (s *testUtilSuite) TearDownSuite(c *C) { func (s *testUtilSuite) TestDumpBinaryTime(c *C) { t, err := types.ParseTimestamp(nil, "0000-00-00 00:00:00.0000000") c.Assert(err, IsNil) - d, err := dumpBinaryDateTime(nil, t, nil) - c.Assert(err, IsNil) + d := dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) t, err = types.ParseDatetime(nil, "0000-00-00 00:00:00.0000000") c.Assert(err, IsNil) - d, err = dumpBinaryDateTime(nil, t, nil) - c.Assert(err, IsNil) + d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) t, err = types.ParseDate(nil, "0000-00-00") c.Assert(err, IsNil) - d, err = dumpBinaryDateTime(nil, t, nil) + d = dumpBinaryDateTime(nil, t) + c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) + +<<<<<<< HEAD +======= + t, err = types.ParseDate(nil, "0000-00-00") c.Assert(err, IsNil) + d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) +>>>>>>> efa179c... server: fix potential timezone related bugs caused by `time.Local` (#14572) myDuration, err := types.ParseDuration(nil, "0000-00-00 00:00:00.0000000", 6) c.Assert(err, IsNil) d = dumpBinaryTime(myDuration.Duration) From af33f5f64c5a16ec3dcf4d0d5a67a1b9c6d00b03 Mon Sep 17 00:00:00 2001 From: reafans Date: Wed, 15 Apr 2020 11:02:06 +0800 Subject: [PATCH 2/3] fix conflict --- server/util.go | 17 +---------------- server/util_test.go | 3 --- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/server/util.go b/server/util.go index 0e7da3e6133d5..5314e24684c04 100644 --- a/server/util.go +++ b/server/util.go @@ -200,24 +200,9 @@ func dumpBinaryTime(dur time.Duration) (data []byte) { return } -<<<<<<< HEAD -func dumpBinaryDateTime(data []byte, t types.Time, loc *time.Location) ([]byte, error) { - if t.Type == mysql.TypeTimestamp && loc != nil { - // TODO: Consider time_zone variable. - t1, err := t.Time.GoTime(time.Local) - if err != nil { - return nil, errors.Errorf("FATAL: convert timestamp %v go time return error!", t.Time) - } - t.Time = types.FromGoTime(t1.In(loc)) - } - +func dumpBinaryDateTime(data []byte, t types.Time) []byte { year, mon, day := t.Time.Year(), t.Time.Month(), t.Time.Day() switch t.Type { -======= -func dumpBinaryDateTime(data []byte, t types.Time) []byte { - year, mon, day := t.Year(), t.Month(), t.Day() - switch t.Type() { ->>>>>>> efa179c... server: fix potential timezone related bugs caused by `time.Local` (#14572) case mysql.TypeTimestamp, mysql.TypeDatetime: data = append(data, 11) data = dumpUint16(data, uint16(year)) diff --git a/server/util_test.go b/server/util_test.go index cc541f90bbbff..70f60569cd1b2 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -73,14 +73,11 @@ func (s *testUtilSuite) TestDumpBinaryTime(c *C) { d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) -<<<<<<< HEAD -======= t, err = types.ParseDate(nil, "0000-00-00") c.Assert(err, IsNil) d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) ->>>>>>> efa179c... server: fix potential timezone related bugs caused by `time.Local` (#14572) myDuration, err := types.ParseDuration(nil, "0000-00-00 00:00:00.0000000", 6) c.Assert(err, IsNil) d = dumpBinaryTime(myDuration.Duration) From 0db3df781d20e7005d8a115d40ac7ba662d70858 Mon Sep 17 00:00:00 2001 From: reafans Date: Wed, 15 Apr 2020 11:33:26 +0800 Subject: [PATCH 3/3] refine --- server/util_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/util_test.go b/server/util_test.go index 70f60569cd1b2..4d979f09dcd38 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -73,11 +73,6 @@ func (s *testUtilSuite) TestDumpBinaryTime(c *C) { d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) - t, err = types.ParseDate(nil, "0000-00-00") - c.Assert(err, IsNil) - d = dumpBinaryDateTime(nil, t) - c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) - myDuration, err := types.ParseDuration(nil, "0000-00-00 00:00:00.0000000", 6) c.Assert(err, IsNil) d = dumpBinaryTime(myDuration.Duration)