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

*: Provide staleReadProcessor to process stale read #32699

Merged
merged 21 commits into from
Mar 8, 2022

Conversation

lcwangchao
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #32697

What is changed and how it works?

This is one of the PRs to refactor stale read. The full draft is here: #32325

This modifications of the PR includes:

  • Introduce a new package staleread to provide stale read related functions.
  • Introduce a new interface staleread.Processor to provide methods processing and fetching stale read context.
  • Move some of the stale read processing codes to staleread.staleReadProcessor which implements staleread.Processor to simplify Preprocessor .

For the PRs in the future, we'll do more things refactoring stale read, including:

  • Move more stale read codes (prepare/execute/begin) to processor.
  • Separate the processor the some sub classes for different scenes (Prepare, CreateView, InitTxnContext ...).
  • Provide StaleReadTxnContextProvider and set it to TxnManager in processor

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

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 1, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Yisaer
  • xhebox

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 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. labels Mar 1, 2022
@lcwangchao
Copy link
Collaborator Author

/run-unit-test
/run-mysql-test

@sre-bot
Copy link
Contributor

sre-bot commented Mar 1, 2022

@lcwangchao
Copy link
Collaborator Author

/run-mysql-test

@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 2, 2022
@lcwangchao
Copy link
Collaborator Author

/run-mysql-test

@lcwangchao
Copy link
Collaborator Author

/run-unit-test

@lcwangchao lcwangchao requested review from Yisaer, xhebox and JmPotato March 2, 2022 08:09
@lcwangchao
Copy link
Collaborator Author

/run-unit-test
/run-mysql-test

@@ -184,6 +188,8 @@ type preprocessor struct {
tableAliasInJoin []map[string]interface{}
withName map[string]interface{}

staleReadProcessor staleread.Processor
Copy link
Member

Choose a reason for hiding this comment

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

Though I'm OK to make this change, does this mean that we may have more and more xxxProcessor fields in the future? Do we have any idea on how to simplify this part?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Having a staleReadProcessor here is to decouple the stale read code from preprocessor and expect to reuse it. It is only a choice for stale read and I think for other scenes the design will not be limited to 'xxxProcessor'.

For stale read, in the future, there is still only one processor to process stale read. However, we can have multiple subclasses inherits staleread.Processor and we can use one of them according to the exact scenario

planner/core/preprocess.go Show resolved Hide resolved
@lcwangchao
Copy link
Collaborator Author

/run-unit-test

@lcwangchao
Copy link
Collaborator Author

/run-unit-test
/run-mysql-test

@lcwangchao
Copy link
Collaborator Author

/run-unit-test

Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

LGTM overall

sessiontxn/staleread/processor.go Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 4, 2022
Copy link
Contributor

@Yisaer Yisaer left a comment

Choose a reason for hiding this comment

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

rest lgtm

Comment on lines +139 to +140
// OnSelectTable will be called when process table in select statement
func (p *staleReadProcessor) OnSelectTable(tn *ast.TableName) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the comment for explaining the code logic removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll complete it later

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

sessiontxn/staleread/main_test.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 8, 2022
@lcwangchao
Copy link
Collaborator Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 371a42b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 8, 2022
@lcwangchao
Copy link
Collaborator Author

/run-mysql-test

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 8, 2022
@lcwangchao
Copy link
Collaborator Author

/run-mysql-test

@lcwangchao
Copy link
Collaborator Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: c350f1e

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 8, 2022
@ti-chi-bot ti-chi-bot merged commit f79d2a5 into pingcap:master Mar 8, 2022
@lcwangchao lcwangchao deleted the stalereadprocessor branch July 5, 2022 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide staleReadProcessor to process stale read
6 participants