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

Reduce the kv_get requests in stale read #25303

Closed
nolouch opened this issue Jun 9, 2021 · 0 comments
Closed

Reduce the kv_get requests in stale read #25303

nolouch opened this issue Jun 9, 2021 · 0 comments

Comments

@nolouch
Copy link
Member

nolouch commented Jun 9, 2021

Background

Infoschema cache is introduced by #24285, which mainly used for stale read and history read. It let executor can get the corresponding history schema. But even if we have the cache, every request still needs to go to TiKV to obtain the schema version to confirm the corresponding schema. which leads one TiKV to have many KV_Get, This may let one TiKV who has the meta region's leader consume too much CPU and become a bottleneck. And intuitively, the request is unbalanced:
image

Implementation

The details are relative to this part:

tidb/domain/domain.go

Lines 101 to 109 in 5c95062

func (do *Domain) loadInfoSchema(startTS uint64) (infoschema.InfoSchema, bool, int64, *tikv.RelatedSchemaChange, error) {
snapshot := do.store.GetSnapshot(kv.NewVersion(startTS))
m := meta.NewSnapshotMeta(snapshot)
neededSchemaVersion, err := m.GetSchemaVersion()
if err != nil {
return nil, false, 0, nil, err
}
if is := do.infoCache.GetByVersion(neededSchemaVersion); is != nil {

Because the schema version is guaranteed to increase monotonicity in the entire cluster, it could be optimized to reduce the extra request by check the schema version is not changed between the older request and the up-to-date schema version. That's means we need to maintain each schema version's latest ts and oldest ts. if the ts hit in [oldest_ts, latest ts], then we can directly got the schema version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant