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

*: write system timezone into mysql.tidb in bootstrap stage. #7638

Merged
merged 63 commits into from
Sep 14, 2018

Conversation

zhexuany
Copy link
Contributor

@zhexuany zhexuany commented Sep 7, 2018

What problem does this PR solve?

It retrieves real IANA timezone name when the location is local. This can avoid the performance delegation on TiKV side.

What is changed and how it works?

We need first get the soft link from /etc/localtime. And then check whether the soft link path contains share/zoneinfo or not. If yes, we get the real IANA timezone name from this path.

If you want to know more about how this PR works please refer to this PR

Check List

Tests

  • Unit test

Code changes

Side effects

Related changes

  • Need to be included in the release note

@zhexuany zhexuany force-pushed the get_tz_name_from_zoneinfo branch 2 times, most recently from 8d368ea to de4a579 Compare September 7, 2018 06:23
@zhexuany zhexuany force-pushed the get_tz_name_from_zoneinfo branch from de4a579 to ec6a822 Compare September 7, 2018 06:24
@@ -139,9 +141,15 @@ func zone(sctx sessionctx.Context) (string, int64) {
if name == "Local" {
path, err := filepath.EvalSymlinks("/etc/localtime")
if err != nil {
log.Errorln(err)
return "Sysytem", int64(offset)
Copy link
Member

Choose a reason for hiding this comment

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

System?

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. I have no idea why this happens. - - Already fixed.

@@ -117,6 +119,18 @@ func closeAll(objs ...Closeable) error {
return errors.Trace(err)
}

// GetTZNameFromFileName gets IANA timezone name from zoninfo path.
Copy link
Member

Choose a reason for hiding this comment

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

s/zoninfo/zoneinfo

path, err := filepath.EvalSymlinks("/etc/localtime")
if err != nil {
log.Errorln(err)
return "Sysytem", int64(offset)
Copy link
Member

Choose a reason for hiding this comment

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

s/Sysytem/System

idx := strings.Index(path, substr)
return string(path[idx+len(substr)+1:]), nil
}
return "", errors.New("only support softlink has share/zoneinfo as a suffix" + path)
Copy link
Member

Choose a reason for hiding this comment

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

maybe this is not kind of a suffix?

@@ -164,13 +165,26 @@ func (h *rpcHandler) buildDAGExecutor(req *coprocessor.Request) (*dagContext, ex
return ctx, e, dagReq, err
}

func getTZNameFromFileName(path string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

why is it implemented again here?

@@ -127,7 +141,17 @@ func zone(sctx sessionctx.Context) (string, int64) {
var name string
name = loc.String()
if name == "Local" {
name = "System"
path, err := filepath.EvalSymlinks("/etc/localtime")
Copy link
Member

Choose a reason for hiding this comment

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

How is this function evaluated? If it is evaluated frequently, we need to cache the zone.

Copy link
Member

Choose a reason for hiding this comment

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

Agree.

idx := strings.Index(path, substr)
return string(path[idx+len(substr)+1:]), nil
}
return "", errors.New("only support softlink has share/zoneinfo as a suffix" + path)
Copy link
Contributor

Choose a reason for hiding this comment

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

should be "as a prefix"?

@@ -164,13 +165,26 @@ func (h *rpcHandler) buildDAGExecutor(req *coprocessor.Request) (*dagContext, ex
return ctx, e, dagReq, err
}

func getTZNameFromFileName(path string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems be duplicated to GetTZNameFromFileName and no any caller~?

Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

The new cache seems good to me

breezewish
breezewish previously approved these changes Sep 7, 2018
@zhexuany
Copy link
Contributor Author

zhexuany commented Sep 7, 2018

@lysu PTAL

breezewish
breezewish previously approved these changes Sep 8, 2018
Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@coocood
Copy link
Member

coocood commented Sep 8, 2018

LGTM

@coocood
Copy link
Member

coocood commented Sep 8, 2018

/run-all-tests

@zhexuany
Copy link
Contributor Author

zhexuany commented Sep 8, 2018

/run-all-tests


// Local returns time.Local's IANA timezone name. It is TiDB's global timezone name.
func Local() *time.Location {
loc, err := LoadLocation(systemTZ)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happen when Local() is called before or during cluster bootstrapping ?
systemTZ is not initialized yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see line 11. I assign "System" to it in order to avoid test case failure.

@zhexuany zhexuany force-pushed the get_tz_name_from_zoneinfo branch from 1389abc to bd1693e Compare September 14, 2018 03:31
@zhexuany
Copy link
Contributor Author

zhexuany commented Sep 14, 2018

@shenli @tiancaiamao @breeswish PTAL

@zhexuany
Copy link
Contributor Author

/run-all-tests

func loadSystemTZ(se *session) (string, error) {
sql := `select variable_value from mysql.tidb where variable_name = "system_tz"`
rss, errLoad := se.Execute(context.Background(), sql)
defer rss[0].Close()
Copy link
Member

Choose a reason for hiding this comment

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

If errLoad is not nill, the rss maybe empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@zhexuany
Copy link
Contributor Author

@shenli @tiancaiamao PTAL

session/session.go Outdated Show resolved Hide resolved
@zhexuany zhexuany force-pushed the get_tz_name_from_zoneinfo branch 2 times, most recently from 2212e63 to fb8584d Compare September 14, 2018 08:49
@zhexuany zhexuany force-pushed the get_tz_name_from_zoneinfo branch from fb8584d to 64a5b2e Compare September 14, 2018 08:53
}

// getLoc first trying to load location from a cache map. If nothing found in such map, then call
// `time.LoadLocation` to get a timezone location. After trying both way, an error wil be returned
Copy link
Member

Choose a reason for hiding this comment

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

s/wil be/will be/

// `time.LoadLocation` to get a timezone location. After trying both way, an error wil be returned
// if valid Location is not found.
func (lm *locCache) getLoc(name string) (*time.Location, error) {
if name == "System" {
Copy link
Member

Choose a reason for hiding this comment

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

Define a constant for "System". Should we consider case insensitive comparison?

name = loc.String()
// when we found name is "SystemLocation", we have no chice but push down
// "System" to tikv side.
if name == "Local" {
Copy link
Member

Choose a reason for hiding this comment

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

Define a constant for "Local".

Copy link
Contributor

Choose a reason for hiding this comment

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

Please make sure TiKV would handle this @breeswish

@tiancaiamao
Copy link
Contributor

LGTM @shenli

@coocood
Copy link
Member

coocood commented Sep 14, 2018

/run-all-tests

@zhexuany
Copy link
Contributor Author

@shenli @coocood All tests passed.

@shenli shenli merged commit 2944195 into pingcap:master Sep 14, 2018
@zhexuany zhexuany deleted the get_tz_name_from_zoneinfo branch September 14, 2018 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/coprocessor priority/release-blocker This issue blocks a release. Please solve it ASAP. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants