-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
8d368ea
to
de4a579
Compare
de4a579
to
ec6a822
Compare
executor/distsql.go
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System
?
There was a problem hiding this comment.
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.
executor/distsql.go
Outdated
@@ -117,6 +119,18 @@ func closeAll(objs ...Closeable) error { | |||
return errors.Trace(err) | |||
} | |||
|
|||
// GetTZNameFromFileName gets IANA timezone name from zoninfo path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/zoninfo/zoneinfo
executor/distsql.go
Outdated
path, err := filepath.EvalSymlinks("/etc/localtime") | ||
if err != nil { | ||
log.Errorln(err) | ||
return "Sysytem", int64(offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Sysytem/System
executor/distsql.go
Outdated
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
executor/distsql.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
executor/distsql.go
Outdated
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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~?
There was a problem hiding this 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
@lysu PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM |
/run-all-tests |
…into get_tz_name_from_zoneinfo
/run-all-tests |
util/timeutil/time.go
Outdated
|
||
// Local returns time.Local's IANA timezone name. It is TiDB's global timezone name. | ||
func Local() *time.Location { | ||
loc, err := LoadLocation(systemTZ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
1389abc
to
bd1693e
Compare
@shenli @tiancaiamao @breeswish PTAL |
/run-all-tests |
session/session.go
Outdated
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@shenli @tiancaiamao PTAL |
2212e63
to
fb8584d
Compare
fb8584d
to
64a5b2e
Compare
util/timeutil/time.go
Outdated
} | ||
|
||
// 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 |
There was a problem hiding this comment.
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/
util/timeutil/time.go
Outdated
// `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" { |
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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
LGTM @shenli |
/run-all-tests |
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 containsshare/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
Code changes
Side effects
Related changes