Skip to content

descs: add ByIDGetter and ByNameGetter interfaces#93813

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
postamar:descs-interfaces
Jan 2, 2023
Merged

descs: add ByIDGetter and ByNameGetter interfaces#93813
craig[bot] merged 1 commit intocockroachdb:masterfrom
postamar:descs-interfaces

Conversation

@postamar
Copy link
Copy Markdown

@postamar postamar commented Dec 16, 2022

These pave the way for deprecating the existing Get*ByID and Get*ByName Collection methods.

Informs #87753.

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@postamar postamar force-pushed the descs-interfaces branch 4 times, most recently from b15a9cd to 3afba2a Compare December 19, 2022 17:59
@postamar
Copy link
Copy Markdown
Author

This is ready for a round of review. This doesn't functionally change much, the purpose of this PR is to make it possible to sort the frightful mess that the tree.CommonLookupFlags and tree.ObjectLookupFlags have become, which in turn should lead to #87753.

@postamar postamar marked this pull request as ready for review December 19, 2022 19:00
@postamar postamar requested a review from a team as a code owner December 19, 2022 19:00
@postamar postamar requested review from a team and rhu713 and removed request for a team and rhu713 December 19, 2022 19:00
Copy link
Copy Markdown
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.

I love the direction. It makes a lot of sense to me. We'll need to be careful to not trash performance when we adopt this. Leaving my high-level feedback now and will come back to look at details.

Reviewed 13 of 34 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @postamar)


pkg/sql/catalog/descs/getters.go line 33 at r1 (raw file):

// ByIDGetter looks up immutable descriptors by ID.
type ByIDGetter interface {

I'm modestly worries that this interface approach is going to end up hurting from a performance perspective, at least, eventually. I worry that we're going to end up allocating frequently. I do get the value in doing this. I wonder if ultimately the approach we'll want to take is to return the concrete struct which implements this to the callers and have all the various forms actually share the same underlying pointer. Consider:

type ByIDGetter getterBase

You can then implement ByIDGetter the interface and have all the fields of a getterBase without exposing any of its methods or what not. Then, to convert between the various implementations, you can cast the values without ever incurring the need to allocate the object on the heap.

Keep an eye on the various benchmarks we have related to resolving descriptors as you make progress around these parts. This code ends up being rather performance critica.


pkg/sql/catalog/descs/getters.go line 578 at r1 (raw file):

// TODO(postamar): clean up inconsistencies, enforce sane defaults.
type getterFlags struct {
	context      contextFlags

the code might read more cleanly if you embed the contextFlags

Copy link
Copy Markdown
Contributor

@Xiang-Gu Xiang-Gu left a comment

Choose a reason for hiding this comment

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

I saw that you categorize all the flags into: context-related, layer-related, and desc-specific. This is very great! My question is that it seems you also introduced withoutStorage and withoutCommittedAdding flags bc they don't exist in the present tree.CommonLookupFlags. Why do you want to have these two new flags?

@postamar
Copy link
Copy Markdown
Author

I wonder if ultimately the approach we'll want to take is to return the concrete struct which implements this to the callers and have all the various forms actually share the same underlying pointer.

Sounds reasonable. When I started sketching out these interfaces I didn't have a clear picture in mind as to where they'd lead to. Now that that's clearer I don't feel strongly that they should be interfaces at all by any means. It's not like there'll be alternative implementations anyway.

Why do you want to have these two new flags?

They were, in fact, in tree.CommonLookupFlags, so they're not new. They're flags that should be internal to the Collection, for sure. This is a big reason why I believe the flags should be cleaned up.

@postamar postamar force-pushed the descs-interfaces branch 2 times, most recently from 61bd1c3 to a3293f1 Compare December 20, 2022 21:08
@postamar
Copy link
Copy Markdown
Author

Thanks for the suggestion to get rid of the interfaces, it's much better without them. I ran some benchmarks and the impact is now negligible, and I attribute it to the txn interface which is a placeholder for what's to come in #93218 .

Assuming the CI isn't sad this should be ready for a thorough review.

Copy link
Copy Markdown
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.

This pleases me very much. In an ideal future world, we'll remove the Txn arg from the *descs.Collection functions and then can encapsulate that thing as an interface (it's always a pointer on the heap anyway). I think if we did that, it'd go a very long way towards making the catalog access more composable. What is currently the getters would be the layer to import and not descs.

return objMeta != nil, prefix, objMeta, err
}

// GetObjectByName returns an object descriptor by name.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this comment should say something more about the structure of the various arguments. What is allowed to be empty and what is not?

These pave the way for deprecating the existing Get*ByID and Get*ByName
Collection methods.

Informs cockroachdb#87753.

Release note: None
@postamar
Copy link
Copy Markdown
Author

postamar commented Jan 2, 2023

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 2, 2023

Build succeeded!

And happy new year! 🎉

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.

4 participants