diff --git a/br/pkg/lightning/restore/restore.go b/br/pkg/lightning/restore/restore.go index 69b213c368..7ea7be3c9d 100644 --- a/br/pkg/lightning/restore/restore.go +++ b/br/pkg/lightning/restore/restore.go @@ -770,7 +770,12 @@ func (rc *Controller) restoreSchema(ctx context.Context) error { go rc.listenCheckpointUpdates() - rc.sysVars = ObtainImportantVariables(ctx, rc.tidbGlue.GetSQLExecutor(), !rc.isTiDBBackend()) + sysVars := ObtainImportantVariables(ctx, rc.tidbGlue.GetSQLExecutor(), !rc.isTiDBBackend()) + // override by manually set vars + for k, v := range rc.cfg.TiDB.Vars { + sysVars[k] = v + } + rc.sysVars = sysVars // Estimate the number of chunks for progress reporting err = rc.estimateChunkCountIntoMetrics(ctx) diff --git a/br/pkg/lightning/restore/restore_test.go b/br/pkg/lightning/restore/restore_test.go index bbd23cbd71..fc44917fdf 100644 --- a/br/pkg/lightning/restore/restore_test.go +++ b/br/pkg/lightning/restore/restore_test.go @@ -1553,8 +1553,23 @@ func (s *restoreSchemaSuite) TearDownTest(c *C) { } func (s *restoreSchemaSuite) TestRestoreSchemaSuccessful(c *C) { + // before restore, if sysVars is initialized by other test, the time_zone should be default value + if len(s.rc.sysVars) > 0 { + tz, ok := s.rc.sysVars["time_zone"] + c.Assert(ok, IsTrue) + c.Assert(tz, Equals, "SYSTEM") + } + + s.rc.cfg.TiDB.Vars = map[string]string{ + "time_zone": "UTC", + } err := s.rc.restoreSchema(s.ctx) c.Assert(err, IsNil) + + // test after restore schema, sysVars has been updated + tz, ok := s.rc.sysVars["time_zone"] + c.Assert(ok, IsTrue) + c.Assert(tz, Equals, "UTC") } func (s *restoreSchemaSuite) TestRestoreSchemaFailed(c *C) { diff --git a/br/pkg/lightning/restore/tidb.go b/br/pkg/lightning/restore/tidb.go index 31639ffdfd..680cd1558e 100644 --- a/br/pkg/lightning/restore/tidb.go +++ b/br/pkg/lightning/restore/tidb.go @@ -83,7 +83,6 @@ func isUnknownSystemVariableErr(err error) bool { } func DBFromConfig(ctx context.Context, dsn config.DBStore) (*sql.DB, error) { - param := common.MySQLConnectParam{ Host: dsn.Host, Port: dsn.Port,