-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: keep in-memory resident for model.TableInfo with special attributes #53301
Conversation
Hi @tiancaiamao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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-sigs/prow repository. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #53301 +/- ##
=================================================
- Coverage 72.4988% 55.2061% -17.2928%
=================================================
Files 1506 1645 +139
Lines 430745 634236 +203491
=================================================
+ Hits 312285 350137 +37852
- Misses 99074 260616 +161542
- Partials 19386 23483 +4097
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/ok-to-test |
can we only store those special attributes, not the whole table-info, as we have discussed in the coference? |
The callee still need the table info. For example, you can check here tidb/pkg/ddl/ddl_tiflash_api.go Lines 274 to 294 in 3ad726d
Or do you mean just the table ID rather than *model.TableInfo? the pointer size itself is just a machine word. |
pkg/infoschema/infoschema.go
Outdated
TableInfo []*model.TableInfo | ||
} | ||
|
||
func (is *infoSchema) ListTablesWithSpecialAttribute(filter specialAttributeFilter) <-chan tableInfoResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add ctx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now. If we need a ctx, then is.SchemaTableInfos
etc all need it, and a lot other codes.
Store these infos may consume too much memory. |
If we don't store them, the we go for the Data Dictionary solution. @wjhuang2016 |
Why do you think it's needed to store them? Performance or Code complexity? |
pkg/infoschema/infoschema.go
Outdated
TableInfo []*model.TableInfo | ||
} | ||
|
||
func (is *infoSchema) ListTablesWithSpecialAttribute(filter specialAttributeFilter) <-chan tableInfoResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (is *infoSchema) ListTablesWithSpecialAttribute(filter specialAttributeFilter) <-chan tableInfoResult { | |
func (is *infoSchema) ListTablesWithSpecialAttribute(dbName string, filter specialAttributeFilter) <-chan tableInfoResult { |
can we change it to get all tables with matched attributes for a db? so we don't to have a routine to do it. it's more complex and error-prone now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the streaming API possible. For example, if we don't store the special attribute and need to fetch data from tikv, then return all data []XXX may use much more memory then this API setting. @D3Hunter
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: D3Hunter, wjhuang2016 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
/hold please fix the callsite of the ListTablesWithSpecialAttribute, you can unhold after change |
/unhold |
What problem does this PR solve?
Issue Number: ref #50959
Problem Summary:
SchemaTables()
is a big problem for infoschema v2. It's slow, it cost a lot CPU resource, it make tidb memory thrash ...What changed and how does it work?
I observe the pattern of call SchemaTables() API in our current codebase look-alike.
For ttl, tiflash and so on, they always iterate the SchemaTables and filter out some attributes.
So, what if we keep all the model.TableInfo with special attributes in-memory?
This could be a temporary solution, dirty and quick but easy to implement and verify.
In this commit, I add a new
ListTablesWithSpecialAttribute()
api to replaceSchemaTableInfos
.All the data are in memory, so it is as fast as or even faster than infoschema v1.
Check List
Tests
The same data, memory usage after vs before:
We can see some jitters even with this change, it is caused by the statistics calling in this loop:
tidb/pkg/statistics/handle/bootstrap.go
Lines 88 to 109 in b9b330a
And this commit only handle the memory in static state, when there are operations like
show xxx
orINFORMATION_SCHEMA.TABLES
visiting, there may still beSchemaTables()
calling cause memory thrash. I'll handle them later.Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.