-
Notifications
You must be signed in to change notification settings - Fork 3.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
sql: use RLock in connExecutor.CancelQuery and connExecutor.CancelActiveQueries #96241
Conversation
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
@@ -2034,12 +2034,6 @@ type queryMeta struct { | |||
database string | |||
} | |||
|
|||
// cancel cancels the query associated with this queryMeta, by closing the | |||
// associated stmt context. | |||
func (q *queryMeta) cancel() { |
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.
This method just calls a similarly named function field and seems like an unnecessary layer.
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.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ecwall and @yuzefovich)
-- commits
line 7 at r1:
just curious: then what is responsible for removing the query from the ActiveQueries
list?
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
// BaseSessionUser is part of the RegistrySession interface. func (ex *connExecutor) BaseSessionUser() username.SQLUsername {
nit: the word Base
is redundant in the function name. the session user is immutable, and always is the user who originally logged in. (you could also replace ex.sessionDataStack.Base().SessionUser()
below with ex.sessionDataStack.SessionUser()
)
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.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @yuzefovich)
Previously, rafiss (Rafi Shamim) wrote…
just curious: then what is responsible for removing the query from the
ActiveQueries
list?
It happens here in a defer
after it is added to ActiveQueries
:
cockroach/pkg/sql/conn_executor_exec.go
Line 351 in 194f6a1
ex.removeActiveQuery(queryID, ast) |
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
nit: the word
Base
is redundant in the function name. the session user is immutable, and always is the user who originally logged in. (you could also replaceex.sessionDataStack.Base().SessionUser()
below withex.sessionDataStack.SessionUser()
)
I renamed BaseSessionUser()
to SessionUser()
, but Stack
does not have a SessionUser()
method.
Are you saying that
func (s *SessionData) SessionUser() username.SQLUsername {
if s.SessionUserProto == "" {
return s.User()
}
return s.SessionUserProto.Decode()
}
should actually be a method on Stack
?
func (s *Stack) SessionUser() username.SQLUsername {
session := s.base
if session.SessionUserProto == "" {
return session.User()
}
return session.SessionUserProto.Decode()
}
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.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ecwall and @yuzefovich)
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, ecwall (Evan Wall) wrote…
I renamed
BaseSessionUser()
toSessionUser()
, butStack
does not have aSessionUser()
method.Are you saying that
func (s *SessionData) SessionUser() username.SQLUsername { if s.SessionUserProto == "" { return s.User() } return s.SessionUserProto.Decode() }
should actually be a method on
Stack
?func (s *Stack) SessionUser() username.SQLUsername { session := s.base if session.SessionUserProto == "" { return session.User() } return session.SessionUserProto.Decode() }
no, i mistyped. i meant to say that you can use ex.sessionData().SessionUser()
. analogous to the user()
function you deleted above.
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.
Reviewed 2 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @ecwall and @rafiss)
Previously, ecwall (Evan Wall) wrote…
It happens here in a
defer
after it is added toActiveQueries
:
cockroach/pkg/sql/conn_executor_exec.go
Line 351 in 194f6a1
ex.removeActiveQuery(queryID, ast)
When I was reviewing #95745, I was also confused by this. Consider adding a quick comment to CancelQuery
and CancelActiveQueries
that we can use read-lock there because the actual removal of the query meta from the map occurs in removeActiveQuery
.
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.
lgtm with one nit, and i also agree with yahor's sugegstion to comment this
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ecwall)
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
no, i mistyped. i meant to say that you can use
ex.sessionData().SessionUser()
. analogous to theuser()
function you deleted above.
nit: i think it would be more consistent with other usages of it were changed
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.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @rafiss)
Previously, yuzefovich (Yahor Yuzefovich) wrote…
When I was reviewing #95745, I was also confused by this. Consider adding a quick comment to
CancelQuery
andCancelActiveQueries
that we can use read-lock there because the actual removal of the query meta from the map occurs inremoveActiveQuery
.
Added
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
nit: i think it would be more consistent with other usages of it were changed
That is using the SessionData from the top of the stack instead of the bottom like before.
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.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ecwall)
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, ecwall (Evan Wall) wrote…
That is using the SessionData from the top of the stack instead of the bottom like before.
as i mentioned above, SessionUser is immutable. see
cockroach/pkg/sql/sessiondata/session_data.go
Lines 148 to 151 in d6a32ed
// SessionUser retrieves the session_user. | |
// The SessionUser is the username that originally logged into the session. | |
// If a user applies SET ROLE, the SessionUser remains the same whilst the | |
// User() changes. |
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.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ecwall)
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
as i mentioned above, SessionUser is immutable. see
cockroach/pkg/sql/sessiondata/session_data.go
Lines 148 to 151 in d6a32ed
// SessionUser retrieves the session_user. // The SessionUser is the username that originally logged into the session. // If a user applies SET ROLE, the SessionUser remains the same whilst the // User() changes.
using Base
does work, but it's just confusing since it's inconsistent with all the other usages of SessionUser
…iveQueries Fixes #95994 `connExecutor.CancelQuery` and `connExecutor.CancelActiveQueries` do not modify `mu.ActiveQueries` or the `*queryMetas` inside so they can safely use `RLock` instead of `Lock`. Release note: None
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.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @rafiss and @yuzefovich)
pkg/sql/conn_executor.go
line 3178 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
using
Base
does work, but it's just confusing since it's inconsistent with all the other usages ofSessionUser
Talked about it in slack. Only the base stack element is thread safe so adding a comment to explain why we are using it instead of the more common ex.sessionData()
.
bors r=rafiss,yuzefovich |
This PR was included in a batch that was canceled, it will be automatically retried |
Build failed (retrying...): |
Build failed (retrying...): |
Build succeeded: |
Fixes #95994
connExecutor.CancelQuery
andconnExecutor.CancelActiveQueries
do not modifymu.ActiveQueries
or the*queryMetas
inside so they can safely useRLock
instead ofLock
.Release note: None