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: add user_id column to system.web_sessions table #96896

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

andyyang890
Copy link
Collaborator

@andyyang890 andyyang890 commented Feb 9, 2023

This patch adds a new user_id column to the system.web_sessions table,
which corresponds to the existing username column. Migrations are
also added to alter and backfill the table in older clusters.

Part of #87079

Release note: None

@blathers-crl
Copy link

blathers-crl bot commented Feb 9, 2023

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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andyyang890 andyyang890 force-pushed the migrate_web_sessions branch 11 times, most recently from 79b3032 to 49040c2 Compare February 15, 2023 05:42
@andyyang890 andyyang890 marked this pull request as ready for review February 15, 2023 05:46
@andyyang890 andyyang890 requested a review from a team February 15, 2023 05:46
@andyyang890 andyyang890 requested review from a team as code owners February 15, 2023 05:46
@andyyang890 andyyang890 requested a review from a team February 15, 2023 05:46
@andyyang890 andyyang890 requested a review from a team as a code owner February 15, 2023 05:46
@andyyang890 andyyang890 requested a review from rafiss February 15, 2023 05:47
@andyyang890 andyyang890 force-pushed the migrate_web_sessions branch 2 times, most recently from db5a381 to 7a9962e Compare February 15, 2023 20:24
@andyyang890 andyyang890 requested a review from a team as a code owner February 15, 2023 20:24
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.

nice, looks good overall! just had a few nits

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andyyang890)


pkg/cli/democluster/session_persistence.go line 211 at r1 (raw file):

		}

		// TODO(yang): Update this to insert new user_id column.

can we do this right now?


pkg/server/authentication.go line 493 at r1 (raw file):

	ctx context.Context, userName username.SQLUsername,
) (int64, []byte, error) {
	privilegesTableHasUserIDCol := s.sqlServer.execCfg.Settings.Version.IsActive(ctx,

should this be using WebSessionsTableHasUserIDColumn?


pkg/upgrade/upgrades/web_sessions_table_user_id_migration_test.go line 100 at r1 (raw file):

		}
		txRunner.Exec(t, fmt.Sprintf("CREATE USER testuser%d", i))
		txRunner.Exec(t, fmt.Sprintf(`

nit: can you add a comment saying that this INSERT is meant to mimic what the real auth code does?

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 @rafiss)


pkg/cli/democluster/session_persistence.go line 211 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

can we do this right now?

Done.


pkg/server/authentication.go line 493 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

should this be using WebSessionsTableHasUserIDColumn?

Oops, yeah. Good catch!


pkg/upgrade/upgrades/web_sessions_table_user_id_migration_test.go line 100 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

nit: can you add a comment saying that this INSERT is meant to mimic what the real auth code does?

Done.

This patch adds a new `user_id` column to the `system.web_sessions` table,
which corresponds to the existing `username` column. Migrations are
also added to alter and backfill the table in older clusters.

Release note: None
@andyyang890
Copy link
Collaborator Author

TFTR!

bors r=rafiss

@andyyang890
Copy link
Collaborator Author

seems like bors got stuck

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Feb 16, 2023

Build failed:

@andyyang890
Copy link
Collaborator Author

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Feb 16, 2023

Build succeeded:

@craig craig bot merged commit 5f85453 into cockroachdb:master Feb 16, 2023
@andyyang890 andyyang890 deleted the migrate_web_sessions branch February 16, 2023 08:21
craig bot pushed a commit that referenced this pull request Feb 28, 2023
97226: Add Inject Retry Errors On Commit variable r=rafiss a=lyang24

fixes #86370

Release note (sql change): The session variable
inject_retry_errors_on_commit_enabled has been added. When this is true, any
COMMIT statement will return a transaction retry
error if it is run inside of an explicit transaction. If the client
retries the transaction using the special cockroach_restart SAVEPOINT,
then after the 3rd error, the transaction will proceed as normal.
Otherwise, the errors will continue until inject_retry_errors_on_commit_enabled
is set to false. The purpose of this setting is to allow developers to
test their transaction retry logic.

97490: cli: use placeholder in SQL query r=rafiss a=knz

Amends #96896.

Release note: None
Epic: CRDB-19134

Co-authored-by: Eric.Yang <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
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.

3 participants