-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: (DRAFT) Refactor stale read code #32325
Conversation
[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 The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
@lcwangchao: 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. |
"github.com/pingcap/tidb/kv" | ||
|
||
"github.com/pingcap/tidb/sessiontxn" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format this part.
Co-authored-by: JmPotato <[email protected]>
[FORMAT CHECKER NOTIFICATION] Notice: To remove the 📖 For more info, you can check the "Contribute Code" section in the development guide. |
This is a draft to refactor stale read according to new txn context management design: #30535 . In this PR, the stale read implements are moved to a standalone package to make the code more cohesive. This PR also provides some interfaces and decouple the stale read processing to some inherent classes according the different scenes.
staleReadTxnContextProvider
In this PR we introduce a new struct
staleReadTxnContextProvider
.staleReadTxnContextProvider
implementsTxnContextProvider
, and it provides the txn context when the current scene is stale read.staleReadTxnContextProvider
implements the below methods:GetTxnInfoSchema
returns the information schema for stale read.GetReadTS
returns the ts for readGetReadReplicaScope
returns the read replica prefer for the stale readNotice that
staleReadTxnContextProvider
is only one of subclasses forTxnContextProvider
, we'll implement other providers likeRRTxnContextProvider
orRCTxnContextProvider
. So the concept of these methods should not limited only to stale read.After moving the stale read context to
TxnManager
we can the fetch these context from session instead of passing them as method arguments, it makes the code more simple and clear.staleread.StmtProcessor
In this PR, we moved the stale read processing code to
staleread.StmtProcessor
. Comparing the old code, it decoupled stale read processing from preprocessor and make the code easier to do uint test.We should process stale read for below scenes:
The process rules for the above scenes are not the same. The old implement write all the processing code together that makes it hard to understand and easier to get a bug. In the PR, we separate them into different logicals. The below processors are introduced:
InitTxnContextProcessor
It is used to initialize stale read txn context. This processor will parse the stale read context from sql and sys variables and set the TxnManager's provider tostaleReadTxnContextProvider
PrepareParseProcessor
It is used to parse the stale read ts for a sql to prepare. It will not affect the current txn context.CreateViewProcessor
It is used to forbid stale read sql when creating a view.All the above processors will parse the stale read ts, but the paring ways may be a little different. For example
CreateViewProcessor
will ignore sys variables and only check stale read settings in sql.All the above processors will implement a interface below and the
preprocessor
need not to care about the differences for the above scenes:Other
In this PR, the
staleread
package also provides some methods to encapsulate some stale read operations. For example:staleread.IsStaleness
returns wether the current statement is staleness according to the current txn provider andExplicitStartStaleReadTxn
starts new stale read txn. To move most of the complexity to thestaleread
package, the code is easier to maintain.