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: repair corruption due to DROP SCHEMA bug #63148

Closed
ajwerner opened this issue Apr 6, 2021 · 1 comment · Fixed by #68738
Closed

sql: repair corruption due to DROP SCHEMA bug #63148

ajwerner opened this issue Apr 6, 2021 · 1 comment · Fixed by #68738
Assignees
Labels
A-schema-descriptors Relating to SQL table/db descriptor handling. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@ajwerner
Copy link
Contributor

ajwerner commented Apr 6, 2021

Describe the problem

In #63119 we uncovered a typo bug that then causes corruption when you have schemas of the same name as the database. Fortunately we can repair this type of corruption pretty trivially. We should do this as a read-time repair and then we should write a long-running migration.

@ajwerner ajwerner added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-schema-descriptors Relating to SQL table/db descriptor handling. labels Apr 6, 2021
@jlinder jlinder added the T-sql-schema-deprecated Use T-sql-foundations instead label Jun 16, 2021
@postamar
Copy link
Contributor

I could trigger this corruption by checking out v20.2.7, starting an empty cluster and running the following twice:

CREATE DATABASE foo;
USE foo;
CREATE SCHEMA bar;
DROP SCHEMA bar;

At this point the descriptor for foo is corrupted:

[email protected]:61368/foo> SELECT crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor, false)->'database'->'schemas' FROM system.descriptor WHERE id >= 52;
                ?column?
----------------------------------------
  {"foo": {"dropped": true, "id": 52}}
(1 row)

The schemas map of the database descriptor should contain a bar field but instead it contains foo. Also note that the descriptor ID is that of foo. This is caused by the bug which uses the database name and ID by mistake to populate this map.

There are clusters out there right now with corrupted database descriptors. The impact is minor enough that we haven't heard about it but this should be repaired:

  1. as a new step in RunPostDeserializationChanges.
  2. as a long-running migration that operates on all database descriptors.

The reason that (2) is not enough on its own is that corrupted database descriptors may be present in backups, which can be restored after the migration has run (it runs only once during cluster upgrade).

@craig craig bot closed this as completed in f2aded5 Aug 16, 2021
@exalate-issue-sync exalate-issue-sync bot added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed T-sql-schema-deprecated Use T-sql-foundations instead labels May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-descriptors Relating to SQL table/db descriptor handling. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
4 participants