Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domain: record latest schema version after syncer restarted #49929

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/domain/schema_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type schemaValidator struct {
mux sync.RWMutex
lease time.Duration
latestSchemaVer int64
restartSchemaVer int64
latestInfoSchema infoschema.InfoSchema
do *Domain
latestSchemaExpire time.Time
Expand Down Expand Up @@ -110,6 +111,12 @@ func (s *schemaValidator) Restart() {
s.mux.Lock()
defer s.mux.Unlock()
s.isStarted = true
if s.do != nil {
// When this instance reconnects PD, we should record the latest schema verion after mustReload(),
// to prevent write txns using a stale schema version by aborting them before commit.
// However, the problem still exists for read-only txns.
s.restartSchemaVer = s.do.InfoSchema().SchemaMetaVersion()
}
}

func (s *schemaValidator) Reset() {
Expand All @@ -119,6 +126,7 @@ func (s *schemaValidator) Reset() {
s.isStarted = true
s.latestSchemaVer = 0
s.deltaSchemaInfos = s.deltaSchemaInfos[:0]
s.restartSchemaVer = 0
}

func (s *schemaValidator) Update(leaseGrantTS uint64, oldVer, currVer int64, change *transaction.RelatedSchemaChange) {
Expand Down Expand Up @@ -228,6 +236,11 @@ func (s *schemaValidator) Check(txnTS uint64, schemaVer int64, relatedPhysicalTa
logutil.BgLogger().Info("the schema validator stopped before checking")
return nil, ResultUnknown
}

if schemaVer < s.restartSchemaVer {
logutil.BgLogger().Info("the schema version is too old", zap.Int64("schemaVer", schemaVer))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add please check if the tidb and pd are healthy after the transaction started

return nil, ResultFail
}
if s.lease == 0 {
return nil, ResultSucc
}
Expand Down