Skip to content

Commit 4600cd3

Browse files
craig[bot]fqazi
andcommitted
Merge #157918
157918: catalog/lease: address bugs with leased descriptors in catalog views r=fqazi a=fqazi This patch makes the following changes to improve behaviour of leased descriptors in catalog views and extend testing: 1. Fixing a bug in the locked leasing where processing multiple descriptor versions could lead to a panic. This would happen if the range feed delivered the special update key before the modified descriptors. 2. Addressed a bug where create_type_statments would break since comments were not being looked up for the point look up index. This patch also adds crdb_internal into the local-leased-descriptor config 3. Enable locked leasing timestamps for the large schema benchmark to improve test coverage. This also helps us ensure no performance regression exists in this mode. Fixes: #157916 Fixes: #157917 Fixes: #157880 Co-authored-by: Faizan Qazi <[email protected]>
2 parents 3bceb1c + 0096155 commit 4600cd3

File tree

8 files changed

+29
-7
lines changed

8 files changed

+29
-7
lines changed

pkg/cmd/roachtest/tests/large_schema_benchmark.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ func registerLargeSchemaBenchmark(r registry.Registry, numTables int, isMultiReg
160160
// pg_catalog and information_schema.
161161
_, err = conn.Exec("SET CLUSTER SETTING sql.catalog.allow_leased_descriptors.enabled = 'true'")
162162
require.NoError(t, err)
163+
// Enabled locked descriptor leasing for correctness.
164+
_, err = conn.Exec("SET CLUSTER SETTING sql.catalog.descriptor_lease.use_locked_timestamps.enabled = 'true'")
165+
require.NoError(t, err)
163166
// Since we will be making a large number of databases / tables
164167
// quickly,on MR the job retention can slow things down. Let's
165168
// minimize how long jobs are kept, so that the creation / ingest

pkg/sql/catalog/descs/getters.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,14 @@ func (b ByIDGetterBuilder) WithoutSynthetic() ByIDGetterBuilder {
530530
return b
531531
}
532532

533+
// WithMetaData configures the byIDGetterBuilder to read zone configs and comments
534+
// for lease descriptors. This is always acquired for descriptors from storage,
535+
// and may need an extra round trip.
536+
func (b ByIDGetterBuilder) WithMetaData() ByIDGetterBuilder {
537+
b.flags.layerFilters.withMetadata = true
538+
return b
539+
}
540+
533541
// WithoutDropped configures the ByIDGetterBuilder to error on descriptors
534542
// which are in a dropped state.
535543
func (b ByIDGetterBuilder) WithoutDropped() ByIDGetterBuilder {

pkg/sql/catalog/lease/lease.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ func (m *Manager) processDescriptorUpdate(
22042204
}
22052205
// Remove one element from the end after.
22062206
entry.mu.DescriptorIDs = entry.mu.DescriptorIDs[:len(entry.mu.DescriptorIDs)-1]
2207-
entry.mu.DescriptorVersions = entry.mu.DescriptorVersions[:len(entry.mu.DescriptorIDs)-1]
2207+
entry.mu.DescriptorVersions = entry.mu.DescriptorVersions[:len(entry.mu.DescriptorVersions)-1]
22082208
break
22092209
}
22102210
return len(entry.mu.DescriptorIDs) == 0

pkg/sql/crdb_internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ CREATE TABLE crdb_internal.create_type_statements (
32273227
addRow func(...tree.Datum) error,
32283228
) (matched bool, err error) {
32293229
id := descpb.ID(tree.MustBeDInt(unwrappedConstraint))
3230-
scName, typDesc, err := getSchemaAndTypeByTypeID(ctx, p, id)
3230+
scName, typDesc, err := getSchemaAndTypeByTypeID(ctx, p, id, true /* includeMetaData */)
32313231
if err != nil || typDesc == nil {
32323232
return false, err
32333233
}

pkg/sql/logictest/testdata/logic_test/crdb_internal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 3node-tenant is blocked from running this file due to heavy reliance on
22
# unavailable node IDs in this test.
3-
# LogicTest: !3node-tenant-default-configs !local-prepared
3+
# LogicTest: !3node-tenant-default-configs !local-prepared local-leased-descriptors default-configs
44

55
query error database "crdb_internal" does not exist
66
ALTER DATABASE crdb_internal RENAME TO not_crdb_internal

pkg/sql/logictest/tests/local-leased-descriptors/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ go_test(
1212
"//build/toolchains:is_heavy": {"test.Pool": "heavy"},
1313
"//conditions:default": {"test.Pool": "large"},
1414
}),
15-
shard_count = 11,
15+
shard_count = 12,
1616
tags = ["cpu:1"],
1717
deps = [
1818
"//pkg/base",

pkg/sql/logictest/tests/local-leased-descriptors/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/pg_catalog.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,9 +3796,13 @@ func addPGAttributeRowForCompositeType(
37963796
}
37973797

37983798
func getSchemaAndTypeByTypeID(
3799-
ctx context.Context, p *planner, id descpb.ID,
3799+
ctx context.Context, p *planner, id descpb.ID, includeMetaData bool,
38003800
) (catalog.SchemaDescriptor, catalog.TypeDescriptor, error) {
3801-
typDesc, err := descs.GetCatalogDescriptorGetter(p.Descriptors(), p.txn, &p.EvalContext().Settings.SV).WithoutNonPublic().Get().Type(ctx, id)
3801+
getter := descs.GetCatalogDescriptorGetter(p.Descriptors(), p.txn, &p.EvalContext().Settings.SV)
3802+
if includeMetaData {
3803+
getter = getter.WithMetaData()
3804+
}
3805+
typDesc, err := getter.WithoutNonPublic().Get().Type(ctx, id)
38023806
if err != nil {
38033807
// If the type was not found, it may be a table.
38043808
if !(errors.Is(err, catalog.ErrDescriptorNotFound) || pgerror.GetPGCode(err) == pgcode.UndefinedObject) {
@@ -3897,7 +3901,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-type.html`,
38973901

38983902
id := typedesc.UserDefinedTypeOIDToID(ooid)
38993903

3900-
sc, typDesc, err := getSchemaAndTypeByTypeID(ctx, p, id)
3904+
sc, typDesc, err := getSchemaAndTypeByTypeID(ctx, p, id, false /* includeMetaData */)
39013905
if err != nil || typDesc == nil {
39023906
return false, err
39033907
}

0 commit comments

Comments
 (0)