-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
There was a problem hiding this 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: 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
912d1dd
to
ae0b1f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 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.
@rafiss TFTR! bors r+ |
blathers backport 23.2 |
Encountered an error creating backports. Some common things that can go wrong:
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. |
blathers backport 24.1 |
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. |
blathers backport 24.2 |
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. |
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
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]>
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
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
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
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