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: fix drop database - sequence ownership bug #50744

Merged
merged 1 commit into from Jul 6, 2020

Conversation

arulajmani
Copy link
Collaborator

Previously, DROP DATABASE CASCADE would not work if the database
contained a sequence owned by a table in the database. This would
happen because of two separate reasons:

  • If the sequence was dropped before the table, the table would try to
    "double drop" the sequence as it owned it; this would result in an
    error.
  • If the table was dropped before the sequence, the sequence would try
    to remove the ownership dependency from the table descriptor, which had
    already been dropped; this would also result in an error.

This PR addresses both these issues separately. Sequences are no longer
double dropped when dropping tables. Additionally, no attempt is made
to remove the ownership dependency from the table descriptor if the
table descriptor has already been dropped.

Fixes #50712

Release note (bug fix): DROP DATABASE CASCADE now works as expected
even when the database has a sequence with an owner in it.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@arulajmani
Copy link
Collaborator Author

For some reason, the tests I added aren't moving past the DROP DATABASE CASCADE line on 3node-tennant; I've added a blocklist on the whole file for now, not sure if this is okay/why the test isn't working.

@rohany
Copy link
Contributor

rohany commented Jun 29, 2020

Note, use the cockroachdb/errors package (errors.Newf) rather than fmt.Errorf

@thoszhang
Copy link
Contributor

For some reason, the tests I added aren't moving past the DROP DATABASE CASCADE line on 3node-tennant; I've added a blocklist on the whole file for now, not sure if this is okay/why the test isn't working.

I haven't looked closely at these changes yet, but this sounds potentially bad. Would you mind digging further into what's getting stuck? I wonder if it's related to the jobs.

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

Agree that we should dig into what's going wrong with that test config.

The changes look reasonable to me though I don't have a deep understanding of the queueJob parameter. It would be great for @lucy-zhang to sign off on that change, i.e. that queueJob is now being set to false when dropping sequences during a DROP DATABASE.

Could you also add analogous tests for DROP DATABASE without CASCADE? Looks like this is not covered right now.

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

@arulajmani
Copy link
Collaborator Author

Couldn't find anything that immediately jumped out w.r.t the 3node-tenant config from the stack traces. Looks like the problem is not related to sequences -- it fails on a db containing a single, regular table as well. I've opened #50840

Previously, `DROP DATABASE CASCADE` would not work if the database
contained a sequence owned by a table in the database. This would
happen because of two separate reasons:
- If the sequence was dropped before the table, the table would try to
"double drop" the sequence as it owned it; this would result in an
error.
- If the table was dropped before the sequence, the sequence would try
to remove the ownership dependency from the table descriptor, which had
already been dropped; this would also result in an error.

This PR addresses both these issues separately. Sequences are no longer
double dropped when dropping tables. Additionally, no attempt is made
to remove the ownership dependency from the table descriptor if the
table descriptor has already been dropped.

Fixes cockroachdb#50712

Release note (bug fix): `DROP DATABASE CASCADE` now works as expected
even when the database has a sequence with an owner in it.
Copy link
Collaborator Author

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Added a test for DROP DATABASE without CASCADE as well. Should be RFAL.

Note on the queueJob -- as part of my change, I plumbed it down so that dropping a sequence owned by a table respects the queueJob of the table that owned it. It doesn't have an affect on the bug.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @lucy-zhang)

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 5 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @lucy-zhang and @solongordon)

@arulajmani
Copy link
Collaborator Author

bors r=solongordon

@craig
Copy link
Contributor

craig bot commented Jul 6, 2020

Build succeeded

@craig craig bot merged commit 0b6e118 into cockroachdb:master Jul 6, 2020
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 DATABASE CASCADE doesn't work with sequence owners
5 participants