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

When the schema is out of date, transactions should fail quickly. #47377

Open
jackysp opened this issue Sep 29, 2023 · 3 comments
Open

When the schema is out of date, transactions should fail quickly. #47377

jackysp opened this issue Sep 29, 2023 · 3 comments
Labels
found/gs found by gs type/enhancement The issue or PR belongs to an enhancement.

Comments

@jackysp
Copy link
Member

jackysp commented Sep 29, 2023

Enhancement

If it is determined that the schema is out of date, there is no need to repeat the check schema version for each transaction.

\"[domain:8027]Information schema is out of date: schema failed to update in 1 lease, please make sure TiDB can connect to TiKV\
github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).checkSchemaValid\
\\t/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.4-0.20230918062126-32c4ef54d6ed/txnkv/transaction/2pc.go:1922\
github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).execute\
\\t/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.4-0.20230918062126-32c4ef54d6ed/txnkv/transaction/2pc.go:1586\
github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).Commit\
\\t/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.4-0.20230918062126-32c4ef54d6ed/txnkv/transaction/txn.go:502\
github.com/pingcap/tidb/store/driver/txn.(*tikvTxn).Commit\
\\t/tidb/store/driver/txn/txn_driver.go:87\
github.com/pingcap/tidb/session.(*LazyTxn).Commit\
\\t/tidb/session/txn.go:408\
github.com/pingcap/tidb/session.(*session).commitTxnWithTemporaryData\
\\t/tidb/session/session.go:856\
github.com/pingcap/tidb/session.(*session).doCommit\
\\t/tidb/session/session.go:742\
github.com/pingcap/tidb/session.(*session).doCommitWithRetry\
\\t/tidb/session/session.go:988\
github.com/pingcap/tidb/session.(*session).CommitTxn\
\\t/tidb/session/session.go:1118\
...

It will always take 5s get ErrInfoSchemaExpired error.

// CheckBySchemaVer checks if the schema version valid or not at txnTS.
func (s *SchemaChecker) CheckBySchemaVer(txnTS uint64, startSchemaVer tikv.SchemaVer) (*transaction.RelatedSchemaChange, error) {
	schemaOutOfDateRetryInterval := SchemaOutOfDateRetryInterval.Load()
	schemaOutOfDateRetryTimes := int(SchemaOutOfDateRetryTimes.Load())
	for i := 0; i < schemaOutOfDateRetryTimes; i++ {
		relatedChange, CheckResult := s.SchemaValidator.Check(txnTS, startSchemaVer.SchemaMetaVersion(), s.relatedTableIDs, s.needCheckSchema)
		switch CheckResult {
		case ResultSucc:
			return nil, nil
		case ResultFail:
			metrics.SchemaLeaseErrorCounter.WithLabelValues("changed").Inc()
			return relatedChange, ErrInfoSchemaChanged
		case ResultUnknown:
			time.Sleep(schemaOutOfDateRetryInterval)
		}
	}
	metrics.SchemaLeaseErrorCounter.WithLabelValues("outdated").Inc()
	return nil, ErrInfoSchemaExpired
}
@jackysp jackysp added the type/enhancement The issue or PR belongs to an enhancement. label Sep 29, 2023
@jackysp
Copy link
Member Author

jackysp commented Sep 29, 2023

/found gs

@ti-chi-bot ti-chi-bot bot added the found/gs found by gs label Sep 29, 2023
@jackysp
Copy link
Member Author

jackysp commented Oct 4, 2023

It is better to add some retries at

err := do.Reload()
, but not at CheckBySchemaVer.

@ngaut
Copy link
Member

ngaut commented Oct 5, 2023

Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found/gs found by gs type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants