sql/catalog: unify the descs.Collection resolution-by-ID API#57343
sql/catalog: unify the descs.Collection resolution-by-ID API#57343craig[bot] merged 2 commits intocockroachdb:masterfrom
Conversation
1f40abf to
697a450
Compare
a2e7277 to
54d4893
Compare
d036c0c to
b260531
Compare
|
I think as a first pass this PR does most of what we want, API-wise. There are still some loose ends: There are a few deprecated methods left on the I'm open to renaming the old |
ajwerner
left a comment
There was a problem hiding this comment.
Sorry this took so long. Once things start getting hidden in the reviewable UI I lose them.
Reviewed 1 of 1 files at r1.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @ajwerner)
pkg/sql/catalog/descs/collection.go, line 899 at r1 (raw file):
// TODO (lucy): Consider how to avoid having to generate user-facing errors // here. At the very least, this is inconsistent with the name resolution // methods, which just return internal errors from filterDescriptorState.
Can you help me better understand what this would take?
7c4e97c to
32c59a6
Compare
This commit unifies the implementations of all the `descs.Collection` resolution-by-ID methods, and increases their consistency in respecting lookup flags for non-public descriptors. It also adds methods with standardized names and signatures: each descriptor type now has mutable and immutable variants for resolution by ID. All the pre-existing methods still exist, but are marked for deprecation. Release note: None
This commit performs a few trivial replacements of `descs.Collection` methods with their new names: - `GetTableVersionByID` -> `GetImmutableTableByID` - `GetTypeVersionByID` -> `GetImmutableTypeByID` - `ResolveSchemaByID` -> `GetImmutableSchemaByID` (which also takes an explicit flag) - `GetDatabaseVersionByID` -> `GetImmutableDatabaseByID` All the `Required` values have also been removed from the flags passed into these methods, since they unconditionally return an error when the descriptor does not exist. Release note: None
32c59a6 to
ee72e00
Compare
thoszhang
left a comment
There was a problem hiding this comment.
Also removed the explicit Required flags from the ByID method calls, since we ignore that flag.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner)
pkg/sql/catalog/descs/collection.go, line 899 at r1 (raw file):
Previously, ajwerner wrote…
// TODO (lucy): Consider how to avoid having to generate user-facing errors // here. At the very least, this is inconsistent with the name resolution // methods, which just return internal errors from filterDescriptorState.Can you help me better understand what this would take?
I deleted this comment, since I'm not convinced that this is a problem, or at least not the most important problem.
I just fixed a bug in this PR that caused TestInvalidOwnedDescriptorsAreDroppable to fail, due to us checking specifically for catalog.ErrDescriptorNotFound (which we used to directly return out of the physical accessor, or something, but now gets discarded in favor of the various user-facing errors in sqlerrors). I fixed it by having us check for pgcode.UndefinedTable instead, but I don't know that this is a good idea.
The point is, it seems potentially useful to have a reliable sentinel error indicating that no such descriptor exists with the given name/ID. We didn't really do this starting with the name resolution APIs, so I don't want to do it in this PR, but I opened #59027 with some thoughts.
ajwerner
left a comment
There was a problem hiding this comment.
cc @postamar - let's get you tagged on reviews like this.
Reviewed 1 of 3 files at r2.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner)
ajwerner
left a comment
There was a problem hiding this comment.
Reviewed 2 of 3 files at r2, 14 of 14 files at r3.
Reviewable status:complete! 1 of 0 LGTMs obtained
pkg/sql/catalog/descs/collection.go, line 899 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
I deleted this comment, since I'm not convinced that this is a problem, or at least not the most important problem.
I just fixed a bug in this PR that caused
TestInvalidOwnedDescriptorsAreDroppableto fail, due to us checking specifically forcatalog.ErrDescriptorNotFound(which we used to directly return out of the physical accessor, or something, but now gets discarded in favor of the various user-facing errors insqlerrors). I fixed it by having us check forpgcode.UndefinedTableinstead, but I don't know that this is a good idea.The point is, it seems potentially useful to have a reliable sentinel error indicating that no such descriptor exists with the given name/ID. We didn't really do this starting with the name resolution APIs, so I don't want to do it in this PR, but I opened #59027 with some thoughts.
I think the answer here should be to leverage errors.Mark to make sure that the meaningful, identifiable error object propagates. Using the pgcodes doesn't make me happy.
thoszhang
left a comment
There was a problem hiding this comment.
TFTR!
bors r+
Reviewable status:
complete! 1 of 0 LGTMs obtained
pkg/sql/catalog/descs/collection.go, line 899 at r1 (raw file):
Previously, ajwerner wrote…
I think the answer here should be to leverage
errors.Markto make sure that the meaningful, identifiable error object propagates. Using the pgcodes doesn't make me happy.
FWIW, we already check for that pgcode here, where the logic is basically the same:
cockroach/pkg/sql/drop_sequence.go
Lines 170 to 174 in 4fcc73a
So I just copied it. But I don't like it either.
We should try to fix the errors soon, though I fear that it won't be that easy since the callers probably don't actually handle errors (or what they indicate) in a very principled way and we just rely on a lot of accidental behavior. Maybe we can do that after finally mocking out the physical access dependencies like we've been meaning to, though that in itself is not necessarily going to help us do the right things.
|
Build succeeded: |
See commits for details. This PR mostly standardizes the
ByIDmethods ondescs.Collectionfor the specific descriptor types.Closes #57539.