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

infoschema: introduce MetaOnlyInfoSchema to provide meta only information schema #52070

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Mar 25, 2024

What problem does this PR solve?

Issue Number: close #52072

Problem Summary:

The API of infoschema.InfoSchema introduces too many dependencies. The main reason is that it not only provides "meta" of tables but also returns table.Table for table mutations. It brings two problems.

The first problem is the dependency cycle. infoschema.InfoSchema is a basic lib and is required by many other packages. This may cause a dependency cycle easily.

Another problem is that, if we want to break the dependency cycle. We have to use some "magic ways". For example, return infoschema.InfoSchemaVersion instead of infoschema.InfoSchema in function signature but cast it to infoschema.InfoSchema when using it. However, the casting is.(infoschema.InfoSchema) is ugly and may lost the benefit of static checks in compile phase.

What changed and how does it work?

In this PR, we extended infoschema.InfoschemaVersion to infoschema.MetaOnlyInfoSchema to provide more common use methods in API and avoid importing the table package there. In most scenes, we only need the table meta and do not want to modify it, so infoschema.MetaOnlyInfoSchema is enough.

We also added some methods to provide table meta only:

type MetaOnlyInfoSchema interface {
	// ...
	TableInfoByName(schema, table model.CIStr) (*model.TableInfo, error)
	TableInfoByID(id int64) (*model.TableInfo, bool)
	FindTableInfoByPartitionID(partitionID int64) (*model.TableInfo, *model.DBInfo, *model.PartitionDefinition)
	SchemaTableInfos(schema model.CIStr) []*model.TableInfo
	// ...
}

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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 ti-chi-bot bot added do-not-merge/needs-linked-issue 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. labels Mar 25, 2024
Copy link

tiprow bot commented Mar 25, 2024

Hi @lcwangchao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Merging #52070 (3c23a06) into master (639fa00) will decrease coverage by 17.6641%.
Report is 11 commits behind head on master.
The diff coverage is 69.2307%.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #52070         +/-   ##
=================================================
- Coverage   72.3876%   54.7236%   -17.6641%     
=================================================
  Files          1485       1599        +114     
  Lines        365503     613536     +248033     
=================================================
+ Hits         264579     335749      +71170     
- Misses        81362     254456     +173094     
- Partials      19562      23331       +3769     
Flag Coverage Δ
integration 36.7199% <7.6923%> (?)
unit 70.4637% <67.6923%> (-1.8062%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9957% <ø> (-2.3014%) ⬇️
parser ∅ <ø> (∅)
br 50.8033% <100.0000%> (+4.4794%) ⬆️

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Mar 25, 2024
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 26, 2024
@@ -181,3 +181,9 @@ func (i InfoStoreAdaptor) TableByName(schema, table model.CIStr) (t table.Table,
}
return tables.MockTableFromMeta(tableInfo), nil
}

// TableInfoByName implements the InfoSchema interface.
// nolint:unused
Copy link
Contributor

Choose a reason for hiding this comment

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

public function will not trigger "unused" linter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, just copied from exists method like TableByName ...

Copy link
Contributor

Choose a reason for hiding this comment

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

How about trying to remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, I'll try to remove it

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 26, 2024
Copy link

ti-chi-bot bot commented Mar 26, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-03-25 11:55:49.790059055 +0000 UTC m=+1896176.812305442: ☑️ agreed by tiancaiamao.
  • 2024-03-26 02:37:42.732553158 +0000 UTC m=+1949089.754799546: ☑️ agreed by lance6716.

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

ti-chi-bot bot commented Mar 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, tangenta, tiancaiamao, windtalker

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Mar 26, 2024
@ti-chi-bot ti-chi-bot bot merged commit bd17acd into pingcap:master Mar 26, 2024
25 checks passed
@lcwangchao lcwangchao deleted the metaonlyinfoschema branch March 26, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

introduce MetaOnlyInfoSchema to provide meta only information schema
5 participants