Skip to content

test: add a integration test for foreign-key-check#1385

Merged
ti-chi-bot[bot] merged 5 commits intopingcap:masterfrom
hongyunyan:0529-2
Jun 4, 2025
Merged

test: add a integration test for foreign-key-check#1385
ti-chi-bot[bot] merged 5 commits intopingcap:masterfrom
hongyunyan:0529-2

Conversation

@hongyunyan
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #xxx

What is changed and how it works?

Check List

Tests

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

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

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

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @hongyunyan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello! Gemini or gemini-code-assist here, providing a summary of this pull request.

This pull request introduces a new integration test focused on verifying TiCDC's behavior when replicating data that violates foreign key constraints. The test simulates a scenario where tables with a foreign key relationship are created, foreign key checks are disabled on the upstream database, and then data that violates the foreign key constraint is inserted. The changefeed replicates this data downstream, and the test uses the sync-diff tool to confirm that the final data state downstream is consistent with the upstream, ensuring CDC can handle such scenarios correctly.

Highlights

  • New Integration Test: Adds a dedicated integration test suite under tests/integration_tests/foreign_key_check to specifically test foreign key replication scenarios.
  • Foreign Key Violation Scenario: The test creates tables with a foreign key constraint (departments and employees), disables foreign key checks on the upstream TiDB instance, and inserts data into the employees table with a dept_id that does not exist in the departments table, thus violating the FK.
  • Data Consistency Verification: Utilizes the sync-diff tool with a specific configuration (diff_config.toml) to compare the data between the upstream and downstream databases after replication, ensuring consistency despite the FK violation upstream.
  • CI Integration: Includes the newly added foreign_key_check test in the list of light integration tests (run_light_it_in_ci.sh) to be executed automatically in the CI pipeline.

Changelog

Click here to see the changelog
  • tests/integration_tests/foreign_key_check/conf/diff_config.toml
    • New file added.
    • Contains configuration for the sync-diff tool, specifying source and target instances, output directory, and tables to check (test.*).
  • tests/integration_tests/foreign_key_check/data/pre.sql
    • New file added.
    • SQL script to set up the test schema and data.
    • Creates departments and employees tables with a foreign key constraint on employees.dept_id referencing departments.dept_id.
    • Inserts data, including a row in employees with a dept_id (999) that violates the foreign key constraint.
  • tests/integration_tests/foreign_key_check/run.sh
    • New file added.
    • Main test script to orchestrate the integration test.
    • Sets up a TiDB cluster.
    • Disables global foreign_key_checks on the upstream database.
    • Starts the CDC server and creates a changefeed.
    • Executes the pre.sql script on the upstream.
    • Runs check_sync_diff using the provided config to verify data consistency.
    • Includes comments explaining the test's purpose: verifying synchronization of FK-violating statements when upstream FK checks are disabled.
  • tests/integration_tests/run_light_it_in_ci.sh
    • Modified to add the foreign_key_check test to the mysql_groups array (specifically group G15) for inclusion in light integration tests run in CI.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Test added, checks FK,
Data flows the CDC way,
Consistency wins the day.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new integration test for foreign-key-check functionality. The test aims to verify that TiCDC can successfully replicate data that violates foreign key constraints when upstream has FK checks disabled, to a downstream MySQL sink that (presumably) has FK detection enabled. The setup involves disabling FK checks on the upstream, inserting data that violates FKs, and then using sync_diff_inspector to ensure the data is replicated correctly.

The overall structure of the test, including the shell script, SQL setup, and diff configuration, appears sound for its purpose. The addition of the test to the CI run is also appropriate.

I have one suggestion for improving the maintainability of the test script.

Summary of Findings

  • Unused variables in test script: The run.sh script defines CDC_COUNT and DB_COUNT which are not subsequently used. This was commented on with medium severity.
  • Non-English comment in SQL script: The pre.sql file contains a comment in Chinese (-- 外键约束). While functional, using English for comments is generally preferred in projects with international contributors for better universal understanding. This was not commented on directly due to its low severity.
  • Missing newline at end of SQL file: The pre.sql file is missing a newline character at the end. This is a minor stylistic issue. This was not commented on directly due to its low severity.
  • Hardcoded temporary path in config: The diff_config.toml uses a hardcoded path in /tmp for output-dir. This is common and generally acceptable for test configurations. This was not commented on directly due to its low severity in a test context.
  • Naming in diff_config.toml: In diff_config.toml, the source TiDB (port 4000) is named mysql1 and the target MySQL (port 3306) is named tidb0. This naming could be slightly counter-intuitive. This is a minor clarity point and was not commented on directly due to its low severity.

Merge Readiness

The pull request is generally in good shape and adds a valuable integration test. There is one medium-severity issue regarding unused variables in the run.sh script that should be addressed to improve code maintainability. Once that is resolved, the PR should be ready for merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval from authorized maintainers.

Comment on lines +17 to +18
CDC_COUNT=3
DB_COUNT=4

Choose a reason for hiding this comment

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

medium

These variables CDC_COUNT and DB_COUNT are defined but don't seem to be used anywhere in this script. Could they be removed to improve clarity and reduce clutter?

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 29, 2025

@gemini-code-assist[bot]: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Code Review

This pull request introduces a new integration test for foreign-key-check functionality. The test aims to verify that TiCDC can successfully replicate data that violates foreign key constraints when upstream has FK checks disabled, to a downstream MySQL sink that (presumably) has FK detection enabled. The setup involves disabling FK checks on the upstream, inserting data that violates FKs, and then using sync_diff_inspector to ensure the data is replicated correctly.

The overall structure of the test, including the shell script, SQL setup, and diff configuration, appears sound for its purpose. The addition of the test to the CI run is also appropriate.

I have one suggestion for improving the maintainability of the test script.

Summary of Findings

  • Unused variables in test script: The run.sh script defines CDC_COUNT and DB_COUNT which are not subsequently used. This was commented on with medium severity.
  • Non-English comment in SQL script: The pre.sql file contains a comment in Chinese (-- 外键约束). While functional, using English for comments is generally preferred in projects with international contributors for better universal understanding. This was not commented on directly due to its low severity.
  • Missing newline at end of SQL file: The pre.sql file is missing a newline character at the end. This is a minor stylistic issue. This was not commented on directly due to its low severity.
  • Hardcoded temporary path in config: The diff_config.toml uses a hardcoded path in /tmp for output-dir. This is common and generally acceptable for test configurations. This was not commented on directly due to its low severity in a test context.
  • Naming in diff_config.toml: In diff_config.toml, the source TiDB (port 4000) is named mysql1 and the target MySQL (port 3306) is named tidb0. This naming could be slightly counter-intuitive. This is a minor clarity point and was not commented on directly due to its low severity.

Merge Readiness

The pull request is generally in good shape and adds a valuable integration test. There is one medium-severity issue regarding unused variables in the run.sh script that should be addressed to improve code maintainability. Once that is resolved, the PR should be ready for merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval from authorized maintainers.

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2025
@ti-chi-bot ti-chi-bot bot added the lgtm label May 29, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented May 29, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: asddongmen

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 29, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-05-29 08:48:07.558780338 +0000 UTC m=+95108.620797958: ☑️ agreed by asddongmen.

@ti-chi-bot ti-chi-bot bot added the approved label May 29, 2025
@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

2 similar comments
@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

1 similar comment
@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 3, 2025

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-linked-issue label, please provide the linked issue number on one line in the PR body, for example: Issue Number: close #123 or Issue Number: ref #456.

📖 For more info, you can check the "Contribute Code" section in the development guide.

@hongyunyan
Copy link
Collaborator Author

/retest

@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 4, 2025

@hongyunyan: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cdc-pulsar-integration-light 9e58a58 link false /test pull-cdc-pulsar-integration-light

Full PR test history. Your PR dashboard.

Details

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-sigs/prow repository. I understand the commands that are listed here.

@hongyunyan
Copy link
Collaborator Author

/test pull-cdc-mysql-integration-heavy

@ti-chi-bot ti-chi-bot bot merged commit eb311db into pingcap:master Jun 4, 2025
14 of 15 checks passed
@hongyunyan hongyunyan deleted the 0529-2 branch December 12, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants