Skip to content
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

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

andyyang890
Copy link
Collaborator

@andyyang890 andyyang890 commented Mar 1, 2023

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.

Part of #87079
Part of #92342

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andyyang890 andyyang890 force-pushed the migrate_external_connections branch 4 times, most recently from e5d2884 to 46c8bc1 Compare March 2, 2023 19:58
@andyyang890 andyyang890 changed the title sql: add owner_id column to system.external_connections table sql,externalconn: add owner_id column to system.external_connections Mar 2, 2023
@andyyang890 andyyang890 force-pushed the migrate_external_connections branch 2 times, most recently from 97519f4 to 9467cf7 Compare March 3, 2023 05:12
@andyyang890 andyyang890 marked this pull request as ready for review March 3, 2023 05:12
@andyyang890 andyyang890 requested a review from a team March 3, 2023 05:12
@andyyang890 andyyang890 requested review from a team as code owners March 3, 2023 05:12
@andyyang890 andyyang890 requested review from dt, rafiss, adityamaru and a team and removed request for a team March 3, 2023 05:12
Copy link
Collaborator

@stevendanna stevendanna left a 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.

@andyyang890
Copy link
Collaborator Author

It might be good to put why we are adding this field in the PR/commit message somewhere.

Done.

We also need to handle external_connections tables in backups that don't the owner_id column.

Yep, I'm planning on doing that in a followup PR where I set the column to be NOT NULL.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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?

Copy link
Collaborator Author

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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

Copy link
Collaborator Author

@andyyang890 andyyang890 left a 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: :shipit: 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.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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

Copy link
Contributor

@adityamaru adityamaru left a 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!

Copy link
Collaborator Author

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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.

@andyyang890
Copy link
Collaborator Author

TFTRs!

bors r=rafiss,adityamaru

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build failed:

@andyyang890
Copy link
Collaborator Author

bors r=rafiss,adityamaru

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

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
@andyyang890
Copy link
Collaborator Author

bors r=rafiss,adityamaru

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build succeeded:

@craig craig bot merged commit 6436b39 into cockroachdb:master Mar 10, 2023
@andyyang890 andyyang890 deleted the migrate_external_connections branch March 10, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants