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/schema: re-organize the UnleasableSystemDescriptors set #74353

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions pkg/sql/catalog/descs/leased_descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,8 @@ func (ld *leasedDescriptors) getByName(
return cached.(lease.LeasedDescriptor).Underlying(), false, nil
}

for _, d := range systemschema.UnleasableSystemDescriptors {
if parentID == d.GetParentID() &&
parentSchemaID == d.GetParentSchemaID() &&
name == d.GetName() {
return nil, true, nil
}
if systemschema.IsUnleasableSystemDescriptorByName(parentID, parentSchemaID, name) {
return nil, true, nil
}

readTimestamp := txn.ReadTimestamp()
Expand All @@ -128,7 +124,7 @@ func (ld *leasedDescriptors) getByID(
return cached.(lease.LeasedDescriptor).Underlying(), false, nil
}

if _, isUnleasable := systemschema.UnleasableSystemDescriptors[id]; isUnleasable {
if systemschema.IsUnleasableSystemDescriptorByID(id) {
return nil, true, nil
}

Expand Down
63 changes: 53 additions & 10 deletions pkg/sql/catalog/systemschema/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2291,23 +2291,66 @@ var (
}}
},
)
)

// UnleasableSystemDescriptors contains the system descriptors which cannot
// be leased. This includes the lease table itself, among others.
UnleasableSystemDescriptors = func(s []catalog.Descriptor) map[descpb.ID]catalog.Descriptor {
m := make(map[descpb.ID]catalog.Descriptor, len(s))
for _, d := range s {
m[d.GetID()] = d
}
return m
}([]catalog.Descriptor{
type descRefByName struct {
parentID descpb.ID
parentSchemaID descpb.ID
name string
}

var (
// UnleasableSystemDescriptors contains the system descriptors which
// cannot be leased. This includes the lease table itself, among others.
UnleasableSystemDescriptors = []catalog.Descriptor{
SystemDB,
LeaseTable,
DescriptorTable,
NamespaceTable,
RangeEventTable,
})
}

unleasableSystemDescriptorsByID = func(s []catalog.Descriptor) map[descpb.ID]struct{} {
m := make(map[descpb.ID]struct{}, len(s))
for _, d := range s {
m[d.GetID()] = struct{}{}
}
return m
}(UnleasableSystemDescriptors)

unleasableSystemDescriptorsByName = func(s []catalog.Descriptor) map[descRefByName]struct{} {
m := make(map[descRefByName]struct{}, len(s))
for _, d := range s {
m[descRefByName{
parentID: d.GetParentID(),
parentSchemaID: d.GetParentSchemaID(),
name: d.GetName(),
}] = struct{}{}
}
return m
}(UnleasableSystemDescriptors)
)

// IsUnleasableSystemDescriptorByID returns whether the specified descriptor is
// a member of the UnleasableSystemDescriptors set, given an ID.
func IsUnleasableSystemDescriptorByID(id descpb.ID) bool {
_, ok := unleasableSystemDescriptorsByID[id]
return ok
}

// IsUnleasableSystemDescriptorByName returns whether the specified descriptor
// is a member of the UnleasableSystemDescriptors set, given a database, schema,
// and name.
func IsUnleasableSystemDescriptorByName(
parentID descpb.ID, parentSchemaID descpb.ID, name string,
) bool {
_, ok := unleasableSystemDescriptorsByName[descRefByName{
parentID: parentID,
parentSchemaID: parentSchemaID,
name: name,
}]
return ok
}

// SpanConfigurationsTableName represents system.span_configurations.
var SpanConfigurationsTableName = tree.NewTableNameWithSchema("system", tree.PublicSchemaName, tree.Name(catconstants.SpanConfigurationsTableName))