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

schema cache: record the ddl timestamp and associate schema cache with the timestamp for stale read #42083

Merged
merged 22 commits into from
Mar 31, 2023

Conversation

hihihuhu
Copy link
Contributor

@hihihuhu hihihuhu commented Mar 9, 2023

What problem does this PR solve?

Issue Number: close #40740

Problem Summary:

What is changed and how it works?

when handle ddl, record the start ts of the transaction as the timestamp of the schema change. then when populate the schema cache, associate each schema version with a timestamp, and search the schema by timestamp for stale read.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 9, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • tiancaiamao
  • xhebox

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/invalid-title release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Mar 9, 2023
@ti-chi-bot
Copy link
Member

Hi @hihihuhu. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@hihihuhu
Copy link
Contributor Author

@xhebox could you help to take a look when you have a chance? thanks!

Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

Maybe we should rename loadschema(startTS uint64) to loadschema(timestamp uint64). This function will accept a timestamp that starts with the desired schema and schemadiff/metadata. It does not mean that startTS is the timestamp set by updateSchemaVersion.

ddl/ddl.go Outdated Show resolved Hide resolved
domain/domain.go Outdated Show resolved Hide resolved
infoschema/cache.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 17, 2023
domain/domain.go Outdated Show resolved Hide resolved
meta/meta.go Outdated Show resolved Hide resolved
domain/domain.go Outdated Show resolved Hide resolved
@hihihuhu hihihuhu force-pushed the master branch 2 times, most recently from b16e8f5 to 8219173 Compare March 21, 2023 19:47
@hihihuhu hihihuhu changed the title [DDL] record the ddl timestamp and associate schema cache with the timestamp for stale read schema cache: record the ddl timestamp and associate schema cache with the timestamp for stale read Mar 21, 2023
@hihihuhu
Copy link
Contributor Author

thanks! i updated to store startTs in schemadiff and use it as the timestamp of a schema version, i haven't tested it yet but want to get your opinion first to see if this is what you expect?

meta/meta.go Outdated Show resolved Hide resolved
@hawkingrei
Copy link
Member

/ok-to-test

@hawkingrei
Copy link
Member

/test all

@hawkingrei
Copy link
Member

/merge

domain/domain.go Outdated Show resolved Hide resolved
@hawkingrei
Copy link
Member

@hihihuhu Please fix it.

owner/manager_test.go:58:63: too many arguments in call to ic.Insert

	have (infoschema.InfoSchema, number, number)

	want (infoschema.InfoSchema, uint64)

owner/manager_test.go:118:63: too many arguments in call to ic.Insert

	have (infoschema.InfoSchema, number, number)

	want (infoschema.InfoSchema, uint64)

owner/manager_test.go:134:64: too many arguments in call to ic2.Insert

	have (infoschema.InfoSchema, number, number)

	want (infoschema.InfoSchema, uint64)

owner/manager_test.go:159:64: too many arguments in call to ic3.Insert

	have (infoschema.InfoSchema, number, number)

	want (infoschema.InfoSchema, uint64)

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 30, 2023
@hihihuhu
Copy link
Contributor Author

/retest

@xhebox
Copy link
Contributor

xhebox commented Mar 31, 2023

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: dab3f0b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 31, 2023
@ti-chi-bot ti-chi-bot merged commit 73d446e into pingcap:master Mar 31, 2023
@hihihuhu
Copy link
Contributor Author

@xhebox consider this is a fix of performance issue, is it possible to merge this into release-6.5? thanks!

@xhebox
Copy link
Contributor

xhebox commented Jul 25, 2023

@xhebox consider this is a fix of performance issue, is it possible to merge this into release-6.5? thanks!

I think 'no'. We only pick fixes of bugs.

hihihuhu added a commit to hihihuhu/tidb that referenced this pull request Jul 26, 2023
* cache schema version by timestamp

* fix test

* avoid recursive locking

* address comment

* optimize the code

* fix 40740

* use the commit ts of the shcema diff as the timestamp of the schema

* address comment

* address comment

* address comment

* fix CI

Signed-off-by: xhe <xw897002528@gmail.com>

* fix CI

Signed-off-by: xhe <xw897002528@gmail.com>

* Update meta/meta.go

* Update domain/domain.go

* fix test

---------

Signed-off-by: xhe <xw897002528@gmail.com>
Co-authored-by: xhe <xw897002528@gmail.com>
Co-authored-by: CbcWestwolf <1004626265@qq.com>
hihihuhu added a commit to hihihuhu/tidb that referenced this pull request Jul 27, 2023
hihihuhu added a commit to hihihuhu/tidb that referenced this pull request Jul 27, 2023
hihihuhu added a commit to hihihuhu/tidb that referenced this pull request Aug 28, 2023
* cache schema version by timestamp

* fix test

* avoid recursive locking

* address comment

* optimize the code

* fix 40740

* use the commit ts of the shcema diff as the timestamp of the schema

* address comment

* address comment

* address comment

* fix CI

Signed-off-by: xhe <xw897002528@gmail.com>

* fix CI

Signed-off-by: xhe <xw897002528@gmail.com>

* Update meta/meta.go

* Update domain/domain.go

* fix test

---------

Signed-off-by: xhe <xw897002528@gmail.com>
Co-authored-by: xhe <xw897002528@gmail.com>
Co-authored-by: CbcWestwolf <1004626265@qq.com>

fix wrong timestamp in schema cache

address comment

format
crazycs520 pushed a commit to crazycs520/tidb that referenced this pull request Sep 1, 2023
ti-chi-bot bot pushed a commit that referenced this pull request Sep 1, 2023
guoshouyan pushed a commit to guoshouyan/tidb that referenced this pull request Mar 5, 2024
* cache schema version by timestamp

* fix test

* avoid recursive locking

* address comment

* optimize the code

* fix 40740

* use the commit ts of the shcema diff as the timestamp of the schema

* address comment

* address comment

* address comment

* fix CI

Signed-off-by: xhe <xw897002528@gmail.com>

* fix CI

Signed-off-by: xhe <xw897002528@gmail.com>

* Update meta/meta.go

* Update domain/domain.go

* fix test

---------

Signed-off-by: xhe <xw897002528@gmail.com>
Co-authored-by: xhe <xw897002528@gmail.com>
Co-authored-by: CbcWestwolf <1004626265@qq.com>

fix wrong timestamp in schema cache

address comment

format

Co-authored-by: Chen Ding <dingc05@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

avoid excessive PointGet request to a single tikv node for stale read when DDL happens
7 participants