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

ddl: fix foreign key and check constraint verify records under async commit #48524

Closed

Conversation

jiyfhust
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #48297

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Code review instead of tests.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added the release-note-none Denotes a PR that doesn't merit a release note. label Nov 11, 2023
Copy link

ti-chi-bot bot commented Nov 11, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign benjamin2037 for approval. For more information see the Kubernetes Code Review Process.

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

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 ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 11, 2023
@jiyfhust
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Nov 11, 2023
Copy link

tiprow bot commented Nov 11, 2023

Hi @jiyfhust. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

Copy link

codecov bot commented Nov 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.5818%. Comparing base (44f9430) to head (8dd0362).
Report is 2645 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #48524        +/-   ##
================================================
+ Coverage   71.3984%   80.5818%   +9.1833%     
================================================
  Files          1403       2676      +1273     
  Lines        406971     766530    +359559     
================================================
+ Hits         290571     617684    +327113     
- Misses        96445     124837     +28392     
- Partials      19955      24009      +4054     
Flag Coverage Δ
integration 53.9315% <78.5714%> (?)
unit 79.4941% <100.0000%> (+8.0956%) ⬆️

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

Components Coverage Δ
dumpling 73.6130% <ø> (+19.6255%) ⬆️
parser ∅ <ø> (∅)
br 70.9575% <ø> (+17.8663%) ⬆️

@jiyfhust
Copy link
Contributor Author

/retest

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Nov 15, 2023

/cc @CbcWestwolf @mjonss @Benjamin2037
Hi,brothers, this pr is easy to review, PTAL.

Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

Is it possible to add a test case showing the effect of this PR?

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Nov 30, 2023

Is it possible to add a test case showing the effect of this PR?

I do not have good idea to reproduce the steps to show the effects. But as async commit logic, we should wait before all txns use the old schema to finish then we can verify records, just as you known that exchange partition handle it the same way.

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Dec 5, 2023

em... Who could help for this pr?

1 similar comment
@jiyfhust
Copy link
Contributor Author

jiyfhust commented Dec 5, 2023

em... Who could help for this pr?

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Dec 5, 2023

For example, modify column null to not null, also use delayAsyncCommit.

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Dec 5, 2023

/cc @tangenta @zimulala PTAL

Copy link

ti-chi-bot bot commented Dec 5, 2023

@jiyfhust: GitHub didn't allow me to request PR reviews from the following users: PTAL.

Note that only pingcap members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @tangenta @zimulala PTAL

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.

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Dec 12, 2023

The case:

  1. set tidb_enable_metadata_lock off
  2. set tidb_enable_async_commit on
  3. execute a add check foreign key ddl
  4. when ddl enter model.StateNone, a dml execute with the schemaVersion and commit use async commit.
  5. while the commit is slow for some reason, and the ddl enter model.StateWriteOnly
  6. the dml finish the prepare use a maxTx which is greate than the checkForeignKeyConstrain readTs
  7. then the dml will be a potential bug for the check.

Is there some thing wrong above?
It is not eazy to reproduce the case, but logically it can occurrs.

right? not right?

Copy link

tiprow bot commented Dec 29, 2023

@jiyfhust: 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
tiprow_fast_test 8dd0362 link true /test tiprow_fast_test

Full PR test history. Your PR dashboard.

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

@jiyfhust
Copy link
Contributor Author

Related #23363.

@jiyfhust
Copy link
Contributor Author

@ti-chi-bot ti-chi-bot bot requested a review from sticnarf December 29, 2023 04:20
Copy link

ti-chi-bot bot commented Aug 2, 2024

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 bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 2, 2024
Copy link

ti-chi-bot bot commented Sep 4, 2024

@jiyfhust: 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-lightning-integration-test 8dd0362 link true /test pull-lightning-integration-test

Full PR test history. Your PR dashboard.

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

@YangKeao YangKeao mentioned this pull request Sep 5, 2024
11 tasks
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

Let's merge this PR! Would you mind adding a test for it?

Ref https://github.com/pingcap/tidb/pull/56349/files, as I've tested, the test and failpoint in that PR should work.

It's also preferred to add more similar tests related to other situations (like check constraints, modify column...).

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Sep 27, 2024

Let's merge this PR! Would you mind adding a test for it?

I'm pleased for it,we can also work together to make this pr more complete.

@mjonss
Copy link
Contributor

mjonss commented Sep 27, 2024

For tests with different DDL States, I wrote tests for partitioning DDL, that have multiple domains, so one can even tests new transactions started in previous schema version, see here. @YangKeao, @jiyfhust That may work as inspiration for writing tests for this PR as well?

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Oct 7, 2024

Let's merge this PR! Would you mind adding a test for it?

Ref https://github.com/pingcap/tidb/pull/56349/files, as I've tested, the test and failpoint in that PR should work.

It's also preferred to add more similar tests related to other situations (like check constraints, modify column...).

My poor virtual host with only 4G memory has diffcuity to reproduce the case, expecially to run txn tests you added.
I have checked the code again, except for the "foreign key", we can't verify there really need delayForAsyncCommit(they add a schema version to handle it, but not sure can handle all cases) , I think you can fix the 'foreign key' case as you pull request does, and we now can left the others aside.

For others, maybe case like this(this is only for note):

normal 2pc and mdl off:
1. prepare
2. get commit_ts
3. if commit_ts < curruent_schema_version 
        return error

however:
async 2pc:
1. tidb node1 prepare with schema v1, not return from tikv yet, it may table a long time but before `SafeWindow` expire
2. tidb ddl owner which is node2 run ddl and schema version enter v3
3. node1 prepare success alther it is not normal now(v1->v3, the schema version is too old)
4. node1 don't need check commit_ts with schema version becasuse it is async commit
5. finally transaction committed. 

@jiyfhust jiyfhust closed this Oct 8, 2024
@jiyfhust jiyfhust deleted the fix_foreignkey_check_constraint branch October 8, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is delayForAsyncCommit needed before verify records by foreign_key and constraints check?
3 participants