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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ec6a822
get tz name from zoneinfo
zhexuany Sep 7, 2018
40f1caf
remove imports
zhexuany Sep 7, 2018
ad574a4
add comment
zhexuany Sep 7, 2018
e76c224
correct a spelling
zhexuany Sep 7, 2018
a74739c
called once for evalSys
zhexuany Sep 7, 2018
f0502c8
address comments
zhexuany Sep 7, 2018
ed136b9
remove unecessary import
zhexuany Sep 7, 2018
085dc79
Merge branch 'master' into get_tz_name_from_zoneinfo
zhexuany Sep 8, 2018
8ba623f
rewrite code
zhexuany Sep 8, 2018
13c7c1b
Merge branch 'get_tz_name_from_zoneinfo' of github.com:zhexuany/tidb …
zhexuany Sep 8, 2018
e962f82
print localStr out
zhexuany Sep 8, 2018
26f65f7
set time_zone in test
zhexuany Sep 8, 2018
d708186
align tz behavior with golang
zhexuany Sep 8, 2018
ceedc34
when tz is empty use localtime
zhexuany Sep 8, 2018
2adc1e8
adding timeutil package
zhexuany Sep 8, 2018
acc0262
make the use of time.Now in expression correct
zhexuany Sep 8, 2018
709c32c
remoeve unecessay file
zhexuany Sep 8, 2018
350d27d
adding test and debug print
zhexuany Sep 9, 2018
c95e6c3
print tz in initLocalStr
zhexuany Sep 9, 2018
21e9e22
move zone to timeutil
zhexuany Sep 9, 2018
a84c028
remove prev changes
zhexuany Sep 9, 2018
c1658d8
init localstr in bootstrap stage
zhexuany Sep 11, 2018
a517a43
init localstr in bootstrap stage
zhexuany Sep 11, 2018
b5e39b6
load system tz by select
zhexuany Sep 12, 2018
84b6e8f
address comment
zhexuany Sep 12, 2018
dae8a5a
correct test case
zhexuany Sep 12, 2018
5c373bf
fix conflict
zhexuany Sep 12, 2018
2d0aca2
fix ci
zhexuany Sep 12, 2018
e624443
remove shadow err
zhexuany Sep 12, 2018
f3ad3bc
remove err shadow
zhexuany Sep 12, 2018
692d4d5
address comment
zhexuany Sep 13, 2018
b32bdd2
remove extra print
zhexuany Sep 13, 2018
49454d5
add more comment
zhexuany Sep 13, 2018
318c12b
address comments
zhexuany Sep 13, 2018
cb5fd7d
address comments
zhexuany Sep 13, 2018
ec66759
fix build error
zhexuany Sep 13, 2018
a3c3cc4
fix test error
zhexuany Sep 13, 2018
3976eda
load system tz after bootstrap
zhexuany Sep 13, 2018
d522982
address comments
zhexuany Sep 13, 2018
dd2d0c9
move code around to avoid critical section
zhexuany Sep 13, 2018
29679ab
remove callback
zhexuany Sep 13, 2018
733331e
remove extra comment
zhexuany Sep 13, 2018
e9bb73b
polish comment of fn
zhexuany Sep 13, 2018
1d8ddfa
fix ci
zhexuany Sep 13, 2018
bd24bee
make code cleanner
zhexuany Sep 13, 2018
2f8018a
correct set time_zone behavior
zhexuany Sep 13, 2018
7d6ae04
add test
zhexuany Sep 13, 2018
d315b25
address comment
zhexuany Sep 13, 2018
5dc988b
fix comment spelling issue
zhexuany Sep 13, 2018
1f99ca1
use one hook
zhexuany Sep 13, 2018
e4418cf
remove boot
zhexuany Sep 13, 2018
44996c2
add extra space
zhexuany Sep 13, 2018
bd1693e
address comment
zhexuany Sep 14, 2018
fda4813
fix ci
zhexuany Sep 14, 2018
9986492
Merge branch 'master' into get_tz_name_from_zoneinfo
zhexuany Sep 14, 2018
1acd491
move code after checking errLoad
zhexuany Sep 14, 2018
65051bb
Merge branch 'get_tz_name_from_zoneinfo' of github.com:zhexuany/tidb …
zhexuany Sep 14, 2018
a37aeeb
add comment
zhexuany Sep 14, 2018
e20dc07
remove reset chk
zhexuany Sep 14, 2018
74d394a
rename local fn
zhexuany Sep 14, 2018
64a5b2e
fix ci
zhexuany Sep 14, 2018
e77ee43
fix ci
zhexuany Sep 14, 2018
1b53dff
Merge branch 'master' into get_tz_name_from_zoneinfo
zhexuany Sep 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ package executor

import (
"math"
"path/filepath"
"runtime"
"sort"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -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

// TODO It will be refined later. This is just a quick fix.
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.

It is better to move this function to util/xxx package.

// phase1 only support read /etc/localtime which is a softlink to zoneinfo file
substr := "share/zoneinfo"
if strings.Contains(path, substr) {
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?

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"?

}

// zone returns the current timezone name and timezone offset in seconds.
// In compatible with MySQL, we change `Local` to `System`.
// TODO: Golang team plan to return system timezone name intead of
Expand All @@ -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.

if err != nil {
log.Errorln(err)
return "System", int64(offset)
}
name, err = GetTZNameFromFileName(path)
if err != nil {
log.Errorln(err)
return "System", int64(offset)
}
return name, int64(offset)
}

return name, int64(offset)
Expand Down
6 changes: 6 additions & 0 deletions executor/distsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,9 @@ func (s *testSuite) TestUniqueKeyNullValueSelect(c *C) {
res = tk.MustQuery("select * from t where id is null;")
res.Check(testkit.Rows("<nil> a", "<nil> b", "<nil> c"))
}

func (s *testSuite) TestgetTZNameFromFileName(c *C) {
tz, err := executor.GetTZNameFromFileName("/user/share/zoneinfo/Asia/Shanghai")
c.Assert(err, IsNil)
c.Assert(tz, Equals, "Asia/Shanghai")
}
14 changes: 14 additions & 0 deletions store/mockstore/mocktikv/cop_handler_dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"fmt"
"io"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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?

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~?

// phase1 only support read /etc/localtime which is a softlink to zoneinfo file
substr := "share/zoneinfo"
if strings.Contains(path, substr) {
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)
}

// constructTimeZone constructs timezone by name first. When the timezone name
// is set, the daylight saving problem must be considered. Otherwise the
// timezone offset in seconds east of UTC is used to constructed the timezone.
func constructTimeZone(name string, offset int) (*time.Location, error) {
if name != "" {
// no need to care about case since name is retreved
// from go std library call
return LocCache.getLoc(name)
}

Copy link
Member

Choose a reason for hiding this comment

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

remove this empty line

return time.FixedZone("", offset), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

When will the code run to this branch and what happen then ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

user runs set time_zone="+8:00"?

Copy link
Contributor

Choose a reason for hiding this comment

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

But the time zone name is not "UTC" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, the name should be "empty".

Copy link
Contributor

Choose a reason for hiding this comment

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

Will TiKV handle that ? @breeswish

}

Expand Down