diff --git a/session/bootstrap.go b/session/bootstrap.go index 21742acd1..cb888632a 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -449,7 +449,7 @@ func bootstrap(s Session) { if dom.DDL().OwnerManager().IsOwner() { doDDLWorks(s) doDMLWorks(s) - doBootstrapSQLFile(s) + runBootstrapSQLFile = true logutil.BgLogger().Info("bootstrap successful", zap.Duration("take time", time.Since(startTime))) return @@ -638,6 +638,9 @@ var currentBootstrapVersion int64 = version93 // DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it. var internalSQLTimeout = owner.ManagerSessionTTL + 15 +// whether to run the sql file in bootstrap. +var runBootstrapSQLFile = false + var ( bootstrapVersion = []func(Session, int64){ upgradeToVer2, @@ -2020,6 +2023,7 @@ func doDDLWorks(s Session) { // It is useful for setting the initial value of GLOBAL variables. func doBootstrapSQLFile(s Session) { sqlFile := config.GetGlobalConfig().InitializeSQLFile + ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap) if sqlFile == "" { return } @@ -2033,7 +2037,7 @@ func doBootstrapSQLFile(s Session) { logutil.BgLogger().Fatal("unable to parse InitializeSQLFile", zap.Error(err)) } for _, stmt := range stmts { - rs, err := s.ExecuteStmt(context.Background(), stmt) + rs, err := s.ExecuteStmt(ctx, stmt) if err != nil { logutil.BgLogger().Warn("InitializeSQLFile error", zap.Error(err)) } diff --git a/session/session.go b/session/session.go index c8895ea3b..61a25a8bf 100644 --- a/session/session.go +++ b/session/session.go @@ -2733,7 +2733,7 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { } concurrency := int(config.GetGlobalConfig().Performance.StatsLoadConcurrency) - ses, err := createSessions(store, 7+concurrency) + ses, err := createSessions(store, 8+concurrency) if err != nil { return nil, err } @@ -2803,11 +2803,19 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { }() } + if runBootstrapSQLFile { + pm := &privileges.UserPrivileges{ + Handle: dom.PrivilegeHandle(), + } + privilege.BindPrivilegeManager(ses[6], pm) + doBootstrapSQLFile(ses[6]) + } + // A sub context for update table stats, and other contexts for concurrent stats loading. cnt := 1 + concurrency subCtxs := make([]sessionctx.Context, cnt) for i := 0; i < cnt; i++ { - subCtxs[i] = sessionctx.Context(ses[6+i]) + subCtxs[i] = sessionctx.Context(ses[7+i]) } if err = dom.LoadAndUpdateStatsLoop(subCtxs); err != nil { return nil, err