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

checker(dm): change checker to more smart and gentle #3812

Merged
merged 25 commits into from
Feb 21, 2022

Conversation

okJiang
Copy link
Member

@okJiang okJiang commented Dec 9, 2021

What problem does this PR solve?

Issue Number: close #3766

What is changed and how it works?

  1. 2. If task is full/all mode, the following items will be forced to check (correspondingly, it will not be check in increment mode):
    - dump_privilege
    - schema_of_shard_tables(only for sharding mode)
    3. If task is increment/all mode, the following items will be forced to check (correspondingly, it will not be check in full mode):
    - replication_privilege
    - server_id
    - binlog_enable
    - binlog_format
    - binlog_row_image
    - online_ddl(new added)
    - binlog_do_db(new added)
    4. The following items will always be forced to check:
    - version
    - table_schema
    - auto_increment_ID(only for sharding mode)

  2. add binlog_do_db checker

Check List

Tests

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

test case-sensitive

  1. start MySQL with
[mysqld]
...
binlog_do_db = Upper_DB
binlog_do_db = Upper_DB1
lower_case_table_names = 1
mysql> show master status;
+------------------+----------+--------------------+------------------+-------------------------------------------+
| File             | Position | Binlog_Do_DB       | Binlog_Ignore_DB | Executed_Gtid_Set                         |
+------------------+----------+--------------------+------------------+-------------------------------------------+
| mysql-bin.000006 |     3249 | Upper_DB,Upper_DB1 |                  | a0ec2f1a-d811-11eb-84a7-16210329b3ba:1-52 |
+------------------+----------+--------------------+------------------+-------------------------------------------+
  1. create table in upstream
create database `Upper_DB`;
create database `Upper_DB1`;
mysql> show databases;
+-------------------------+
| Database                |
+-------------------------+
| upper_db                |
| upper_db1               |
+-------------------------+
  1. start dm-master/dm-worker and create source
  2. check task with
case-sensitive: false

mysql-instances:
  - source-id: "mysql-replica-01"
    black-white-list:  "instance" # compatible with deprecated config
    mydumper-config-name: "global"
    loader-config-name: "global"
    syncer-config-name: "global"
    route-rules: ["global"]
    filter-rules: ["global"]

black-white-list: # compatible with deprecated config
  instance:
    do-dbs: ["Upper_DB*", "lower_db"]
    do-tables:
      - db-name: "Upper_DB*"
        tbl-name: "Do_Table*"
      - db-name: "Upper_DB"
        tbl-name: "lower_table*"
      - db-name: "lower_db"
        tbl-name: "Upper_Table*"

routes:
  global:
    schema-pattern: "Upper_DB"
    table-pattern: "Do_Table"
    target-schema: "UPPER_DB_ROUTE"
    target-table: "do_table_route"
  1. check pass

test check failed(not in binlog_do_db)

  1. If remove Upper_DB1 from binlog_do_db
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                         |
+------------------+----------+--------------+------------------+-------------------------------------------+
| mysql-bin.000007 |      194 | Upper_DB     |                  | a0ec2f1a-d811-11eb-84a7-16210329b3ba:1-52 |
+------------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec)
  1. check failed.
» check-task /home/xianjie/ticdc/dm/tests/case_sensitive/conf/dm-task.yaml
{
    "result": false,
    "msg": "[code=26005:class=dm-master:scope=internal:level=medium], Message: fail to check synchronization configuration with type: check was failed, please see detail
        detail: {
                "results": [
                        {
                                "id": 7,
                                "name": "binlog_do_db/binlog_ignore_db check",
                                "desc": "check whether dbs need replication is in binlog_do_db/binlog_ignore_db",
                                "state": "fail",
                                "extra": "these dbs [upper_db1] are not in binlog_do_db[upper_db]"
                        }
                ],
                "summary": {
                        "passed": false,
                        "total": 9,
                        "successful": 8,
                        "failed": 1,
                        "warning": 0
                }
        }"
}

Related changes

  • Need to update the documentation

Release note

Please add a release note.
If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 9, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Ehco1996
  • lance6716

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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 9, 2021
@okJiang
Copy link
Member Author

okJiang commented Dec 13, 2021

/run-verify
/run-dm-integration-test

@okJiang
Copy link
Member Author

okJiang commented Dec 14, 2021

/run-dm-integration-test
/run-verify

1 similar comment
@okJiang
Copy link
Member Author

okJiang commented Dec 14, 2021

/run-dm-integration-test
/run-verify

@okJiang
Copy link
Member Author

okJiang commented Dec 14, 2021

Due to sequence_sharding IT need ignore sharding table check, so the ci failed. Mainly because the task stop then start.

now upstream schema is conflict, ignore it and restart task

Wait the better sharding table check pr merge(not yet open).

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2021
@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/needs-triage-completed and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 14, 2022
@okJiang
Copy link
Member Author

okJiang commented Feb 14, 2022

/run-dm-integration-test

@ti-chi-bot
Copy link
Member

@okJiang: PR needs rebase.

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.

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 14, 2022
@okJiang okJiang marked this pull request as ready for review February 14, 2022 14:44
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 14, 2022
@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 16, 2022
@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2022

Codecov Report

Merging #3812 (122b0b7) into master (9607554) will increase coverage by 0.0672%.
The diff coverage is 57.3113%.

Flag Coverage Δ
cdc 60.2329% <54.0983%> (+0.3107%) ⬆️
dm 51.8990% <58.8491%> (-0.1299%) ⬇️

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

@@               Coverage Diff                @@
##             master      #3812        +/-   ##
================================================
+ Coverage   55.6402%   55.7074%   +0.0672%     
================================================
  Files           494        507        +13     
  Lines         61283      63128      +1845     
================================================
+ Hits          34098      35167      +1069     
- Misses        23750      24469       +719     
- Partials       3435       3492        +57     

dm/dm/config/checking_item.go Outdated Show resolved Hide resolved
dm/pkg/utils/db.go Show resolved Hide resolved
dm/pkg/utils/db.go Outdated Show resolved Hide resolved
dm/pkg/checker/binlog.go Outdated Show resolved Hide resolved
dm/pkg/utils/db.go Outdated Show resolved Hide resolved
}

// NewBinlogDBChecker returns a RealChecker.
func NewBinlogDBChecker(db *sql.DB, dbinfo *dbutil.DBConfig, schemas map[string]struct{}) RealChecker {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need an it test for this checker?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is inconvenient to add it, because should set it in my.cnf.

Maybe manual test is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

manual test is updated in description.

// If both of them are empty, it will log changes for all DBs.
if len(binlogDoDB) != 0 {
for _, doDB := range binlogDoDBs {
delete(c.schemas, doDB)
Copy link
Contributor

Choose a reason for hiding this comment

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

where c.chemas init?

Copy link
Contributor

Choose a reason for hiding this comment

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

we also need to think about case-sensitive of this schemas

Copy link
Member Author

Choose a reason for hiding this comment

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

where c.chemas init?

checkSchemas := make(map[string]struct{}, len(mapping))

we also need to think about case-sensitive of this schemas

To be further confirmed. Because I think if schema name is case-sensitive, the binlog_do_db/binlog_ignore_db are too.

Copy link
Member Author

@okJiang okJiang Feb 18, 2022

Choose a reason for hiding this comment

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

After test, binlog_db_db/binlog_ignore_db is not affected by lower_case_table_names.

[mysqld]
binlog_do_db = Do
binlog_do_db = TestCaseSensitive
lower_case_table_names = 1

mysql> show master status;
+------------------+----------+----------------------+------------------+--------------------------------------------+
| File             | Position | Binlog_Do_DB         | Binlog_Ignore_DB | Executed_Gtid_Set                          |
+------------------+----------+----------------------+------------------+--------------------------------------------+
| mysql-bin.000004 |      194 | Do,TestCaseSensitive |                  | a0ec2f1a-d811-11eb-84a7-16210329b3ba:1-112 |
+------------------+----------+----------------------+------------------+--------------------------------------------+
1 row in set (0.00 sec)

I will add code about case-sensitive.

@okJiang
Copy link
Member Author

okJiang commented Feb 18, 2022

/run-dm-integration-test

@okJiang
Copy link
Member Author

okJiang commented Feb 18, 2022

/run-dm-integration-test

@lance6716
Copy link
Contributor

/check-issue-triage-complete

Copy link
Contributor

@Ehco1996 Ehco1996 left a comment

Choose a reason for hiding this comment

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

LGTM great job

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 21, 2022
@@ -259,7 +264,7 @@ func (c *Checker) Init(ctx context.Context) (err error) {
continue
}
if instance.cfg.ShardMode == config.ShardPessimistic {
c.checkList = append(c.checkList, checker.NewShardingTablesChecker(targetTableID, dbs, shardingSet, columnMapping, checkingShardID, dumpThreads))
c.checkList = append(c.checkList, checker.NewShardingTablesChecker(targetTableID, dbs, shardingSet, checkingShardID, dumpThreads))
} else {
c.checkList = append(c.checkList, checker.NewOptimisticShardingTablesChecker(targetTableID, dbs, shardingSet, dumpThreads))
Copy link
Contributor

Choose a reason for hiding this comment

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

we should also check AutoID for optimistic sharding mode. Will the optimistic table structure join itself can report the AutoID problem so we don't need extra checking logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, optimistic table structure join can report the autoID problem.

I will add some UT later

@@ -575,7 +575,7 @@ func (s *Server) StartTask(ctx context.Context, req *pb.StartTaskRequest) (*pb.S

resp.Result = true
if cfg.RemoveMeta {
resp.Msg += "`remove-meta` in task config is deprecated, please use `start-task ... --remove-meta` instead"
resp.Msg = "`remove-meta` in task config is deprecated, please use `start-task ... --remove-meta` instead"
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment that what message will be overwritten

Copy link
Member Author

Choose a reason for hiding this comment

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

no message will be overwritten. The resp.Msg is just assigned once. Because this pr

	msg, err := checker.CheckSyncConfigFunc(ctx, stCfgs, ctlcommon.DefaultErrorCnt, ctlcommon.DefaultWarnCnt)
	if err != nil {
		resp.CheckResult = terror.WithClass(err, terror.ClassDMMaster).Error()
		return resp, nil
	}
	resp.CheckResult = msg

resp.Msg is changed to resp.CheckResult.

So I just remove + from here.

binlogDoDB = strings.ToLower(binlogDoDB)
binlogIgnoreDB = strings.ToLower(binlogIgnoreDB)
}
binlogDoDB = strings.ReplaceAll(binlogDoDB, " ", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

identifier can have spaces as long as they are backquoted, so this is incorrect

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, there is no spaces among the list of binlog_do_db. So, I just remove this later.

But another question, it seems that identifier also can have ,(comma)?

}
if len(c.schemas) > 0 {
dbs := []string{}
for db := range c.schemas {
Copy link
Contributor

Choose a reason for hiding this comment

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

we have a helper function SetToSlice

dm/pkg/checker/binlog.go Show resolved Hide resolved
@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 Feb 21, 2022
@lance6716
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: f763630

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 21, 2022
@ti-chi-bot ti-chi-bot merged commit 7f90eb5 into pingcap:master Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dm Issues or PRs related to DM. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ 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. status/ptal Could you please take a look?
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pre-Checker: Restrict user usage
5 participants