Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion lightning/backend/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"errors"
"fmt"
"strconv"
"time"

"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/timeutil"

"github.com/pingcap/tidb-lightning/lightning/common"
)
Expand Down Expand Up @@ -194,12 +196,31 @@ func newSession(options *SessionOptions) *session {
vars.StmtCtx.OverflowAsWarning = !sqlMode.HasStrictMode()
vars.StmtCtx.AllowInvalidDate = sqlMode.HasAllowInvalidDatesMode()
vars.StmtCtx.IgnoreZeroInDate = !sqlMode.HasStrictMode() || sqlMode.HasAllowInvalidDatesMode()
var tz *time.Location
if options.SysVars != nil {
var tidbTimeZone, tidbSystemTimeZone string
for k, v := range options.SysVars {
vars.SetSystemVar(k, v)
if k == "time_zone" {
tidbTimeZone = v
}
if k == "system_time_zone" {
tidbSystemTimeZone = v
}
}
// if we get system zone from TiDB server, we can set it for lightning session.
if tidbTimeZone == "SYSTEM" && tidbSystemTimeZone != "" {
loc, err := timeutil.LoadLocation(tidbSystemTimeZone)
if err != nil {
loc = time.Local
}
tz = loc
}
}
if tz == nil {
tz = vars.Location()
}
vars.StmtCtx.TimeZone = vars.Location()
vars.StmtCtx.TimeZone = tz
vars.SetSystemVar("timestamp", strconv.FormatInt(options.Timestamp, 10))
vars.TxnCtx = nil

Expand Down
1 change: 1 addition & 0 deletions lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
"max_allowed_packet": "67108864",
"div_precision_increment": "4",
"time_zone": "SYSTEM",
"system_time_zone": "",
"lc_time_names": "en_US",
"default_week_format": "0",
"block_encryption_mode": "aes-128-ecb",
Expand Down
2 changes: 2 additions & 0 deletions lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func (s *tidbSuite) TestObtainRowFormatVersionSucceed(c *C) {
c.Assert(sysVars, DeepEquals, map[string]string{
"tidb_row_format_version": "2",
"max_allowed_packet": "1073741824",
"system_time_zone": "",
"div_precision_increment": "10",
"time_zone": "-08:00",
"lc_time_names": "ja_JP",
Expand All @@ -442,6 +443,7 @@ func (s *tidbSuite) TestObtainRowFormatVersionFailure(c *C) {
c.Assert(sysVars, DeepEquals, map[string]string{
"tidb_row_format_version": "1",
"max_allowed_packet": "67108864",
"system_time_zone": "",
"div_precision_increment": "4",
"time_zone": "+00:00",
"lc_time_names": "en_US",
Expand Down