diff --git a/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row b/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row index 38ff52cd806d..ab32718b8e06 100644 --- a/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row +++ b/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row @@ -244,7 +244,7 @@ ALTER TABLE t2 ADD COLUMN new_col INT query idx=2 SELECT * FROM t2 AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 2 ---- -pq: referenced descriptor ID 105: descriptor not found +pq: referenced descriptor ID 105: looking up ID 105: descriptor not found events (7 found): * event 1: colbatchscan trace on node_idx 2: local read * event 2: transaction retry on node_idx: 2 @@ -257,7 +257,7 @@ events (7 found): query idx=2 SELECT * FROM t2 AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 2 ---- -pq: referenced descriptor ID 105: descriptor not found +pq: referenced descriptor ID 105: looking up ID 105: descriptor not found events (7 found): * event 1: colbatchscan trace on node_idx 2: local read * event 2: transaction retry on node_idx: 2 diff --git a/pkg/cli/testdata/doctor/test_examine_zipdir b/pkg/cli/testdata/doctor/test_examine_zipdir index f5fcebabc717..90ab3aa396c2 100644 --- a/pkg/cli/testdata/doctor/test_examine_zipdir +++ b/pkg/cli/testdata/doctor/test_examine_zipdir @@ -9,7 +9,7 @@ Examining 37 descriptors and 42 namespace entries... ParentID 52, ParentSchemaID 29: relation "vehicle_location_histories" (56): referenced database ID 52: referenced descriptor not found ParentID 52, ParentSchemaID 29: relation "promo_codes" (57): referenced database ID 52: referenced descriptor not found ParentID 52, ParentSchemaID 29: relation "user_promo_codes" (58): referenced database ID 52: referenced descriptor not found - ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced descriptor not found + ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced schema ID 52: referenced descriptor not found Examining 2 jobs... job 587337426984566785: running schema change GC refers to missing table descriptor(s) [59]; existing descriptors that still need to be dropped []; job safe to delete: true. ERROR: validation failed diff --git a/pkg/cli/testdata/doctor/test_examine_zipdir_verbose b/pkg/cli/testdata/doctor/test_examine_zipdir_verbose index ba62a211e7ab..7303a4751622 100644 --- a/pkg/cli/testdata/doctor/test_examine_zipdir_verbose +++ b/pkg/cli/testdata/doctor/test_examine_zipdir_verbose @@ -50,7 +50,7 @@ Examining 37 descriptors and 42 namespace entries... ParentID 52, ParentSchemaID 29: relation "user_promo_codes" (58): referenced database ID 52: referenced descriptor not found ParentID 52, ParentSchemaID 29: relation "user_promo_codes" (58): processed ParentID 0, ParentSchemaID 0: namespace entry "defaultdb" (50): processed - ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced descriptor not found + ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced schema ID 52: referenced descriptor not found ParentID 0, ParentSchemaID 0: namespace entry "postgres" (51): processed ParentID 0, ParentSchemaID 0: namespace entry "system" (1): processed ParentID 1, ParentSchemaID 0: namespace entry "public" (29): processed diff --git a/pkg/sql/catalog/descs/descriptor.go b/pkg/sql/catalog/descs/descriptor.go index bcb7e50d5d5d..0c15250ae340 100644 --- a/pkg/sql/catalog/descs/descriptor.go +++ b/pkg/sql/catalog/descs/descriptor.go @@ -201,7 +201,7 @@ func getDescriptorsByID( if flags.layerFilters.withoutStorage { // Some descriptors are still missing and there's nowhere left to get // them from. - return catalog.ErrDescriptorNotFound + return errors.Wrapf(catalog.ErrDescriptorNotFound, "looking up descriptor(s) %v", readIDs) } const isDescriptorRequired = true read, err := tc.cr.GetByIDs(ctx, txn, readIDs.Ordered(), isDescriptorRequired, catalog.Any) @@ -235,7 +235,7 @@ func getDescriptorsByID( func filterDescriptor(desc catalog.Descriptor, flags getterFlags) error { if expected := flags.descFilters.maybeParentID; expected != descpb.InvalidID { if actual := desc.GetParentID(); actual != descpb.InvalidID && actual != expected { - return catalog.ErrDescriptorNotFound + return errors.Wrapf(catalog.ErrDescriptorNotFound, "expected %d, got %d", expected, actual) } } if flags.descFilters.withoutDropped { @@ -371,7 +371,7 @@ func (q *byIDLookupContext) lookupLeased( // If we have already read all of the descriptors, use it as a negative // cache to short-circuit a lookup we know will be doomed to fail. if q.tc.cr.IsDescIDKnownToNotExist(id, q.flags.descFilters.maybeParentID) { - return nil, catalog.NoValidation, catalog.ErrDescriptorNotFound + return nil, catalog.NoValidation, catalog.NewDescriptorNotFoundError(id) } desc, shouldReadFromStore, err := q.tc.leased.getByID(q.ctx, q.tc.deadlineHolder(q.txn), id) if err != nil || shouldReadFromStore { diff --git a/pkg/sql/catalog/descs/hydrate.go b/pkg/sql/catalog/descs/hydrate.go index 0db075d2cc48..a9ab1d8e3716 100644 --- a/pkg/sql/catalog/descs/hydrate.go +++ b/pkg/sql/catalog/descs/hydrate.go @@ -190,7 +190,7 @@ func HydrateCatalog(ctx context.Context, c nstree.MutableCatalog) error { defer sp.Finish() fakeLookupFunc := func(_ context.Context, id descpb.ID, skipHydration bool) (catalog.Descriptor, error) { - return nil, catalog.WrapDescRefErr(id, catalog.ErrDescriptorNotFound) + return nil, catalog.NewDescriptorNotFoundError(id) } typeLookupFunc := makeTypeLookupFuncForHydration(c, fakeLookupFunc) var hydratable []catalog.Descriptor diff --git a/pkg/sql/catalog/errors.go b/pkg/sql/catalog/errors.go index e94bc71b3202..b3a259af6690 100644 --- a/pkg/sql/catalog/errors.go +++ b/pkg/sql/catalog/errors.go @@ -90,6 +90,10 @@ func HasInactiveDescriptorError(err error) bool { // found with the given id. var ErrDescriptorNotFound = errors.New("descriptor not found") +func NewDescriptorNotFoundError(id descpb.ID) error { + return errors.Wrapf(ErrDescriptorNotFound, "looking up ID %d", errors.Safe(id)) +} + // ErrReferencedDescriptorNotFound is like ErrDescriptorNotFound but for // descriptors referenced within another descriptor. var ErrReferencedDescriptorNotFound = errors.New("referenced descriptor not found") diff --git a/pkg/sql/catalog/internal/catkv/catalog_query.go b/pkg/sql/catalog/internal/catkv/catalog_query.go index 07df8f30fb24..065ccbed96b1 100644 --- a/pkg/sql/catalog/internal/catkv/catalog_query.go +++ b/pkg/sql/catalog/internal/catkv/catalog_query.go @@ -214,5 +214,5 @@ func requiredError(expectedType catalog.DescriptorType, id descpb.ID) (err error default: err = errors.Errorf("failed to find descriptor [%d]", id) } - return errors.CombineErrors(catalog.ErrDescriptorNotFound, err) + return errors.CombineErrors(catalog.NewDescriptorNotFoundError(id), err) } diff --git a/pkg/sql/catalog/internal/validate/validate.go b/pkg/sql/catalog/internal/validate/validate.go index 3efa3679086b..24d37a038b57 100644 --- a/pkg/sql/catalog/internal/validate/validate.go +++ b/pkg/sql/catalog/internal/validate/validate.go @@ -294,7 +294,7 @@ var _ catalog.ValidationDescGetter = (*validationDescGetterImpl)(nil) func (vdg *validationDescGetterImpl) GetDescriptor(id descpb.ID) (catalog.Descriptor, error) { desc, found := vdg.descriptors[id] if !found || desc == nil { - return nil, catalog.NewReferencedDescriptorNotFoundError("object", id) + return nil, catalog.NewReferencedDescriptorNotFoundError("descriptor", id) } return desc, nil } diff --git a/pkg/sql/catalog/lease/lease.go b/pkg/sql/catalog/lease/lease.go index 8c40b270bd83..691138618be2 100644 --- a/pkg/sql/catalog/lease/lease.go +++ b/pkg/sql/catalog/lease/lease.go @@ -933,7 +933,7 @@ func (m *Manager) AcquireByName( // If the name we had doesn't match the newest descriptor in the DB, then // we're trying to use an old name. desc.Release(ctx) - return nil, catalog.ErrDescriptorNotFound + return nil, catalog.NewDescriptorNotFoundError(id) } } return validateDescriptorForReturn(desc) @@ -974,7 +974,10 @@ func (m *Manager) resolveName( return id, err } if id == descpb.InvalidID { - return id, catalog.ErrDescriptorNotFound + return id, errors.Wrapf(catalog.ErrDescriptorNotFound, + "resolving name %s with parentID %d and parentSchemaID %d", + name, parentID, parentSchemaID, + ) } return id, nil } diff --git a/pkg/sql/crdb_internal_test.go b/pkg/sql/crdb_internal_test.go index 91e39155af99..80e17febb5bc 100644 --- a/pkg/sql/crdb_internal_test.go +++ b/pkg/sql/crdb_internal_test.go @@ -522,9 +522,9 @@ UPDATE system.namespace SET id = %d WHERE id = %d; {fmt.Sprintf("%d", schemaID), fmt.Sprintf("[%d]", databaseID), "public", "", fmt.Sprintf(`schema "public" (%d): referenced database ID %d: referenced descriptor not found`, schemaID, databaseID), }, - {fmt.Sprintf("%d", databaseID), "t", "", "", `referenced descriptor not found`}, - {fmt.Sprintf("%d", tableFkTblID), "defaultdb", "public", "fktbl", `referenced descriptor not found`}, - {fmt.Sprintf("%d", fakeID), fmt.Sprintf("[%d]", databaseID), "public", "test", `referenced descriptor not found`}, + {fmt.Sprintf("%d", databaseID), "t", "", "", `referenced schema ID 104: referenced descriptor not found`}, + {fmt.Sprintf("%d", tableFkTblID), "defaultdb", "public", "fktbl", `referenced schema ID 107: referenced descriptor not found`}, + {fmt.Sprintf("%d", fakeID), fmt.Sprintf("[%d]", databaseID), "public", "test", `referenced schema ID 12345: referenced descriptor not found`}, }) } diff --git a/pkg/sql/doctor/doctor_test.go b/pkg/sql/doctor/doctor_test.go index 3565b882d8ef..287d7d5c7129 100644 --- a/pkg/sql/doctor/doctor_test.go +++ b/pkg/sql/doctor/doctor_test.go @@ -383,7 +383,7 @@ func TestExamineDescriptors(t *testing.T) { {NameInfo: descpb.NameInfo{Name: "causes_error"}, ID: 2}, }, expected: `Examining 0 descriptors and 4 namespace entries... - ParentID 0, ParentSchemaID 0: namespace entry "causes_error" (2): referenced descriptor not found + ParentID 0, ParentSchemaID 0: namespace entry "causes_error" (2): referenced schema ID 2: referenced descriptor not found `, }, { // 14 diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal b/pkg/sql/logictest/testdata/logic_test/crdb_internal index c5a8c8a606e3..68126f18c99b 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal @@ -1113,10 +1113,10 @@ query ITTTT colnames SELECT * FROM "".crdb_internal.invalid_objects ORDER BY id ---- id database_name schema_name obj_name error -500 baddb · · referenced descriptor not found -501 system badschema · referenced descriptor not found -502 system public badobj referenced descriptor not found -503 system [404] badobj referenced descriptor not found +500 baddb · · referenced schema ID 500: referenced descriptor not found +501 system badschema · referenced schema ID 501: referenced descriptor not found +502 system public badobj referenced schema ID 502: referenced descriptor not found +503 system [404] badobj referenced schema ID 503: referenced descriptor not found statement ok SELECT crdb_internal.unsafe_delete_namespace_entry(0, 0, 'baddb', 500, true);