From bdd8f1f2108900515df05325a253bfc443c776a8 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Fri, 23 Dec 2022 08:12:54 -0700 Subject: [PATCH] Update patch from suggestions --- session/bootstrap.go | 10 +++++++--- session/session.go | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 478bc2e0657b5..618b88ab7ad0b 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -527,7 +527,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 @@ -746,6 +746,9 @@ var currentBootstrapVersion int64 = version109 // 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, @@ -2315,6 +2318,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 } @@ -2323,12 +2327,12 @@ func doBootstrapSQLFile(s Session) { if err != nil { logutil.BgLogger().Fatal("unable to read InitializeSQLFile", zap.Error(err)) } - stmts, err := s.Parse(context.Background(), string(b)) + stmts, err := s.Parse(ctx, string(b)) if err != nil { 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 d358d761560e2..e58d534197582 100644 --- a/session/session.go +++ b/session/session.go @@ -3297,7 +3297,7 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { analyzeConcurrencyQuota := int(config.GetGlobalConfig().Performance.AnalyzePartitionConcurrencyQuota) concurrency := int(config.GetGlobalConfig().Performance.StatsLoadConcurrency) - ses, err := createSessions(store, 9) + ses, err := createSessions(store, 10) if err != nil { return nil, err } @@ -3397,7 +3397,13 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { // setup historical stats worker dom.SetupHistoricalStatsWorker(ses[8]) dom.StartHistoricalStatsWorker() - + if runBootstrapSQLFile { + pm := &privileges.UserPrivileges{ + Handle: dom.PrivilegeHandle(), + } + privilege.BindPrivilegeManager(ses[9], pm) + doBootstrapSQLFile(ses[9]) + } // A sub context for update table stats, and other contexts for concurrent stats loading. cnt := 1 + concurrency syncStatsCtxs, err := createSessions(store, cnt)