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

*: infoschema compatibility with prepare #25080

Closed
wants to merge 2 commits into from
Closed

Conversation

xhebox
Copy link
Contributor

@xhebox xhebox commented Jun 3, 2021

Signed-off-by: xhe [email protected]

What problem does this PR solve?

Problem Summary: #24613 has one workaround at planner/core/common_plans.go:L268. This PR removed it.

How it works

As the new design in #24613, you should never write: ret := &PreprocessorReturn{InfoSchema: is}, the introduction of this new struct is to return something from planner.Preprocess() without touching its API definition, instead of passing down something. But without that, TestPlanCacheSchemaChange will fail.

The failure of test is due to the incorrect infoschema. And you could blame the incorrectness to concurrent DDL leads to stale infoschema in parallel transactions.

It is so hard to solve that we only workaround the problem for some of the cases. Like prepare/execute statements does not choose the correct infoschema for updateRead(even if there are no parallel transactions), so it picked up the wrong cached plan. #22381 is a workaround for this problem.

I came up with the solution of returning the latest infoschema for pessimistic transaction, and it is a direct solution for concurrent DDL and stale infoschema problem. But it seems a little risky for @jackysp .

So here is another solution, instead of solving the rock hard concurrent DDL and stale infoschema problem, the solution of #22381 is refined and concurrent DDL for tk1 and tk3 in the test is manually removed. The test should be still effective, tk2 will responsible for the wanted SchemaChange cases: there is still concurrent DDL for tk1 and tk2.

Release note

  • No release note

@xhebox xhebox requested review from a team as code owners June 3, 2021 05:27
@xhebox xhebox requested review from qw4990 and removed request for a team June 3, 2021 05:27
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 3, 2021
@xhebox xhebox requested a review from nolouch June 3, 2021 05:27
@github-actions github-actions bot added sig/execution SIG execution sig/sql-infra SIG: SQL Infra labels Jun 3, 2021
@xhebox
Copy link
Contributor Author

xhebox commented Jun 3, 2021

Fixing tests
/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 3, 2021
@jackysp
Copy link
Member

jackysp commented Jun 3, 2021

I think we have an internal discussion for it, and it depends on the MDL feature in TiDB.

@xhebox
Copy link
Contributor Author

xhebox commented Jun 3, 2021

@jackysp I'll pick another approach to fix instead.

@xhebox xhebox changed the title *: infoschema compatibility with pessimistic txn *: infoschema compatibility with prepare Jun 3, 2021
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 3, 2021
@xhebox
Copy link
Contributor Author

xhebox commented Jun 3, 2021

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 3, 2021
@github-actions github-actions bot added the sig/planner SIG: Planner label Jun 3, 2021
@nolouch
Copy link
Member

nolouch commented Jun 4, 2021

PTAL @lysu @cfzjywxk

ok, err = s.IsCachedExecOk(ctx, preparedStmt)

var is infoschema.InfoSchema
if preparedStmt.ForUpdateRead {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a bit risky currently to change the used schema version in transaction execution. Now the possible inconsistency issue bettwen the current read and snapshot schema meta is not resolved completely or it's worked around by a temprora index in https://github.com/pingcap/tidb/pull/22152/files. There are some implicit logic in tidb logic assuming the information schema is always consistent during the executions.

Copy link
Contributor Author

@xhebox xhebox Jun 4, 2021

Choose a reason for hiding this comment

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

No, it is not a change in this PR. It is a change introduced by #22381. I only extract the logic outside IsCachedExecOK and optimize, which is essentially a cleanup. I did nothing to the current logic of execution.

The real change is the removal of tk3 and InfoSchema: is in ret := &PreprocessorReturn{InfoSchema: is}. The removal of InfoSchema: is will lead to the test error again, and the removal of tk3 fixed the test error by avoid concurrent DDL.

Copy link
Contributor

Choose a reason for hiding this comment

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

The inforschema change for the cached plan short path is ok as it's only for autocommit point get read, the extraction may affect the common path in whch change inforschema version is risky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, it is not a must for me to change that anyway. It is reverted.

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 4, 2021
@xhebox xhebox requested a review from cfzjywxk June 4, 2021 10:39
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2021
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

Current changes are not the same as what the pr body describes?
I have no idea why the the new one can take effect:joy:

@xhebox
Copy link
Contributor Author

xhebox commented Jun 21, 2021

Current changes are not the same as what the pr body describes?
I have no idea why the the new one can take effect😂

Same, except that the refine part is removed. In short, I want to remove PreprocessorReturn{Infoschema: is}, which will lead to concurrent DDL error in tests, and the corresponding tests are patched.

The cause for concurrent DDL error: if you specify infoschema in PreprocessorReturn, it is enforced to the latest infoschema, which will sync changes amomg three different transactions.

But it is actually not correct in another view of point. Our expectation is that infoschema is unchanged because txn startTS is never changed, and DDL is not executed in this session. Only some cases are special, e.g. forUpdate needs the latest infoschema.

My previous PR unify most getters of infoschema to return the infoschema of the transaction, if it is in transactions. This infoschema of transction does not sync among others, and that breaks some tests assuming synchronisation of infoschema amomg multiple transactions.

@ti-chi-bot
Copy link
Member

@xhebox: 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 the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 8, 2021
@xhebox
Copy link
Contributor Author

xhebox commented Aug 9, 2021

Closed in favor of #26759

@xhebox xhebox closed this Aug 9, 2021
@xhebox xhebox deleted the stale_4 branch August 9, 2021 02:22
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. sig/execution SIG execution sig/planner SIG: Planner sig/sql-infra SIG: SQL Infra 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.

6 participants