diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 8b74c95e53972..4ee4f9036a106 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -1889,8 +1889,8 @@ func (b *builtinSysDateWithFspSig) evalTime(row types.Row) (d types.Time, isNull return types.Time{}, isNull, errors.Trace(err) } - tz := b.ctx.GetSessionVars().Location() - now := time.Now().In(tz) + loc := b.ctx.GetSessionVars().Location() + now := time.Now().In(loc) result, err := convertTimeToMysqlTime(now, int(fsp)) if err != nil { return types.Time{}, true, errors.Trace(err) @@ -3663,7 +3663,7 @@ func getBf4TimeAddSub(ctx sessionctx.Context, args []Expression) (tp1, tp2 *type } func getTimeZone(ctx sessionctx.Context) *time.Location { - ret := ctx.GetSessionVars().TimeZone + ret := ctx.GetSessionVars().Loc if ret == nil { ret = time.Local } diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 381a69aff0721..f82e1aa3f330d 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1447,7 +1447,7 @@ func (s *testEvaluatorSuite) TestUnixTimestamp(c *C) { c.Assert(d.IsNull(), Equals, true) // Set the time_zone variable, because UnixTimestamp() result depends on it. - s.ctx.GetSessionVars().TimeZone = time.UTC + s.ctx.GetSessionVars().Loc = time.UTC tests := []struct { inputDecimal int input types.Datum @@ -2213,9 +2213,9 @@ func (s *testEvaluatorSuite) TestLastDay(c *C) { func (s *testEvaluatorSuite) TestWithTimeZone(c *C) { sv := s.ctx.GetSessionVars() originTZ := sv.Location() - sv.TimeZone, _ = time.LoadLocation("Asia/Tokyo") + sv.Loc, _ = time.LoadLocation("Asia/Tokyo") defer func() { - sv.TimeZone = originTZ + sv.Loc = originTZ }() timeToGoTime := func(d types.Datum, loc *time.Location) time.Time { @@ -2224,7 +2224,7 @@ func (s *testEvaluatorSuite) TestWithTimeZone(c *C) { } durationToGoTime := func(d types.Datum, loc *time.Location) time.Time { t, _ := d.GetMysqlDuration().ConvertToTime(sv.StmtCtx, mysql.TypeDatetime) - result, _ := t.Time.GoTime(sv.TimeZone) + result, _ := t.Time.GoTime(sv.Loc) return result } @@ -2242,11 +2242,11 @@ func (s *testEvaluatorSuite) TestWithTimeZone(c *C) { } for _, t := range tests { - now := time.Now().In(sv.TimeZone) + now := time.Now().In(sv.Loc) f, err := funcs[t.method].getFunction(s.ctx, s.datumsToConstants(t.Input)) d, err := evalBuiltinFunc(f, nil) c.Assert(err, IsNil) - result := t.convertToTime(d, sv.TimeZone) + result := t.convertToTime(d, sv.Loc) c.Assert(result.Sub(now), LessEqual, 2*time.Second) } } diff --git a/plan/cache.go b/plan/cache.go index c85fc363c0f05..aa1002d01b7f7 100644 --- a/plan/cache.go +++ b/plan/cache.go @@ -80,8 +80,8 @@ func (key *sqlCacheKey) Hash() []byte { // NewSQLCacheKey creates a new sqlCacheKey object. func NewSQLCacheKey(sessionVars *variable.SessionVars, sql string, schemaVersion int64, readOnly bool) kvcache.Key { timezoneOffset, user, host := 0, "", "" - if sessionVars.TimeZone != nil { - _, timezoneOffset = time.Now().In(sessionVars.TimeZone).Zone() + if sessionVars.Loc != nil { + _, timezoneOffset = time.Now().In(sessionVars.Loc).Zone() } if sessionVars.User != nil { user = sessionVars.User.Username @@ -135,8 +135,8 @@ func (key *pstmtPlanCacheKey) Hash() []byte { // NewPSTMTPlanCacheKey creates a new pstmtPlanCacheKey object. func NewPSTMTPlanCacheKey(sessionVars *variable.SessionVars, pstmtID uint32, schemaVersion int64) kvcache.Key { timezoneOffset := 0 - if sessionVars.TimeZone != nil { - _, timezoneOffset = time.Now().In(sessionVars.TimeZone).Zone() + if sessionVars.Loc != nil { + _, timezoneOffset = time.Now().In(sessionVars.Loc).Zone() } return &pstmtPlanCacheKey{ database: sessionVars.CurrentDB, diff --git a/plan/cache_test.go b/plan/cache_test.go index b02f1bb13f6a9..5f3326f48b14f 100644 --- a/plan/cache_test.go +++ b/plan/cache_test.go @@ -31,7 +31,7 @@ func (s *testCacheSuite) SetUpSuite(c *C) { ctx := mockContext() ctx.GetSessionVars().SnapshotTS = 0 ctx.GetSessionVars().SQLMode = mysql.ModeNone - ctx.GetSessionVars().TimeZone = time.UTC + ctx.GetSessionVars().Loc = time.UTC ctx.GetSessionVars().ConnectionID = 0 s.ctx = ctx } diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index d2c0e43518735..f0b9e7136f512 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -255,7 +255,7 @@ type SessionVars struct { // Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. // See https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html - TimeZone *time.Location + Loc *time.Location SQLMode mysql.SQLMode @@ -413,7 +413,7 @@ func (s *SessionVars) GetNextPreparedStmtID() uint32 { // Location returns the value of time_zone session variable. If it is nil, then return time.Local. func (s *SessionVars) Location() *time.Location { - loc := s.TimeZone + loc := s.Loc if loc == nil { loc = time.Local } @@ -458,7 +458,7 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { if err != nil { return errors.Trace(err) } - s.TimeZone = tz + s.Loc = tz case SQLModeVar: val = mysql.FormatSQLModeStr(val) // Modes is a list of different modes separated by commas. diff --git a/sessionctx/variable/varsutil_test.go b/sessionctx/variable/varsutil_test.go index 4ec98a2f26bb8..ff22858646495 100644 --- a/sessionctx/variable/varsutil_test.go +++ b/sessionctx/variable/varsutil_test.go @@ -154,11 +154,11 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) { for _, tt := range tests { err = SetSessionSystemVar(v, TimeZone, types.NewStringDatum(tt.input)) c.Assert(err, IsNil) - c.Assert(v.TimeZone.String(), Equals, tt.expect) + c.Assert(v.Loc.String(), Equals, tt.expect) if tt.compareValue { SetSessionSystemVar(v, TimeZone, types.NewStringDatum(tt.input)) t1 := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) - t2 := time.Date(2000, 1, 1, 0, 0, 0, 0, v.TimeZone) + t2 := time.Date(2000, 1, 1, 0, 0, 0, 0, v.Loc) c.Assert(t2.Sub(t1), Equals, tt.diff) } } diff --git a/store/tikv/gcworker/gc_worker.go b/store/tikv/gcworker/gc_worker.go index 082a8729de5ab..d29c4b91b6022 100644 --- a/store/tikv/gcworker/gc_worker.go +++ b/store/tikv/gcworker/gc_worker.go @@ -760,7 +760,6 @@ func (w *GCWorker) checkLeader() (bool, error) { terror.Log(errors.Trace(err1)) return false, errors.Trace(err) } - fmt.Println("fuck" + time.Now().String()) err = w.saveTime(gcLeaderLeaseKey, time.Now().Add(gcWorkerLease)) if err != nil { _, err1 := se.Execute(ctx, "ROLLBACK")