-
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,externalconn: add owner_id column to system.external_connections #97877
sql,externalconn: add owner_id column to system.external_connections #97877
Conversation
e5d2884
to
46c8bc1
Compare
97519f4
to
9467cf7
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.
Thanks! It might be good to put why we are adding this field in the PR/commit message somewhere.
We also need to handle external_connections tables in backups that don't the owner_id column. Check out 1bc6c6d for an example.
9467cf7
to
b7bdea3
Compare
Done.
Yep, I'm planning on doing that in a followup PR where I set the column to be NOT NULL. |
b7bdea3
to
e1639ff
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @andyyang890, @dt, and @stevendanna)
pkg/cloud/externalconn/record.go
line 355 at r2 (raw file):
case `owner`: arg = tree.NewDString(e.rec.Owner.Normalized()) case `owner_id`:
it looks like this change will cause the owner_id column to always be stored. but we need to gate it on the clusterversion you just added.
and it would be good to have a test that shows it working fine in a mixed version cluster. let's add another mixed-version logic test using the new framework (which is skipped right now, but you should be able to run locally)
pkg/sql/create_external_connection.go
line 141 at r2 (raw file):
row, err := txn.QueryRowEx(params.ctx, `get-user-id`, txn.KV(), sessiondata.NodeUserSessionDataOverride, `SELECT user_id FROM system.users WHERE username = $1`,
in the future, we should add another function similar to p.User()
that returns the user ID instead. that way we can cache the user ID in one place, and avoid having to do this lookup query in many places. could you file a github issue for that, and make a comment here that references it?
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 @adityamaru, @dt, @rafiss, and @stevendanna)
pkg/sql/create_external_connection.go
line 141 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
in the future, we should add another function similar to
p.User()
that returns the user ID instead. that way we can cache the user ID in one place, and avoid having to do this lookup query in many places. could you file a github issue for that, and make a comment here that references it?
Done. See #98170
e1639ff
to
d0a04d5
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.
FYI I rebased this onto #98163 so the first commit is from that.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @dt, @rafiss, and @stevendanna)
pkg/cloud/externalconn/record.go
line 355 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
it looks like this change will cause the owner_id column to always be stored. but we need to gate it on the clusterversion you just added.
and it would be good to have a test that shows it working fine in a mixed version cluster. let's add another mixed-version logic test using the new framework (which is skipped right now, but you should be able to run locally)
I added some gating by threading through a map of excluded columns from the relevant planner function since I don't think this function has access to the version handle, but I'm not sure if this is the best approach. Let me know if you have any other ideas!
pkg/upgrade/upgrades/external_connections_table_user_id_migration_test.go
line 20 at r4 (raw file):
"github.com/cockroachdb/cockroach/pkg/base" _ "github.com/cockroachdb/cockroach/pkg/cloud/userfile"
I had to add this import in order to trigger the init()
function to make the CREATE EXTERNAL CONNECTION
statement below work.
d0a04d5
to
52a82cd
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @andyyang890, @dt, and @stevendanna)
pkg/cloud/externalconn/record.go
line 355 at r2 (raw file):
Previously, andyyang890 (Andy Yang) wrote…
I added some gating by threading through a map of excluded columns from the relevant planner function since I don't think this function has access to the version handle, but I'm not sure if this is the best approach. Let me know if you have any other ideas!
this looks like it works, but i'd be curious if @stevendanna or @adityamaru have opinions on how to version gate this, since they own this area of the code.
pkg/sql/logictest/testdata/logic_test/testserver_22.2_23.1_external_connections_user_id_upgrade
line 3 at r5 (raw file):
# LogicTest: cockroach-go-testserver-22.2-master # Verify that all nodes are running 22.2 binaries.
nit: i think we can remove these checks for 22.2 binaries. they were there in the first mixed version test more as a sanity check / proof-of-concept
pkg/sql/logictest/testdata/logic_test/testserver_22.2_23.1_external_connections_user_id_upgrade
line 52 at r5 (raw file):
upgrade 2 # Verify that all nodes are now running 23.1 binaries.
ditto 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.
Thanks for doing this!
pkg/sql/logictest/testdata/logic_test/testserver_22.2_23.1_external_connections_user_id_upgrade
Outdated
Show resolved
Hide resolved
52a82cd
to
d5feb1f
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @dt, @rafiss, and @stevendanna)
pkg/sql/logictest/testdata/logic_test/testserver_22.2_23.1_external_connections_user_id_upgrade
line 3 at r5 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
nit: i think we can remove these checks for 22.2 binaries. they were there in the first mixed version test more as a sanity check / proof-of-concept
Done.
pkg/sql/logictest/testdata/logic_test/testserver_22.2_23.1_external_connections_user_id_upgrade
line 52 at r5 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
ditto above
Done.
d5feb1f
to
99a4f6a
Compare
TFTRs! bors r=rafiss,adityamaru |
Build failed: |
bors r=rafiss,adityamaru |
Build failed: |
This patch adds a new `owner_id` column to the `system.external_connections` table, which corresponds to the existing `owner` column, in order to bring us closer to the eventual goal of allowing renaming of users. Migrations are also added to alter and backfill the table in older clusters. Release note: None
99a4f6a
to
b4e7296
Compare
bors r=rafiss,adityamaru |
Build failed (retrying...): |
Build succeeded: |
This patch adds a new
owner_id
column to thesystem.external_connections
table, which corresponds to the existing
owner
column, in order to bring uscloser to the eventual goal of allowing renaming of users. Migrations are
also added to alter and backfill the table in older clusters.
Part of #87079
Part of #92342
Release note: None