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/catalog/resolver: return UndefinedDatabase in more cases #71440

Conversation

ajwerner
Copy link
Contributor

@ajwerner ajwerner commented Oct 12, 2021

In 21.1 and prior, we returned UndefinedDatabase (3D000) in cases where a
table name was used to signify a virtual table and the database did not
exist. It turns out that this behavior was important. It existed for
arbitrary implementation reasons. When that code was refactored
earlier in the 21.2 release, the behavior was removed. Now we restore
that behavior and make the behavior more consistent. When we know that
we're trying to resolve a relation in the current database and we know
that the current database does not exist, we now return the
UndefinedDatabase error.

Fixes #71495

Release note (bug fix): In prior betas of 21.2, some error codes returned when
looking for a descriptor in a non-existent database were changed from
UndefinedDatabase (3D000) to UndefinedObject (42704). The behavior has been
reverted and more generally name resolution when the current database is
undefined will return UndefinedDatabase.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

lgtm with a nit!

if found, prefix, result, err = r.LookupObject(
ctx, lookupFlags, curDb, u.Schema(), u.Object(),
); found || err != nil || isVirtualSchema {
if !found && err == nil && prefix.Database == nil { // && isVirtualSchema
Copy link
Collaborator

Choose a reason for hiding this comment

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

nite: some commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh it was intentional, I'm noting that that condition is implied. I'll make that clearer.

In 21.1 and prior, we returned UndefinedDatabase (3D000) in cases where a
table name was used to signify a virtual table and the database did not
exist. It turns out that this behavior was important. It existed for
arbitrary implementation reasons. When that code was refactored
earlier in the 21.2 release, the behavior was removed. Now we restore
that behavior and make the behavior more consistent. When we know that
we're trying to resolve a relation in the current database and we know
that the current database does not exist, we now return the
UndefinedDatabase error.

Release note (bug fix): In prior betas of 21.2, some error codes returned when
looking for a descriptor in a non-existent database were changed from
UndefinedDatabase (3D000) to UndefinedObject (42704). The behavior has been
reverted and more generally name resolution when the current database is
undefined will return UndefinedDatabase.
@ajwerner ajwerner requested a review from a team October 13, 2021 03:03
@ajwerner ajwerner force-pushed the ajwerner/fix-some-error-returns-for-missing-database branch from c70ea9a to a7c58d6 Compare October 13, 2021 03:03
@ajwerner ajwerner marked this pull request as ready for review October 13, 2021 03:04
@ajwerner
Copy link
Contributor Author

@fqazi can I have a review from you, you touched this area.

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 7 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)

@ajwerner
Copy link
Contributor Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 14, 2021

Build failed:

@ajwerner
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 14, 2021

Build succeeded:

@storjBuildBot
Copy link

Change https://review.dev.storj.io/c/storj/gateway-mt/+/6498 mentions this issue.

storjBuildBot pushed a commit to storj/edge that referenced this pull request Dec 10, 2021
This change partially reverts d176707
and fixes the actual underlying problem of the failing test. The reason
we were failing with CRDB v21.2.x is that it now returns the 3D000 error
code instead of 42P01 when the database does not exist (which happens
when we run AOST queries right after migration). Previously, we only
checked 42P01 before we errored or fell back to a query without AOST.

The d176707-fix was incorrect because we have a fallback to a non-AOST
query implemented.

Reference: cockroachdb/cockroach#71440

Change-Id: Ic4b83d40579c983c8f1f5b21f3afd833d7e6057f
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.

Able to Connect to Non-Existent Databases
5 participants