Skip to content

Commit

Permalink
lightning: let session vars in config also impact kv encoder (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv authored Oct 21, 2021
1 parent 412dd4f commit eca2dbb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion br/pkg/lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions br/pkg/lightning/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit eca2dbb

Please sign in to comment.