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

parser: support create and alter placement policy #1313

Merged
merged 8 commits into from
Aug 23, 2021

Conversation

AilinKid
Copy link
Contributor

What problem does this PR solve?

support create and alter placement policy

What is changed and how it works?

add syntax for
1: create placement policy if not exists x placement_opts
2: alter placement policy if exists x placement_opts

this is based on #1299, wait for it merged first.

Check List

Tests

  • Unit test
  • Integration test

Related changes

  • Need to update the documentation

Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 18, 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.

parser.y Outdated Show resolved Hide resolved
.
Signed-off-by: ailinkid <314806019@qq.com>
{"create placement policy x learner_constraints='ww'", true, "CREATE PLACEMENT POLICY `x` LEARNER_CONSTRAINTS = 'ww'"},
{"create placement policy x primary_region='cn' regions='us' schedule='even'", true, "CREATE PLACEMENT POLICY `x` PRIMARY_REGION = 'cn' REGIONS = 'us' SCHEDULE = 'even'"},
{"create placement policy x primary_region='cn', leader_constraints='ww', leader_constraints='yy'", true, "CREATE PLACEMENT POLICY `x` PRIMARY_REGION = 'cn' LEADER_CONSTRAINTS = 'ww' LEADER_CONSTRAINTS = 'yy'"},
{"create placement policy if not exists x regions = 'us', follower_constraints='yy'", true, "CREATE PLACEMENT POLICY IF NOT EXISTS `x` REGIONS = 'us' FOLLOWER_CONSTRAINTS = 'yy'"},
Copy link
Contributor

@lcwangchao lcwangchao Aug 19, 2021

Choose a reason for hiding this comment

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

What happens if we execute "create placement policy x placement policy y"? I think it is better to make it as a syntax error instead of handling it in planner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch, done

Copy link
Contributor

Choose a reason for hiding this comment

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

PlacementOption2 is not a good name, what about DirectPlacementOption or somethine similar?

Signed-off-by: ailinkid <314806019@qq.com>
Signed-off-by: ailinkid <314806019@qq.com>
@kennytm kennytm changed the title parser: support create and alter policy parser: support create and alter placement policy Aug 19, 2021
@AilinKid
Copy link
Contributor Author

/cc @lcwangchao @xhebox

@@ -1568,6 +1586,9 @@ PlacementOption:
{
$$ = &ast.PlacementOption{Tp: ast.PlacementOptionLearnerConstraints, StrValue: $3}
}

PlacementOption:
DirectPlacementOption
| "PLACEMENT" "POLICY" EqOpt stringLit
Copy link
Contributor

@lcwangchao lcwangchao Aug 20, 2021

Choose a reason for hiding this comment

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

Is PlacementOption used now? May be below is better because a database or table can not assign a policy and set the direct placement option at the same time.

PlacementPolicyOrOptionList:
	PlacementOptionList
|       "PLACEMENT" "POLICY" EqOpt stringLit

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.

DirectPlacementOption is a basic option set for create policy usage.
PlacementOption is super set of DirectPlacementOption, plus placement policy for create table usage.

a database or table can't assign a policy and set the direct placement option at the same time, @morgo Is this true?

I think alter table t placement policy = x, follower_constraints='yy', other placement_opt is tolerant, the application will check whether these options together are compatible like old placement rules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that's true. For simplification we decided setting a placement policy unsets all placement options (and vice versa)

Copy link
Contributor Author

@AilinKid AilinKid Aug 22, 2021

Choose a reason for hiding this comment

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

After code trying. we couldn't convert PlacementPolicyOrOptionList to a single database option since databaseOptList assume it's element is every single database option, no a list here.

for example
placement policy = x character set='utf8' follower_constraints='yy'
parser will treat every token individually, every element is a database option, we couldn't divide/tell the placement_options list and placement_policy apart at the first beginning. For this case character_set is not a placement option.

We should handle this in the TiDB side, what's your option? @lcwangchao

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are right, we should at least guarantee follower=1 character set='utf8' follower_constraints='yy' can be accepted by parser.

@ti-chi-bot ti-chi-bot added status/LGT2 LGT2 and removed status/LGT1 LGT1 labels Aug 23, 2021
@xhebox
Copy link
Contributor

xhebox commented Aug 23, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 4aedcff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants