Skip to content

Commit

Permalink
address reviewer's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
zhexuany committed Jul 13, 2018
1 parent 0bc91cb commit 690c644
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -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)
}
}
8 changes: 4 additions & 4 deletions plan/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion plan/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sessionctx/variable/varsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion store/tikv/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 690c644

Please sign in to comment.