-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
*: make package sqlexec
not depend on sessionctx
anymore
#52031
Conversation
Hi @lcwangchao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
1981522
to
bb9d614
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #52031 +/- ##
=================================================
- Coverage 72.4146% 55.3920% -17.0226%
=================================================
Files 1481 1597 +116
Lines 365306 615494 +250188
=================================================
+ Hits 264535 340935 +76400
- Misses 81220 251233 +170013
- Partials 19551 23326 +3775
Flags with carried forward coverage won't be shown. Click here to find out more.
|
[LGTM Timeline notifier]Timeline:
|
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.
br part lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: BornChanger, hawkingrei, lance6716, tangenta, xhebox 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 |
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
What problem does this PR solve?
Issue Number: close #52029
Problem Summary:
sqlexec
is a package that defines interfaces to execute SQL. The session in TiDB implements these interfaces insqlexec
. However, in most cases, the session is provided to the coder as the typesessionctx.Context
, if the coder wants to execute some SQL there, they have to castsessionctx.Context
tosqlexec.SQLExecutor
orsqlexec.RestrictedSQLExecutor
like this:The above operation is dangerous because we have an assumption that the variable
sctx
must also implementsqlexec.SQLExecutor
and this assumption is not guaranteed by the compiler. If one day we introduced a new type that implementssessionctx.Context
but not implementssqlexec.SQLExecutor
, the above code will panic.Why not to make
sessionctx.Context
implementsqlexec.SQLExecutor
? Because it has a reverse dependency thatsqlexec.SQLExecutor
depends onsessionctx.Context
. And it is another problem because it means any package want to usesqlexec
will also depend onsessionctx
which also brings a large number of dependencies.It's better to make a change to let
sessionctx
to depend onsqlexec
instead.What changed and how does it work?
In this PR:
sysproctrack
and move some related interface definitions to it.sqlexec
depend onsysproctrack
instead ofsessionctx
.sessionctx.Context
depend onsqlexec
and added two methods on it:GetSQLExectuor
to get aSQLExecutor
GetRestrictedSQLExecutor
to get aRestrictedSQLExecutor
sctx.(sqlexec.SQLExecutor)
tosctx.GetRestrictedSQLExecutor()
to make the code stronger.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.