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

ddl: add sync bundles logic for creating and droping #28037

Merged
merged 28 commits into from
Sep 23, 2021

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Sep 14, 2021

Signed-off-by: ailinkid 314806019@qq.com

What problem does this PR solve?

Issue Number: close #26580, #28058

Create table with placement policy or direct placement options should sync PD about the rules.
Drop table with placement policy or direct placement options should clean PD about the rules.
Also add a cache map about the policy reference relationship

What is changed and how it works?

What's Changed:

Create table with placement policy or direct placement options should sync PD about the rules.
Drop table with placement policy or direct placement options should clean PD about the rules.

Check List

Tests

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

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 14, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lcwangchao
  • 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 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 Sep 14, 2021
@sre-bot
Copy link
Contributor

sre-bot commented Sep 14, 2021

Please follow PR Title Format:

  • pkg [, pkg2, pkg3]: what is changed

Or if the count of mainly changed packages are more than 3, use

  • *: what is changed

After you have format title, you can leave a comment /run-check_title to recheck it

@AilinKid AilinKid changed the title add the policy cache and sync logic ddl: add the policy cache and sync logic for create and drop policy Sep 14, 2021
@AilinKid AilinKid changed the title ddl: add the policy cache and sync logic for create and drop policy ddl: add the policy cache and sync bundles logic for create and drop policy Sep 15, 2021
@AilinKid AilinKid changed the title ddl: add the policy cache and sync bundles logic for create and drop policy ddl: add the policy dependency cache and sync bundles logic for create and drop policy Sep 15, 2021
@AilinKid AilinKid changed the title ddl: add the policy dependency cache and sync bundles logic for create and drop policy ddl: add the policy dependency cache and sync bundles logic for create and drop Sep 15, 2021
@xhebox xhebox self-requested a review September 15, 2021 05:33
@lcwangchao lcwangchao linked an issue Sep 15, 2021 that may be closed by this pull request
infoschema/infoschema.go Outdated Show resolved Hide resolved
ddl/placement_policy.go Outdated Show resolved Hide resolved
ddl/placement_policy.go Outdated Show resolved Hide resolved
domain/domain.go Outdated Show resolved Hide resolved
ddl/placement_policy.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/placement_policy.go Outdated Show resolved Hide resolved
infoschema/infoschema.go Outdated Show resolved Hide resolved
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.

My biggest concern is about policyDependencies in infoschema. Infoschema is neither persistent, nor strong consistent. It is tricky to use it broadcast events. It becomes the new all-in-one cache while it is designed to sync our old table/pt/db meta changes.

In fact, I wanted to remove all tricky bundle sync in infoschema by persisting more things on TiKV. But it is gone due to cyclic import between parser and TiDB.

Maybe storing ids in the meta info of policy is good and fast enough. Something like push another DDL job that will add affected ids into policy meta when binding a policy.

ddl/placement_policy.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/placement_policy.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
ddl/table.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-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 Sep 16, 2021
@AilinKid AilinKid force-pushed the drop-policy-apply-table branch from 6314266 to 1cace4a Compare September 17, 2021 08:48
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
.
Signed-off-by: ailinkid <314806019@qq.com>
@AilinKid AilinKid changed the title ddl: add sync bundles logic for create and drop ddl: add sync bundles logic for creating and droping Sep 22, 2021
@AilinKid AilinKid requested a review from lcwangchao September 22, 2021 03:17
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 22, 2021
ddl/placement_policy.go Show resolved Hide resolved
}
// Do the http request only when the rules is existed.
bundles := make([]*placement.Bundle, 0, len(ids))
for _, id := range ids {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The id list contains database ids. However db do not have records stored in tikv

Copy link
Contributor Author

@AilinKid AilinKid Sep 22, 2021

Choose a reason for hiding this comment

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

Nice insight, the work is also a preparation for what is coming from @zhaoxugang / @mattias who are under the db policy work

}
if bundle == nil {
// get the default bundle from DB or PD.
bundle = infoschema.GetBundle(d.infoCache.GetLatest(), []int64{schemaID})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not generating the default bundle using the schema's meta.

Copy link
Contributor Author

@AilinKid AilinKid Sep 22, 2021

Choose a reason for hiding this comment

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

yes we can, copyed from wanghe's work for simplicity.
cases is that: once schema did not set a policy, here may need a default bundle with PDBundleID (also from cache or via http to pd).

cache problem may be your concern, I will change this when all to-do things are much more clear.

@AilinKid
Copy link
Contributor Author

/run-all-tests

@AilinKid AilinKid force-pushed the drop-policy-apply-table branch from 656800f to 21bb88a Compare September 23, 2021 04:14
@lcwangchao
Copy link
Collaborator

Some logics are still need to be refactor because this implement is based on the legacy code. The refactor can be done in later pull requests.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 23, 2021
@xhebox
Copy link
Contributor

xhebox commented Sep 23, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 078fe50

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 23, 2021
@ti-chi-bot ti-chi-bot merged commit d14566c into pingcap:master Sep 23, 2021
@nolouch
Copy link
Member

nolouch commented Sep 26, 2021

Why need to add a rule to PD when creating a table?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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.

Placement policy will be lost after restarting the tidb server Support named PLACEMENT POLICY
6 participants