From 08541498f7ec4e9539022853cf3d85ad0293fff8 Mon Sep 17 00:00:00 2001 From: Jianjun Liao <36503113+Leavrth@users.noreply.github.com> Date: Mon, 8 May 2023 17:45:06 +0800 Subject: [PATCH] br: avoid too many warning logs after update schema version (#43416) close pingcap/tidb#43402 --- br/pkg/restore/client.go | 16 ++++++++++++++-- domain/domain.go | 11 +++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/br/pkg/restore/client.go b/br/pkg/restore/client.go index 3d9c1f63ed..b14e60c2b7 100644 --- a/br/pkg/restore/client.go +++ b/br/pkg/restore/client.go @@ -3072,8 +3072,20 @@ func (rc *Client) UpdateSchemaVersion(ctx context.Context) error { func(ctx context.Context, txn kv.Transaction) error { t := meta.NewMeta(txn) var e error - schemaVersion, e = t.GenSchemaVersions(128) - return e + // To trigger full-reload instead of diff-reload, we need to increase the schema version + // by at least `domain.LoadSchemaDiffVersionGapThreshold`. + schemaVersion, e = t.GenSchemaVersions(64 + domain.LoadSchemaDiffVersionGapThreshold) + if e != nil { + return e + } + // add the diff key so that the domain won't retry to reload the schemas with `schemaVersion` frequently. + return t.SetSchemaDiff(&model.SchemaDiff{ + Version: schemaVersion, + Type: model.ActionNone, + SchemaID: -1, + TableID: -1, + RegenerateSchemaMap: true, + }) }, ); err != nil { return errors.Trace(err) diff --git a/domain/domain.go b/domain/domain.go index 1ac73cc9bc..d2bdf875c0 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -96,6 +96,9 @@ import ( var ( mdlCheckLookDuration = 50 * time.Millisecond + + // LoadSchemaDiffVersionGapThreshold is the threshold for version gap to reload domain by loading schema diffs + LoadSchemaDiffVersionGapThreshold int64 = 100 ) func init() { @@ -230,7 +233,7 @@ func (do *Domain) loadInfoSchema(startTS uint64) (infoschema.InfoSchema, bool, i // 3. There are less 100 diffs. // 4. No regenrated schema diff. startTime := time.Now() - if currentSchemaVersion != 0 && neededSchemaVersion > currentSchemaVersion && neededSchemaVersion-currentSchemaVersion < 100 { + if currentSchemaVersion != 0 && neededSchemaVersion > currentSchemaVersion && neededSchemaVersion-currentSchemaVersion < LoadSchemaDiffVersionGapThreshold { is, relatedChanges, err := do.tryLoadSchemaDiffs(m, currentSchemaVersion, neededSchemaVersion) if err == nil { do.infoCache.Insert(is, uint64(schemaTs)) @@ -415,13 +418,13 @@ func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64 phyTblIDs := make([]int64, 0, len(diffs)) actions := make([]uint64, 0, len(diffs)) for _, diff := range diffs { + if diff.RegenerateSchemaMap { + return nil, nil, errors.Errorf("Meets a schema diff with RegenerateSchemaMap flag") + } IDs, err := builder.ApplyDiff(m, diff) if err != nil { return nil, nil, err } - if diff.RegenerateSchemaMap { - return nil, nil, errors.Errorf("Meets a schema diff with RegenerateSchemaMap flag") - } if canSkipSchemaCheckerDDL(diff.Type) { continue }