-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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/pgwire: send down parameter status updates #42376
sql/pgwire: send down parameter status updates #42376
Conversation
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.
Does this make that JDBC test pass?
pkg/sql/exec_util.go
Outdated
if m.onSessionDataChangeListeners == nil { | ||
m.onSessionDataChangeListeners = make(map[string][]func(val interface{})) | ||
} | ||
if _, ok := m.onSessionDataChangeListeners[key]; !ok { |
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.
There's no need for this block.
pkg/sql/exec_util.go
Outdated
applicationNameChanged func(newName string) | ||
// onSessionDataChangeListeners stores all the observers to execute when | ||
// session data is modified, keyed by the value to change on. | ||
onSessionDataChangeListeners map[string][]func(val interface{}) |
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.
Why does this need to be a slice? Can there ever by more than one per key?
pkg/sql/pgwire/conn.go
Outdated
value := connHandler.GetStatusParam(ctx, param) | ||
if err := c.sendStatusParam(param, value); err != nil { | ||
return sql.ConnectionHandler{}, err | ||
} | ||
// pgwire also expects updates when these parameters change. | ||
connHandler.RegisterOnSessionDataChange(param, func(val interface{}) { | ||
convertVal := val.(string) |
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.
Can val be a string
instead of interface{}
to avoid the forced cast? Seems unsafe otherwise.
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.
Yep, the tests pass with this change.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mjibson, @otan, and @rafiss)
pkg/sql/exec_util.go, line 1743 at r1 (raw file):
Previously, mjibson (Matt Jibson) wrote…
Why does this need to be a slice? Can there ever by more than one per key?
Yes, I think the application_name
one can be used more than once - once for stats and once for pgwire (the change for this is somewhere else in this PR).
pkg/sql/exec_util.go, line 1752 at r1 (raw file):
Previously, mjibson (Matt Jibson) wrote…
There's no need for this block.
Ooh.
pkg/sql/pgwire/conn.go, line 620 at r1 (raw file):
Previously, mjibson (Matt Jibson) wrote…
Can val be a
string
instead ofinterface{}
to avoid the forced cast? Seems unsafe otherwise.
Yes, I saw some Set
params that were not string
s, but they don't seem to need listeners (yet) so okay with doing this.
pkg/sql/pgwire/testdata/pgtest/connection_params, line 22 at r1 (raw file):
Previously, mjibson (Matt Jibson) wrote…
Do we support word time zones (
MDT
)? If so I'd like to see another test with that.
Added a test.
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 @mjibson and @rafiss)
pkg/sql/pgwire/testdata/pgtest/connection_params, line 1 at r1 (raw file):
Previously, mjibson (Matt Jibson) wrote…
If this file differs from what postgres does it should document that with a comment.
Done.
98b1e7b
to
db63b33
Compare
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.
Can you flesh out the comment in the commit message about exactly why the logic test results changed? Is it because lib/pq supports reading the timezone back from the connection and sets the location data of received timestamps from it?
{"Type":"ReadyForQuery","TxStatus":"I"} | ||
|
||
# Change the time zone. | ||
# NOTE: the order is different than postgres, because we execute the statement |
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.
once at the top is enough
@@ -0,0 +1,55 @@ | |||
# Change the application name. | |||
# NOTE: the order is different than postgres, because we execute the statement |
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.
Are you sure this is the reason? The commit message is more unsure. (I'm also unsure, I just don't want to have an incorrect statement here.)
db63b33
to
e891f0a
Compare
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.
Can you flesh out the comment in the commit message about exactly why the logic test results changed? Is it because lib/pq supports reading the timezone back from the connection and sets the location data of received timestamps from it?
yep!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mjibson and @rafiss)
pkg/sql/pgwire/testdata/pgtest/connection_params, line 2 at r2 (raw file):
Previously, mjibson (Matt Jibson) wrote…
Are you sure this is the reason? The commit message is more unsure. (I'm also unsure, I just don't want to have an incorrect statement here.)
I dug even further into this and realised I wasn't buffering. I got mislead earlier.
pkg/sql/pgwire/testdata/pgtest/connection_params, line 22 at r2 (raw file):
Previously, mjibson (Matt Jibson) wrote…
once at the top is enough
Done.
19ce597
to
00f99b3
Compare
Nice stuff! Could you take a look at |
Server parameters such as `application_name` require updates over pgwire when they are charged. This was previously not done. This applies to time zone changes as well. In this PR, we introduce a listener-esque object on `sessionDataMutator` that pgwire will add itself onto to send updates on these changes. Coincidentally, this means a few logic tests changes because lib/pq will encode this into the string. Release note (sql change): This PR introduces a new pgwire update that sends ParameterStatus messages when certain server parameters are changed for the given session over pgwire.
00f99b3
to
08c89c4
Compare
thanks! bors r+ |
42376: sql/pgwire: send down parameter status updates r=otan a=otan Resolves #40854. Server parameters such as `application_name` and `timezone` require updates over pgwire when they are changed. This was previously not done. In this PR, we introduce a listener-esque object on `sessionDataMutator` that pgwire will add itself onto to send updates on these changes. Coincidentally, this means a few logic tests changes because lib/pq will encode this into the string. Release note (sql change): This PR introduces a new pgwire update that sends ParameterStatus messages when certain server parameters are changed for the given session over pgwire. Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
Build succeeded |
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.
@otan did you attempt to implement this through the sql.CommandResult
interface, instead of creating a new communication mechanism between sql and pgwire? I'm thinking the sql.CommandResult
could carry these updates, which would make the control flow much easier to reason about.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mjibson and @rafiss)
@andreimatei that works too, see #44883. couldn't get this to work for |
Resolves #40854.
Server parameters such as
application_name
andtimezone
require updatesover pgwire when they are changed. This was previously not done.
In this PR, we introduce a listener-esque object on
sessionDataMutator
that pgwire will add itself onto to send updates on these changes.
Coincidentally, this means a few logic tests changes because lib/pq will
encode this into the string.
Release note (sql change): This PR introduces a new pgwire update that
sends ParameterStatus messages when certain server parameters are
changed for the given session over pgwire.