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

meta: support storing placement policy into meta #27251

Merged
merged 36 commits into from
Aug 23, 2021

Conversation

AilinKid
Copy link
Contributor

Signed-off-by: ailinkid [email protected]

What problem does this PR solve?

Issue Number: close #27250

Support store the placement policy into meta

What is changed and how it works?

What's Changed:
support storing placement policy into meta. It's has a global scope and is at the same level like schema(database) but it doesn't share the namespace and idspace with any other elements.

Check List

Tests

  • Unit test
  • Integration test

Release note

meta: support storing placement policy into meta

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 16, 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 Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 16, 2021
@github-actions github-actions bot added the sig/sql-infra SIG: SQL Infra label Aug 16, 2021
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.

Overall LGTM

ddl/placement/policy.go Outdated Show resolved Hide resolved
meta/meta.go Outdated
@@ -144,6 +153,21 @@ func (m *Meta) GetGlobalID() (int64, error) {
return m.txn.GetInt64(mNextGlobalIDKey)
}

func (m *Meta) GenPolicyID() (int64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe generate the id when creating the new policy? a.k.a auto incremental id.

Copy link
Contributor Author

@AilinKid AilinKid Aug 17, 2021

Choose a reason for hiding this comment

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

It is

Copy link
Contributor

Choose a reason for hiding this comment

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

@AilinKid Actually, I mean "remove this API". GenPolicyID is used outside CreatePolicy, the behavior is not controlled by meta. One could just generate a random number other than numbers from GenPolicyID. Is there any advantage with a standalone ID generating method? Otherwise I prefer less/simple/opinionated API.

Not a necessary change request. rest code LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

meta/meta.go Show resolved Hide resolved
infoschema/infoschema.go Outdated Show resolved Hide resolved
meta/meta.go Show resolved Hide resolved
meta/meta.go Outdated Show resolved Hide resolved
@AilinKid AilinKid force-pushed the support-store-policy-in-meta branch from 9197a87 to 3896af7 Compare August 18, 2021 06:11
@AilinKid
Copy link
Contributor Author

/build

Signed-off-by: ailinkid <[email protected]>
meta/meta.go Show resolved Hide resolved
meta/meta.go Show resolved Hide resolved
@AilinKid
Copy link
Contributor Author

/run-check_dev_2

meta/meta.go Outdated Show resolved Hide resolved

func detachMagicByte(value []byte) ([]byte, error) {
magic, data := value[:1], value[1:]
switch whichMagicType(magic[0]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain how should we use the magic byte in the future? Does it means if the byte <= 0x3F they must be compatible each other? For example 0x3F can read the data with byte 0x0 and 0x0 can read the data with byte 0x3F too. If we want to make an incompatible version, the byte must be upgraded to > 0x3F? And it can still be in json format, but ... incompatible.

Copy link
Contributor Author

@AilinKid AilinKid Aug 21, 2021

Choose a reason for hiding this comment

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

This point comes from wanghe. (like magic byte in Java class file)

Appending fields is naturally compatible with old version, so we don't have to change magic byte. For extreme case, modifying a old field will cause misunderstanding between versions, in which we should change the magic byte + 0x01, that told new / old version to handling in a new way / just throw a error, but it should be still in the json handler-range.

In other extreme case, one day we may use msgpack/yaml/other-serialization-format instead, where we should change the magic byte to other reserved corresponding range.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, but for the code:

	case typeJSON:
		return data, nil

It does not make any error only if the magic number < 0x3F. Does it mean new versions must be compatible with old version if their magic numbers are in the same range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, nice catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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.

One last thing, I think PolicyInfo will better in meta as meta/placement or meta/placementpolicy. But the PR LGTM now.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 23, 2021
@AilinKid
Copy link
Contributor Author

One last thing, I think PolicyInfo will better in meta as meta/placement or meta/placementpolicy. But the PR LGTM now.

Eventually, I will put it into the parser, now there is import circle here, that's also why I put it in the util package

@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 Aug 23, 2021
@AilinKid
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: d318359

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 23, 2021
@AilinKid
Copy link
Contributor Author

/run-unit-test

@ti-chi-bot ti-chi-bot merged commit de22c5a into pingcap:master Aug 23, 2021
@AilinKid AilinKid mentioned this pull request Aug 25, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/sql-infra SIG: SQL Infra 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.

5 participants