Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

use system_time_zone to encode kv if tidb set it #564

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
@@ -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"
)
@@ -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

1 change: 1 addition & 0 deletions lightning/restore/tidb.go
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 2 additions & 0 deletions lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
@@ -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",
@@ -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",