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: creating new tables using crdb_internal.unsafe_upsert_descriptor should affect ID generation #68230

Closed
ajwerner opened this issue Jul 29, 2021 · 1 comment · Fixed by #68662
Assignees
Labels
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

Describe the problem

If you use a tool like cockroach debug doctor recreate to add descriptors, it will not change the ID generation counter. That means that subsequent descriptor creation may fail due to a conflict with existing descriptors.

@ajwerner ajwerner added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jul 29, 2021
@blathers-crl blathers-crl bot added the T-sql-schema-deprecated Use T-sql-foundations instead label Jul 29, 2021
@postamar
Copy link
Contributor

postamar commented Aug 3, 2021

This should only fast-forward the counter if the force flag is set.

craig bot pushed a commit that referenced this issue Aug 13, 2021
68662: sql: unsafe_upsert_descriptor to bump descriptor ID sequence r=postamar a=postamar

Previously, it was possible to use this descriptor repair function to
insert a new descriptor with an ID greater than any descriptor in the
cluster and would not update the descriptor ID sequence value.
Subsequent CREATE statements would therefore write descriptors
with IDs smaller or equal to the descriptor inserted previously. In the
equal case, this corrupts the schema.

This commit adds a test that checks that the ID is less than the value
stored in the descriptor ID sequence. When that is not the case:
- an error is returned when the `force` flag is not set,
- otherwise, the sequence value is incremented appropriately.

Fixes #68230.

Release note: None

Co-authored-by: Marius Posta <[email protected]>
@craig craig bot closed this as completed in 0323719 Aug 13, 2021
ajwerner pushed a commit to ajwerner/cockroach that referenced this issue Oct 19, 2021
Previously, it was possible to use this descriptor repair function to
insert a new descriptor with an ID greater than any descriptor in the
cluster and would not update the descriptor ID sequence value.
Subsequent CREATE statements would therefore write descriptors
with IDs smaller or equal to the descriptor inserted previously. In the
equal case, this corrupts the schema.

This commit adds a test that checks that the ID is less than the value
stored in the descriptor ID sequence. When that is not the case:
- an error is returned when the `force` flag is not set,
- otherwise, the sequence value is incremented appropriately.

Fixes cockroachdb#68230.

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

Successfully merging a pull request may close this issue.

2 participants