Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

syncer: fix the case-sensitive issue #1738

Merged
merged 45 commits into from
Jul 19, 2021
Merged

Conversation

glorv
Copy link
Collaborator

@glorv glorv commented May 31, 2021

What problem does this PR solve?

Fix the bug that case-sensitive can not take effect as expected.

What is changed and how it works?

  • Check upstream lower_case_table_names setting at bootstrap, do not allow set case-sensitive = true when lower_case_table_names = true
  • return schema/table name base on lower_case_table_names, return Name.O for 0, and Name.L for 1/2.
  • Try fix all the persistent data at syncer start if lower_case_table_names = 0

Check List

Tests

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

Code changes

  • Has persistent data change

Side effects

  • Breaking backward compatibility
  • If the cluster is upgrade for a lower version with some upstream lower_case_table_names = 0, we can't rollback to the origin version since some persistent data has been changed.

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

@lance6716 lance6716 added needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated labels Jun 1, 2021
@lance6716 lance6716 added this to the v2.0.4 milestone Jun 1, 2021
@glorv
Copy link
Collaborator Author

glorv commented Jun 2, 2021

/run-all-tests

@glorv
Copy link
Collaborator Author

glorv commented Jun 2, 2021

/build

@glorv
Copy link
Collaborator Author

glorv commented Jun 3, 2021

/run-all-tests

@glorv
Copy link
Collaborator Author

glorv commented Jun 4, 2021

/run-all-tests

@glorv
Copy link
Collaborator Author

glorv commented Jun 7, 2021

/run-all-tests

Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

will review soon

@@ -202,3 +202,26 @@ func (o *Optimist) PendingOperation() *optimism.Operation {
op := *o.pendingOp
return &op
}

// CheckPersistentData check and fix the persistent data.
Copy link
Collaborator

Choose a reason for hiding this comment

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

may address that currently this function is not used because user will meet error at early version if set unsupported case-sensitive.

@@ -840,6 +843,44 @@ func (cp *RemoteCheckPoint) Load(tctx *tcontext.Context) error {
return terror.WithScope(terror.DBErrorAdapt(rows.Err(), terror.ErrDBDriverError), terror.ScopeDownstream)
}

// CheckAndUpdate check the checkpoint data consistency and try to fix them if possible.
func (cp *RemoteCheckPoint) CheckAndUpdate(ctx context.Context, schemas map[string]string, tables map[string]map[string]string) error {
cp.Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe no lock is needed (but it's OK to acquire a lock)

Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

rest lgtm

syncer/syncer.go Show resolved Hide resolved
tests/others_integration.txt Outdated Show resolved Hide resolved
tests/case-sensitive/run.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@lichunzhu lichunzhu left a comment

Choose a reason for hiding this comment

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

Will review later

if lcSetting == utils.LCTableNamesMixed {
msg := "can not set `case-sensitive = true` when upstream `lower_case_table_names = 2`"
log.L().Error(msg, zap.Any("instance", cfg))
return nil, errors.New(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this make a chaos test fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure 🤔

@@ -344,3 +344,47 @@ func (oldInfo *OldInfo) toInfo() Info {
TableInfosAfter: []*model.TableInfo{oldInfo.TableInfoAfter},
}
}

// CheckDDLInfos try to check and fix all the schema and table names for DDL info.
func CheckDDLInfos(cli *clientv3.Client, source string, schemaMap map[string]string, talesMap map[string]map[string]string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func CheckDDLInfos(cli *clientv3.Client, source string, schemaMap map[string]string, talesMap map[string]map[string]string) error {
func CheckDDLInfos(cli *clientv3.Client, source string, schemaMap map[string]string, tablesMap map[string]map[string]string) error {

// GenTableID generates table ID.
func GenTableID(schema, table string) (id string, isSchemaOnly bool) {
if len(table) == 0 {
return fmt.Sprintf("`%s`", schema), true
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this have a better performance?

Suggested change
return fmt.Sprintf("`%s`", schema), true
return "`" + schema + "`", true

if len(table) == 0 {
return fmt.Sprintf("`%s`", schema), true
}
return fmt.Sprintf("`%s`.`%s`", schema, table), false
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Comment on lines 875 to 878
tctx := &tcontext.Context{
Logger: log.L(),
Ctx: ctx,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tctx := &tcontext.Context{
Logger: log.L(),
Ctx: ctx,
}
tctx := tcontext.NewContext(ctx, log.L())

@ti-chi-bot ti-chi-bot added the status/LGT1 One reviewer already commented LGTM label Jul 19, 2021
@@ -65,6 +65,8 @@ type OnlinePlugin interface {
Clear(tctx *tcontext.Context) error
// Close closes online ddl plugin
Close()
// CheckAndUpdate try to check and fix the shcema/table case-sensitive issue
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// CheckAndUpdate try to check and fix the shcema/table case-sensitive issue
// CheckAndUpdate try to check and fix the schema/table case-sensitive issue

@glorv
Copy link
Collaborator Author

glorv commented Jul 19, 2021

/run-all-tests

Copy link
Contributor

@lichunzhu lichunzhu left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lance6716
  • lichunzhu

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 status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Jul 19, 2021
@glorv
Copy link
Collaborator Author

glorv commented Jul 19, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 0a09c5b

@glorv
Copy link
Collaborator Author

glorv commented Jul 19, 2021

/run-all-tests

@ti-chi-bot ti-chi-bot merged commit a5a219c into pingcap:master Jul 19, 2021
@glorv glorv deleted the case-sensitive branch July 19, 2021 10:09
ti-chi-bot pushed a commit to ti-chi-bot/dm that referenced this pull request Jul 19, 2021
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #1886.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated size/XXL status/can-merge status/LGT2 Two reviewers already commented LGTM, ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants