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/upgrades: add upgrade logic so that sequences are referenced by ID #81583

Merged

Conversation

Xiang-Gu
Copy link
Contributor

A few releases ago, sequences are referenced by name but we have
changed it to be by ID (to enable things like RENAME AS). However,
the necessary migration work, supposedly tracked in #61017, somehow
fell out of the team's radar unfortunately. This PR filled this gap by
implementing the migration logic, among many from v22.1 to v22.2, that
iterates over all table (or view) descriptor and upgrade their sequence
reference from by name to by ID, if not already.

fixed: #61017

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@Xiang-Gu Xiang-Gu force-pushed the migrate_sequence_to_be_referenced_by_id branch 2 times, most recently from aa3c112 to 007e92e Compare May 23, 2022 20:01
@Xiang-Gu Xiang-Gu marked this pull request as ready for review May 23, 2022 20:04
@Xiang-Gu Xiang-Gu requested a review from a team May 23, 2022 20:04
@Xiang-Gu Xiang-Gu force-pushed the migrate_sequence_to_be_referenced_by_id branch from 007e92e to 798e769 Compare May 23, 2022 20:07
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

nice work on this, so sorry about the very slow review. Just nits

Reviewed 4 of 12 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @Xiang-Gu)


pkg/upgrade/tenant_upgrade.go line 47 at r1 (raw file):

	TestingKnobs               *TestingKnobs
	InternalPlannerConstructor func(txn *kv.Txn, descriptors *descs.Collection, currDb string) (interface{}, func())

can you narrow this to resolver.SchemaResolver for the return type?


pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go line 151 at r1 (raw file):

	// Construct an internal planner
	planner, cleanup := d.InternalPlannerConstructor(txn, descriptors, dbDesc.GetName())

@chengxiong-ruan almost got the schemaResolver fully extracted from the planner. What do you think about finishing that work by extracting sql.schemaResolver into a new package and then constructing that thing directly? I think it'll be a good deal cleaner and will make me happy. Feel free to do it in follow-up.

Code quote:

,

@Xiang-Gu Xiang-Gu force-pushed the migrate_sequence_to_be_referenced_by_id branch from 798e769 to 82c14b3 Compare June 6, 2022 19:57
Copy link
Contributor Author

@Xiang-Gu Xiang-Gu left a comment

Choose a reason for hiding this comment

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

Thanks. I address the comments to change the return types. RFAL again.

I'm interested in finishing up @chengxiong-ruan's refactoring in a follow-up (also an exercise to learn more about the codebase) PR. I left a few questions in the comment below.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @chengxiong-ruan)


pkg/upgrade/tenant_upgrade.go line 47 at r1 (raw file):

Previously, ajwerner wrote…

can you narrow this to resolver.SchemaResolver for the return type?

done


pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go line 151 at r1 (raw file):

Previously, ajwerner wrote…

@chengxiong-ruan almost got the schemaResolver fully extracted from the planner. What do you think about finishing that work by extracting sql.schemaResolver into a new package and then constructing that thing directly? I think it'll be a good deal cleaner and will make me happy. Feel free to do it in follow-up.

I'd love to do that in a follow-up! Before that, can you explain a bit more about what needs to be done to finish that work?

I read @chengxiong-ruan's pr for his refactoring effort and learned that, previously, planner implemented the resolver.SchemaResolver interface, and Chengxiong moved them into a struct sql.schemaResolver and let this struct implement the resolver.SchemaResolver interface. He also left a TODO there saying "refactor this out into a separate package", which resonates with what you said. I don't, however, understand what's the "end state" we'd like to see to finish this work and what's required.

More concretely,

  1. Where should this "separate" package be? Should it be the "resolver" package or somewhere else?

  2. What do you mean by "constructing that thing directly"?

  3. What is the "end-state" we'd like to see to finish this refactoring effort?

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 12 files at r1, 5 of 5 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @chengxiong-ruan)

Copy link
Contributor

@chengxiong-ruan chengxiong-ruan 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 @ajwerner)


pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go line 151 at r1 (raw file):

  1. Where should this "separate" package be? Should it be the "resolver" package or somewhere else?

It need to be somewhere else, like a schemaresolver package under sql package.

  1. What do you mean by "constructing that thing directly"?

It means you construct the SchemaResolver directly instead of the big mighty planner.

  1. What is the "end-state" we'd like to see to finish this refactoring effort?

The end state is that schemaResolver is not embedded within planner, instead, it's separate child field it depends on. So you see that planner itself won't be a SchemaResolver anymore. It'd be a happy lighter object.

@Xiang-Gu Xiang-Gu force-pushed the migrate_sequence_to_be_referenced_by_id branch from 82c14b3 to dc96653 Compare June 13, 2022 13:44
A few release ago, sequences are referenced by name but we have
change it to be by ID (to enable things like `RENAME AS`). However,
the necessary migration work, supposedly tracked in cockroachdb#61017, somehow
fell out of the team's radar unfortunately. This PR filled this gap by
implementing the migration logic, among many from v22.1 to v22.2, that
iterates over all table (or view) descriptor and upgrade their sequence
reference from by name to by ID, if not already.

Release note: None
@Xiang-Gu Xiang-Gu force-pushed the migrate_sequence_to_be_referenced_by_id branch from dc96653 to 796fa2c Compare June 13, 2022 14:03
@Xiang-Gu
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 13, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jun 13, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jun 13, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jun 13, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jun 13, 2022

Build succeeded:

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.

Migrate old sequences to be referenced by ID
5 participants