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: block concurrent renames with declarative schema changes #128683

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

fqazi
Copy link
Collaborator

@fqazi fqazi commented Aug 9, 2024

Previously, we allowed the legacy and declarative schema change jobs to run concurrently with declarative schema change jobs, for example renames of objects. If a drop operation was executed next to a legacy schema change job, it was possible for the legacy code to delete the descriptor before the declarative schema changer. To address this, we are going to safe guard rename operations, which currently do not check for declarative schema changer jobs.

Fixes: #128268

Release note: None

@fqazi fqazi requested a review from a team as a code owner August 9, 2024 16:02
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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 find!

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


pkg/sql/rename_table.go line 121 at r1 (raw file):

	// Exit early with an error if the table is undergoing a declarative schema
	// change.
	if catalog.HasConcurrentDeclarativeSchemaChange(n.tableDesc) {

ah interesting. i thought we already automatically blocked all legacy schema changes if HasConcurrentDeclarativeSchemaChange is true.

is there a way to make that happen, rather than needing to remember to add this in each legacy schema change op?


pkg/sql/schemachanger/schemachanger_test.go line 630 at r1 (raw file):

		decl := rand.Intn(2) == 0
		if !decl {
			_, err := sqlDB.Exec("SET use_declarative_schema_changer='off';")

technically sqlDB is a connection pool, so if we want this to be reliable, we would need to change the test to operate at the connection level. or maybe we can just set sqlDB.SetMaxOpenConns(1) at the beginning of the test.

Previously, we allowed the legacy and declarative schema change jobs to
run concurrently with declarative schema change jobs, for example
renames of objects. If a drop operation was executed next to a legacy
schema change job, it was possible for the legacy code to delete the
descriptor before the declarative schema changer. To address this, we
are going to safe guard rename operations, which currently do not check
for declarative schema changer jobs.

Fixes: cockroachdb#128268

Release note: None
@fqazi fqazi force-pushed the concurrentRenameAndDropFix branch from 912d1dd to ae0b1f8 Compare August 9, 2024 22:02
Copy link
Collaborator Author

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


pkg/sql/schemachanger/schemachanger_test.go line 630 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

technically sqlDB is a connection pool, so if we want this to be reliable, we would need to change the test to operate at the connection level. or maybe we can just set sqlDB.SetMaxOpenConns(1) at the beginning of the test.

Done.

I went with a middle ground approach where I opened one pool per worker with a connection limit.


pkg/sql/rename_table.go line 121 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

ah interesting. i thought we already automatically blocked all legacy schema changes if HasConcurrentDeclarativeSchemaChange is true.

is there a way to make that happen, rather than needing to remember to add this in each legacy schema change op?

Done.

I pushed this into the lower layers of when we create the jobs, which should impact everything, except for GRANT statements.

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


pkg/sql/table.go line 278 at r2 (raw file):

			tableDesc.Name)
	}
	// Exit early with an error if the table is undergoing a declarative schema

would we need the same check for schema changes on types or functions?

Copy link
Collaborator Author

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


pkg/sql/table.go line 278 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

would we need the same check for schema changes on types or functions?

Good point for types this PR already has coverage via writeTypeSchemaChange. For functions only dropping involves jobs and thats covered by dropFunctionImpl.

@fqazi
Copy link
Collaborator Author

fqazi commented Aug 10, 2024

@rafiss TFTR!

bors r+

@craig craig bot merged commit 27468a2 into cockroachdb:master Aug 10, 2024
21 of 23 checks passed
@fqazi
Copy link
Collaborator Author

fqazi commented Aug 12, 2024

blathers backport 23.2

Copy link

blathers-crl bot commented Aug 12, 2024

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from ae0b1f8 to blathers/backport-release-23.2-128683: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.2 failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@fqazi
Copy link
Collaborator Author

fqazi commented Aug 12, 2024

blathers backport 24.1

Copy link

blathers-crl bot commented Aug 12, 2024

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #128268: branch-release-24.1.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@fqazi
Copy link
Collaborator Author

fqazi commented Aug 12, 2024

blathers backport 24.2

Copy link

blathers-crl bot commented Aug 12, 2024

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #128268: branch-release-24.2.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

fqazi added a commit to fqazi/cockroach that referenced this pull request Aug 13, 2024
Previously, this test would flake if descriptors were being dropped
concurrently while dropping tables. This was because cockroachdb#128683 added
support for dropping schemas. To address this, this patch adds the
descriptor being dropped as a valid error for CREATE INDEX.
Additionally, this patch fixes the rename logic to avoid collisions by
sequentially picking object names.

Fixes: cockroachdb#128731, cockroachdb#128797

Release note: None
craig bot pushed a commit that referenced this pull request Aug 13, 2024
128929: sql/schemachanger: fix flake inside TestConcurrentSchemaChanges r=fqazi a=fqazi

Previously, this test would flake if descriptors were being dropped concurrently while dropping tables. This was because #128683 added support for dropping schemas. To address this, this patch adds the descriptor being dropped as a valid error for CREATE INDEX. Additionally, this patch fixes the rename logic to avoid collisions by sequentially picking object names.

Fixes: #128731
fixes #128797

Release note: None

Co-authored-by: Faizan Qazi <[email protected]>
fqazi added a commit that referenced this pull request Aug 14, 2024
Previously, this test would flake if descriptors were being dropped
concurrently while dropping tables. This was because #128683 added
support for dropping schemas. To address this, this patch adds the
descriptor being dropped as a valid error for CREATE INDEX.
Additionally, this patch fixes the rename logic to avoid collisions by
sequentially picking object names.

Fixes: #128731, #128797

Release note: None
fqazi added a commit that referenced this pull request Aug 14, 2024
Previously, this test would flake if descriptors were being dropped
concurrently while dropping tables. This was because #128683 added
support for dropping schemas. To address this, this patch adds the
descriptor being dropped as a valid error for CREATE INDEX.
Additionally, this patch fixes the rename logic to avoid collisions by
sequentially picking object names.

Fixes: #128731, #128797

Release note: None
fqazi added a commit to fqazi/cockroach that referenced this pull request Aug 14, 2024
Previously, this test would flake if descriptors were being dropped
concurrently while dropping tables. This was because cockroachdb#128683 added
support for dropping schemas. To address this, this patch adds the
descriptor being dropped as a valid error for CREATE INDEX.
Additionally, this patch fixes the rename logic to avoid collisions by
sequentially picking object names.

Fixes: cockroachdb#128731, cockroachdb#128797

Release note: None
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.

roachtest: schemachange/random-load failed
3 participants