Skip to content

Commit

Permalink
Update patch from suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo committed Dec 23, 2022
1 parent db4fe52 commit bdd8f1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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))
}
Expand Down
10 changes: 8 additions & 2 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bdd8f1f

Please sign in to comment.