Skip to content

Commit

Permalink
domain: adjust initialization sequence of domain-reload and ddl-start…
Browse files Browse the repository at this point in the history
… to avoid infoCache nil (pingcap#28945)
  • Loading branch information
AilinKid authored Oct 21, 2021
1 parent eca2dbb commit 6219010
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
32 changes: 15 additions & 17 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,24 +737,31 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R
ddl.WithHook(callback),
ddl.WithLease(ddlLease),
)
err = do.ddl.Start(sysCtxPool)
if err != nil {
return err
}
failpoint.Inject("MockReplaceDDL", func(val failpoint.Value) {
if val.(bool) {
if err := do.ddl.Stop(); err != nil {
logutil.BgLogger().Error("stop DDL failed", zap.Error(err))
}
do.ddl = d
}
})

// step 1: prepare the info/schema syncer which domain reload needed.
skipRegisterToDashboard := config.GetGlobalConfig().SkipRegisterToDashboard
do.info, err = infosync.GlobalInfoSyncerInit(ctx, do.ddl.GetID(), do.ServerID, do.etcdClient, skipRegisterToDashboard)
if err != nil {
return err
}
err = do.ddl.SchemaSyncer().Init(ctx)
if err != nil {
return err
}
// step 2: domain reload the infoSchema.
err = do.Reload()
if err != nil {
return err
}
// step 3: start the ddl after the domain reload, avoiding some internal sql running before infoSchema construction.
err = do.ddl.Start(sysCtxPool)
if err != nil {
return err
}

if config.GetGlobalConfig().Experimental.EnableGlobalKill {
if do.etcdClient != nil {
Expand All @@ -774,15 +781,6 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R
}
}

do.info, err = infosync.GlobalInfoSyncerInit(ctx, do.ddl.GetID(), do.ServerID, do.etcdClient, skipRegisterToDashboard)
if err != nil {
return err
}
err = do.Reload()
if err != nil {
return err
}

// Only when the store is local that the lease value is 0.
// If the store is local, it doesn't need loadSchemaInLoop.
if ddlLease > 0 {
Expand Down
1 change: 0 additions & 1 deletion domain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func SubTestInfo(t *testing.T) {
ddl.WithInfoCache(dom.infoCache),
ddl.WithLease(ddlLease),
)
require.NoError(t, dom.ddl.Start(nil))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/domain/MockReplaceDDL", `return(true)`))
require.NoError(t, dom.Init(ddlLease, sysMockFactory))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/domain/MockReplaceDDL"))
Expand Down

0 comments on commit 6219010

Please sign in to comment.