-
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: migrate prepared statements during session migration #76399
sql: migrate prepared statements during session migration #76399
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.
changes lgtm.
one thing i am curious about - what happens to prepared statements if a schema change happened and the types change? in turn, does AddPreparedStatement
during a session migration potentially change the result of the prepared statement producing an entirely different statement? is it worth testing?
CC @RaduBerinde to make sure to take a look at this. |
This is the behavior without any session migration involved:
yeah we definitely should test. given the above, i guess the two options are to not serialize a prepared statement if it's not valid at the time of serialization, or to ignore certain types of prepare errors at the time of deserialization. |
We could also keep the behavior as-is and just error out. (The user-impact is that their client would get a hard disconnect rather than a graceful session migration.) |
happy with erroring out. also happy for you to add this test in a separate PR. |
347fce3
to
a1477d2
Compare
confirmed the behavior for prepared statements after a schema change at the last multi-tenant team meeting with signoff from @jeffswenson so going to merge this. bors r=otan |
a1477d2
to
ad02cf5
Compare
Canceled. |
bors r=otan |
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.
I believe this will fail:
cockroach/pkg/ccl/testccl/sqlccl/show_transfer_state_test.go
Lines 199 to 225 in 696cdd5
t.Run("prepared_statements", func(t *testing.T) { | |
pgURL, cleanup := sqlutils.PGUrl( | |
t, | |
tenant.SQLAddr(), | |
"TestShowTransferState-errors-prepared_statements", | |
url.UserPassword(security.TestUser, "hunter2"), | |
) | |
defer cleanup() | |
conn, err := gosql.Open("postgres", pgURL.String()) | |
require.NoError(t, err) | |
defer conn.Close() | |
// Use a dummy prepared statement. | |
stmt, err := conn.Prepare("SELECT 1 WHERE 1 = 1") | |
require.NoError(t, err) | |
defer stmt.Close() | |
var errVal, sessionState, sessionRevivalToken gosql.NullString | |
err = conn.QueryRow("SHOW TRANSFER STATE").Scan(&errVal, &sessionState, &sessionRevivalToken) | |
require.NoError(t, err) | |
require.True(t, errVal.Valid) | |
require.Equal(t, "cannot serialize a session which has portals or prepared statements", errVal.String) | |
require.False(t, sessionState.Valid) | |
require.False(t, sessionRevivalToken.Valid) | |
}) |
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jaylim-crl and @rafiss)
pkg/sql/types/types.go, line 1746 at r5 (raw file):
// messages
//and also to produce the output of SHOW CREATE.
nit: typo here?
Build failed (retrying...): |
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.
ah, whoops. fixing
bors r-
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jaylim-crl)
pkg/sql/types/types.go, line 1746 at r5 (raw file):
Previously, jaylim-crl (Jay Lim) wrote…
// messages
//and also to produce the output of SHOW CREATE.nit: typo here?
fixed
Canceled. |
ad02cf5
to
762f214
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.
@jaylim-crl i edited that test, in case you want to take a look
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jaylim-crl)
edit: nvm i see it is done 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.
@jaylim-crl i edited that test, in case you want to take a look
Thanks. The test LGTM.
Reviewed 2 of 2 files at r1, 2 of 2 files at r2, 4 of 4 files at r3, 13 of 16 files at r4, 4 of 4 files at r6, 3 of 3 files at r7, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)
This will allow us to more easily call into the code to prepare statements when deserializing. Release note: None
Release note: None
After the recent refactor for deserialize_session, it no longer needs to be exposed. Release note: None
Release note (sql change): The crdb_internal.serialize_session and crdb_internal.deserialize_session now can handle prepared statements. When deserializing, any prepared statements that existed when the session was serialized are re-prepared. It is an error to re-prepare a statement if the current session already has a statement with that name.
A schema change can make an existing prepared statement invalid. Rather than returning an error when deserializing that invalid statement, now the error will be returned only when trying to use the statement. This makes a session migration even more transparent to the end user. Release note: None
762f214
to
dda2fa9
Compare
tftrs! bors r=otan |
Build failed (retrying...): |
Build failed: |
the failures all seem to be flakes as far as i can tell.. bors r=otan |
Build failed: |
yet another flake.. bors r=otan |
Build succeeded: |
congrats on winning the CI lottery! |
fixes #76398
See individual commits. The last one contains the business logic changes,
and the rest are just refactors.
Release note (sql change): The crdb_internal.serialize_session and
crdb_internal.deserialize_session now can handle prepared statements.
When deserializing, any prepared statements that existed when the
session was serialized are re-prepared. It is an error to re-prepare a
statement if the current session already has a statement with that name.