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

release-20.2: sql: fix drop schema bug which corrupts schemas using the name of the db #63397

Merged
merged 1 commit into from
Apr 9, 2021

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Apr 9, 2021

Backport 1/2 commits from #63119.
fixes #63016

/cc @cockroachdb/release


This bug has obscure impact but is rather egregious. When dropping a schema
we would add entry with the name of it's parent database rather than itself
into the database's name map. This generally means we'll have an orphaned
entry in that map corresponding to the database itself. That's only going to
be a problem if you want to create a schema of the same name as the database.
We can make a follow-up patch to have the code ignore entries (remove at
deserialization time) that correspond to the database itself and then we
can write a long-running migration. For now we're going to fix the root
cause.

This bug was exposed by cross-descriptor validation of schemas. Prior
to this fix, you'd get an ugly error like the following:

        (XX000) internal error: schema "samename" (155): not present in parent database [152] schemas mapping
        schema_desc.go:190: in ValidateCrossReferences()
        DETAIL: stack trace:

I am worried that we're going to see support issues for this (starting in 20.2) and we'll need
a follow-up change to do some automated repair or robustness to this problem.

Fixes #62920

Release note (bug fix): Fixed a bug in user-defined schemas whereby the
dropping of any schema may prevent creation of schemas with the name of
the database and may corrupt already existing schemas of that name.

@rafiss rafiss requested a review from ajwerner April 9, 2021 18:37
@cockroach-teamcity
Copy link
Member

This change is Reviewable

This bug has obscure impact but is rather egregious. When dropping a schema
we would add entry with the name of it's parent database rather than itself
into the database's name map. This generally means we'll have an orphaned
entry in that map corresponding to the database itself. That's only going to
be a problem if you want to create a schema of the same name as the database.
We can make a follow-up patch to have the code ignore entries (remove at
deserialization time) that correspond to the database itself and then we
can write a long-running migration. For now we're going to fix the root
cause.

This bug was exposed by cross-descriptor validation of schemas. Prior
to this fix, you'd get an ugly error like the following:

```
        (XX000) internal error: schema "samename" (155): not present in parent database [152] schemas mapping
        schema_desc.go:190: in ValidateCrossReferences()
        DETAIL: stack trace:
```

I am worried that we're going to see support issues for this and we'll need
a follow-up change to do some automated repair or robustness to this problem.

Release note (bug fix): Fixed a bug in user-defined schemas whereby the
dropping of any schema may prevent creation of schemas with the name of
the database and may corrupt already existing schemas of that name.
@rafiss rafiss force-pushed the backport20.2-63119 branch from 1753a68 to 998f4db Compare April 9, 2021 19:45
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.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@rafiss rafiss merged commit 31d3f45 into cockroachdb:release-20.2 Apr 9, 2021
@rafiss rafiss deleted the backport20.2-63119 branch April 9, 2021 21:17
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.

3 participants