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

*: fix check constraintInfo state change #44455

Merged
merged 33 commits into from
Jun 16, 2023

Conversation

fzzf678
Copy link
Contributor

@fzzf678 fzzf678 commented Jun 6, 2023

What problem does this PR solve?

Issue Number: ref #41711

Problem Summary:

What is changed and how it works?

In the process of changing the schemaState of the check constraint, it is stateNone- > stateWriteOnly - > statePublic. The remaining data will be verified during sateWriteOnly. At this time, if there is a tidb node still in stateNone state, it is possible to insert data that violates the check constraint.
To avoid this problem, I added a stateWriteReorg state after the stateWriteOnly state, where the remaining data is checked. Make sure other tidb nodes are at least in stateWriteOnly state

Check List

Tests

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

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
Copy link

ti-chi-bot bot commented Jun 6, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 6, 2023
@ti-chi-bot ti-chi-bot bot requested a review from nolouch June 6, 2023 11:26
@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 6, 2023
@fzzf678 fzzf678 changed the title *: State check constraint *: State check constraint | tidb-test=pr/2146 Jun 6, 2023
@fzzf678 fzzf678 removed the request for review from nolouch June 6, 2023 11:27
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 6, 2023

/test all

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 6, 2023

/test all

@ti-chi-bot ti-chi-bot bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 7, 2023
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 7, 2023

/test check_dev_2

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 7, 2023

@fzzf678: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test canary-scan-security
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-integration-mysql-test
  • /test unit-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test

In response to this:

/test check_dev_2

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.

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 7, 2023

/test check-dev2

ver, err = updateVersionAndTableInfoWithCheck(d, t, job, tblInfo, originalState != constraintInfoInMeta.State)
case model.StateWriteReorganization:
skipCheck := false
failpoint.Inject("mockVerifyRemainDataSuccess", func(val failpoint.Value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can put it to verifyRemainRecordsForCheckConstraint, and if mockVerifyRemainDataSuccess is ture, we can return this function. Then we needn't add skipCheck.

job.SchemaState = model.StateWriteReorganization
constraintInfoInMeta.State = model.StateWriteReorganization
ver, err = updateVersionAndTableInfoWithCheck(d, t, job, tblInfo, originalState != constraintInfoInMeta.State)
case model.StateWriteReorganization:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we add a new state for this operation?

Copy link
Contributor Author

@fzzf678 fzzf678 Jun 12, 2023

Choose a reason for hiding this comment

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

Because I want to make sure that the state of all tidb nodes is changed to StateWriteOnly before doing remaining data verification, so that no data is written that violates the check constraint.
If doing remaining data verification in StateWriteOnly state, the state of some nodes may be still in StateNone ( am i right?), so even if the remaining data verification passes, there are still StateNone nodes that can write data that violates the check constraint. Hence I added a state to ensure that all nodes change at least to StateWriteOnly before verifying the data. Is this right or not, please give some advice, thks

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, there was no PR description before, I don't know why it suddenly added a status, so ask.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems here we missed delete-only state, that is before writeonly state. write reorg means will reorg table data.

@fzzf678 fzzf678 requested a review from zimulala June 14, 2023 06:09
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 15, 2023

/cc @wjhuang2016 PTAL

@ti-chi-bot ti-chi-bot bot requested a review from wjhuang2016 June 15, 2023 01:03
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 15, 2023

@fzzf678: 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 @wjhuang2016 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.

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 15, 2023

/test check-dev2

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 15, 2023

@fzzf678: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test canary-scan-security
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-integration-mysql-test
  • /test unit-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test

In response to this:

/test check-dev2

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.

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 15, 2023

/test check-dev2

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 15, 2023
dbInfo, tblInfo, constraintInfo, enforced, err := checkAlterCheckConstraint(t, job)
if err != nil {
return ver, errors.Trace(err)
}

// enforced will fetch table data and check the constraint.
if constraintInfo.Enforced != enforced && enforced {
err = w.verifyRemainRecordsForCheckConstraint(dbInfo, tblInfo, constraintInfo, job)
Copy link
Contributor Author

@fzzf678 fzzf678 Jun 16, 2023

Choose a reason for hiding this comment

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

In the check constraint, when changing from not enforced to enforced, remaining data verification is required. All nodes in tidb may have two states, enforced and not enforced.If the remaining data verification is carried out directly, data that violates the check constraint may also be written after passing. Therefore, state changes are added to ensure that all nodes have reached the enforced state before remaining data verification.

Copy link
Contributor

@TonsnakeLin TonsnakeLin 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 ti-chi-bot bot added the lgtm label Jun 16, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CbcWestwolf, TonsnakeLin

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

The pull request process is described 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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 16, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 16, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-06-15 15:55:07.768910566 +0000 UTC m=+273904.183514646: ☑️ agreed by CbcWestwolf.
  • 2023-06-16 03:09:16.39890828 +0000 UTC m=+314352.813512358: ☑️ agreed by TonsnakeLin.

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 16, 2023

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants