Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor, store: fixed daylight saving time issue #6823

Merged
merged 33 commits into from
Jul 16, 2018

Conversation

zhexuany
Copy link
Contributor

@zhexuany zhexuany commented Jun 12, 2018

Thank you for working on TiDB! Please read TiDB's CONTRIBUTING document BEFORE filing this PR.

What have you changed? (mandatory)

During coprocessor dag task, it first uses timezone name, if non-empty, to get legitimate timezone variable. To achieve this, we need push down such data into tikv which leads to change the logic of building pushdown request. The logic I mentioned mainly resides in executor package.

I change timeZoneOffset to zone and add second return parameter name string. The intentioned of doing this to adopt the convention of time package.

For the same purpose, I change GetTimeZone to Location. As you can see, in time package, timezone was bind to Location.

What are the type of the changes (mandatory)?

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this PR been tested (mandatory)?

@@ -1098,7 +1099,7 @@ func (b *executorBuilder) buildAnalyzeIndexPushdown(task plan.AnalyzeIndexTask)
Tp: tipb.AnalyzeType_TypeIndex,
StartTs: math.MaxUint64,
Flags: statementContextToFlags(b.ctx.GetSessionVars().StmtCtx),
TimeZoneOffset: timeZoneOffset(b.ctx),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lamxTyler For analyse executor, do we need timezone name too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not need.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lamxTyler Is offset needed in analyzer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @lamxTyler

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems not needned.

@zhexuany zhexuany force-pushed the fix_daylight_saving_time_issue branch from 2fcc3a2 to 4a59ac4 Compare June 12, 2018 16:59
@shenli
Copy link
Member

shenli commented Jun 12, 2018

  1. DO NOT leave the description empty
  2. Could you move the vendor updating into a separate commit?

@zhexuany
Copy link
Contributor Author

@shenli I usually created PR via command-line. That is being said, I will fill info later via website.

For second question, I can certainly do this.

@shenli
Copy link
Member

shenli commented Jun 14, 2018

Please fix the CI and resolve the conflicts.

@zhexuany zhexuany force-pushed the fix_daylight_saving_time_issue branch 8 times, most recently from 654c0d9 to 61e72f8 Compare June 17, 2018 08:51
@shenli
Copy link
Member

shenli commented Jun 19, 2018

Please fix the CI.

@zhexuany zhexuany force-pushed the fix_daylight_saving_time_issue branch from e3d702f to 249bd55 Compare June 24, 2018 04:48
@zhexuany
Copy link
Contributor Author

/run-all-tests

@zhexuany
Copy link
Contributor Author

@shenli I was on a vacation break. Sorry for the delay. Now, CI has been fixed. PTAL

@coocood
Copy link
Member

coocood commented Jun 27, 2018

@zhexuany
The default location name is Local, can tikv handle this?

@zhexuany
Copy link
Contributor Author

Already checked with engineer from tikv. TiKV does not need handle this.

@zhexuany
Copy link
Contributor Author

time.LoadLocation is super slow because it read zip file from disk. I am diving into this and trying to find an alternative way to improve this.

var LocCache *locCache

func (lm *locCache) getLoc(name string) (*time.Location, error) {
if v, ok := lm.locMap[name]; ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need read lock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This was already fixed.

@zhexuany zhexuany force-pushed the fix_daylight_saving_time_issue branch from c8e3626 to eb92e87 Compare July 13, 2018 13:05
@@ -1889,7 +1889,7 @@ func (b *builtinSysDateWithFspSig) evalTime(row types.Row) (d types.Time, isNull
return types.Time{}, isNull, errors.Trace(err)
}

tz := b.ctx.GetSessionVars().GetTimeZone()
tz := b.ctx.GetSessionVars().Location()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/tz/loc/?

// GetTimeZone returns the value of time_zone session variable.
func (s *SessionVars) GetTimeZone() *time.Location {
// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to rename s.TimeZone to s.Location or any other proper names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location is better and also time package uses the same name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do it in another PR, keep this PR focused on the daylight saving time issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already did - -.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to Loc eventually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor Author

@zhexuany zhexuany Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a conflict and to avoid further change I undo my changes and I will file another PR for changing this once this PR gets merged into master.

if err != nil {
_, err1 := se.Execute(ctx, "ROLLBACK")
terror.Log(errors.Trace(err1))
return false, errors.Trace(err)
}
err = w.saveTime(gcLeaderLeaseKey, time.Now().Add(gcWorkerLease), se)
fmt.Println("fuck" + time.Now().String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove debug log.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahahaha! @zhexuany

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally understand your mind!

@zhexuany zhexuany force-pushed the fix_daylight_saving_time_issue branch from 6573b27 to 690c644 Compare July 13, 2018 14:46
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1272,7 +1275,7 @@ func (b *executorBuilder) buildAnalyzeColumnsPushdown(task plan.AnalyzeColumnsTa
Tp: tipb.AnalyzeType_TypeColumn,
StartTs: math.MaxUint64,
Flags: statementContextToFlags(b.ctx.GetSessionVars().StmtCtx),
TimeZoneOffset: timeZoneOffset(b.ctx),
TimeZoneOffset: offset,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add TimeZoneName in Analyze request? @lamxTyler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already confirmed with him. No need to consider dst in statistics.

@@ -1938,6 +1938,7 @@ func (s *testSuite) TestTimestampTimeZone(c *C) {
r.Check(testkit.Rows("123381351 1734 2014-03-31 08:57:10 127.0.0.1")) // Cover IndexLookupExec

// For issue https://github.com/pingcap/tidb/issues/3485
tk.MustExec("set time_zone = 'Asia/Shanghai'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we add this line? Is there any dst issue in the test case?

Copy link
Contributor Author

@zhexuany zhexuany Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to line 1907. It sets timezone with offset -6. If we want to compare datetime correctly, we have to set timezone as Asia/Shanghai.

// Talked with Golang team about whether they can have some forms of cache policy available for programmer,
// they suggests that only programmers knows which one is best for their use case.
// For detail, please refer to: https://github.com/golang/go/issues/26106
type locCache struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about locationCache? locCache looks like lockCache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loc is generally used everywhere in our codebase. Additionally, it is generally used in time package.

if sc.TimeZone, err = LocCache.getLoc(dagReq.TimeZoneName); err != nil {
return nil, nil, nil, errors.Trace(err)
}
dagReq.TimeZoneName = sc.TimeZone.String()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set dagReq.TimeZoneName ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set dagReq.TimeZoneOffset here, so do dagReq.TimeZoneName.

@@ -240,7 +240,7 @@ func (w *GCWorker) leaderTick(ctx context.Context) error {
return nil
}

// prepare checks required conditions for starting a GC job. It returns a bool
// prepare checks preconditions for starting a GC job. It returns a bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this file? Is it related to the dst issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It has nothing to do with dst issue. I change it mainly becuase GCoworker already has session as its variable so we do not need access such info with passing it as parameter around.

I found this on the way fixing dst, it should be done via another PR. I will be carefully next time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@shenli
Copy link
Member

shenli commented Jul 16, 2018

LGTM

@shenli
Copy link
Member

shenli commented Jul 16, 2018

/run-all-tests

@shenli shenli added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 16, 2018
@coocood
Copy link
Member

coocood commented Jul 16, 2018

@zhexuany Please resolve the conflict.

@zhexuany
Copy link
Contributor Author

@coocood conflict was already resolved.

@zhexuany zhexuany merged commit 7c18d24 into pingcap:master Jul 16, 2018
@zhexuany zhexuany deleted the fix_daylight_saving_time_issue branch July 16, 2018 10:15
zhexuany added a commit to zhexuany/tidb that referenced this pull request Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/coprocessor status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants