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: delete descriptor when function is dropped #96385

Conversation

chengxiong-ruan
Copy link
Contributor

Fixes: #95364

sql: delete descriptor when function is dropped

Previously, in legacy schema changer, descriptor stayed as
a orphan recrod in system.descriptor when a function is dropped.
While this is not a big issue, we should keep data clean.
This PR adds schema change job logic to handle the deletions.

upgrades: add upgrade to delete dropped function descriptors

This commit adds an upgrade to delete orphan descriptors of
functions dropped through legacy schema changer before 23.1.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@chengxiong-ruan chengxiong-ruan force-pushed the drop-function-descriptor-in-legacy-schema-changer branch 5 times, most recently from 8fcf122 to bcd525d Compare February 2, 2023 05:07
@chengxiong-ruan chengxiong-ruan marked this pull request as ready for review February 2, 2023 14:36
@chengxiong-ruan chengxiong-ruan requested a review from a team as a code owner February 2, 2023 14:36
@chengxiong-ruan chengxiong-ruan requested a review from a team February 2, 2023 14:36
@chengxiong-ruan chengxiong-ruan requested a review from a team as a code owner February 2, 2023 14:36
@chengxiong-ruan chengxiong-ruan requested review from michae2 and removed request for michae2 February 2, 2023 14:36
@chengxiong-ruan
Copy link
Contributor Author

chengxiong-ruan commented Feb 2, 2023

hmm.. looks like the TestDeleteDescriptorsOfDroppedFunctions test is flaky for some reason.
(edit: looks like the fix is to use txn.Exec instead of txn.Query friends.)

@chengxiong-ruan chengxiong-ruan force-pushed the drop-function-descriptor-in-legacy-schema-changer branch 2 times, most recently from 3694c5b to 0bd725a Compare February 2, 2023 14:54
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 8 of 8 files at r1, 9 of 9 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @chengxiong-ruan)


pkg/jobs/jobspb/jobs.proto line 808 at r1 (raw file):

    (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb.ID"
  ];
  repeated uint32 dropped_functions = 12 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb.ID"];

Nit: Maybe a comment here


pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 66 at r2 (raw file):

		const batchSize = 50

		for curID := 1; curID <= maxID; curID += batchSize {

What does the batching buy is here or what are we trying to avoid by doing it?

@chengxiong-ruan
Copy link
Contributor Author

pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 66 at r2 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

What does the batching buy is here or what are we trying to avoid by doing it?

I think this is just in case there're too many descriptors which is rare though. But I think it's just nicer to do small batch to avoid one heavy operation.

@chengxiong-ruan
Copy link
Contributor Author

pkg/jobs/jobspb/jobs.proto line 808 at r1 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

Nit: Maybe a comment here

will do

Previously, in legacy schema changer, descriptor stayed as
a orphan recrod in system.descriptor when a function is dropped.
While this is not a big issue, we should keep data clean.
This PR adds schema change job logic to handle the deletions.

Fixes: cockroachdb#95364

Release note: None
This commit adds an upgrade to delete orphan descriptors of
functions dropped through legacy schema changer before 23.1.

Release note: None
@chengxiong-ruan chengxiong-ruan force-pushed the drop-function-descriptor-in-legacy-schema-changer branch from 0bd725a to 0a8e800 Compare February 2, 2023 15:29
@chengxiong-ruan
Copy link
Contributor Author

pkg/jobs/jobspb/jobs.proto line 808 at r1 (raw file):

Previously, chengxiong-ruan (Chengxiong Ruan) wrote…

will do

done

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.

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


pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 66 at r2 (raw file):

Previously, chengxiong-ruan (Chengxiong Ruan) wrote…

I think this is just in case there're too many descriptors which is rare though. But I think it's just nicer to do small batch to avoid one heavy operation.

I think implicitly each delete will get its own KV batch, so this might not be necessary. Thinking the SQL layer would handle the select side nicely, but I'm okay with it.

@chengxiong-ruan
Copy link
Contributor Author

TFTR!
bors r+

@craig
Copy link
Contributor

craig bot commented Feb 2, 2023

This PR was included in a batch that was canceled, it will be automatically retried

@craig
Copy link
Contributor

craig bot commented Feb 2, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 2, 2023

Build succeeded:

@craig craig bot merged commit fbc9321 into cockroachdb:master Feb 2, 2023
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.

sql: DROP FUNCTION does not delete function descriptor
3 participants