Skip to content

Commit

Permalink
timeutil: do not use system files to verify timezone (pingcap#13593)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored and XiaTianliang committed Dec 21, 2019
1 parent a03ed9c commit 6047102
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions util/timeutil/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package timeutil

import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"
Expand All @@ -41,13 +40,6 @@ var locCa *locCache

// systemTZ is current TiDB's system timezone name.
var systemTZ string
var zoneSources = []string{
"/usr/share/zoneinfo/",
"/usr/share/lib/zoneinfo/",
"/usr/lib/locale/TZ/",
// this is for macOS
"/var/db/timezone/zoneinfo/",
}

// locCache is a simple map with lock. It stores all used timezone during the lifetime of tidb instance.
// Talked with Golang team about whether they can have some forms of cache policy available for programmer,
Expand All @@ -60,7 +52,7 @@ type locCache struct {
}

// InferSystemTZ reads system timezone from `TZ`, the path of the soft link of `/etc/localtime`. If both of them are failed, system timezone will be set to `UTC`.
// It is exported because we need to use it during bootstap stage. And it should be only used at that stage.
// It is exported because we need to use it during bootstrap stage. And it should be only used at that stage.
func InferSystemTZ() string {
// consult $TZ to find the time zone to use.
// no $TZ means use the system default /etc/localtime.
Expand All @@ -79,10 +71,9 @@ func InferSystemTZ() string {
}
logutil.BgLogger().Error("locate timezone files failed", zap.Error(err1))
case tz != "" && tz != "UTC":
for _, source := range zoneSources {
if _, err := os.Stat(source + tz); err == nil {
return tz
}
_, err := time.LoadLocation(tz)
if err == nil {
return tz
}
}
return "UTC"
Expand Down Expand Up @@ -161,8 +152,8 @@ func LoadLocation(name string) (*time.Location, error) {
func Zone(loc *time.Location) (string, int64) {
_, offset := time.Now().In(loc).Zone()
name := loc.String()
// when we found name is "System", we have no chice but push down
// "System" to tikv side.
// when we found name is "System", we have no choice but push down
// "System" to TiKV side.
if name == "Local" {
name = "System"
}
Expand Down

0 comments on commit 6047102

Please sign in to comment.