From 13ae514b69e4953411aa962b0aa4a0e48323fb9d Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 5 Jul 2023 15:20:17 +0800 Subject: [PATCH] domain: fix a bug that reload take a long time when init domain --- domain/domain.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/domain/domain.go b/domain/domain.go index 029431e19632b..f331650ce2648 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -1197,6 +1197,7 @@ func (do *Domain) Init( if err != nil { return err } + startReloadTime := time.Now() // step 2: domain reload the infoSchema. err = do.Reload() if err != nil { @@ -1212,6 +1213,17 @@ func (do *Domain) Init( // 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 { + sub := time.Since(startReloadTime) + // The reload(in step 2) operation takes more than ddlLease and a new reload operation was not performed, + // the next query will respond by ErrInfoSchemaExpired error. So we do a new reload to update schemaValidator.latestSchemaExpire. + if sub > (ddlLease / 2) { + logutil.BgLogger().Warn("loading schema takes a long time, we do a new reload", zap.Duration("take time", sub)) + err = do.Reload() + if err != nil { + return err + } + } + // Local store needs to get the change information for every DDL state in each session. do.wg.Run(func() { do.loadSchemaInLoop(ctx, ddlLease)