Skip to content

Commit b291808

Browse files
committed
catalog: add more detail to ErrDescriptorNotFound errors
Now the ID will always be shown when this error happens. Release note: None
1 parent d5193f7 commit b291808

File tree

12 files changed

+27
-20
lines changed

12 files changed

+27
-20
lines changed

pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ ALTER TABLE t2 ADD COLUMN new_col INT
244244
query idx=2
245245
SELECT * FROM t2 AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 2
246246
----
247-
pq: referenced descriptor ID 105: descriptor not found
247+
pq: referenced descriptor ID 105: looking up ID 105: descriptor not found
248248
events (7 found):
249249
* event 1: colbatchscan trace on node_idx 2: local read
250250
* event 2: transaction retry on node_idx: 2
@@ -257,7 +257,7 @@ events (7 found):
257257
query idx=2
258258
SELECT * FROM t2 AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 2
259259
----
260-
pq: referenced descriptor ID 105: descriptor not found
260+
pq: referenced descriptor ID 105: looking up ID 105: descriptor not found
261261
events (7 found):
262262
* event 1: colbatchscan trace on node_idx 2: local read
263263
* event 2: transaction retry on node_idx: 2

pkg/cli/testdata/doctor/test_examine_zipdir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Examining 37 descriptors and 42 namespace entries...
99
ParentID 52, ParentSchemaID 29: relation "vehicle_location_histories" (56): referenced database ID 52: referenced descriptor not found
1010
ParentID 52, ParentSchemaID 29: relation "promo_codes" (57): referenced database ID 52: referenced descriptor not found
1111
ParentID 52, ParentSchemaID 29: relation "user_promo_codes" (58): referenced database ID 52: referenced descriptor not found
12-
ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced descriptor not found
12+
ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced schema ID 52: referenced descriptor not found
1313
Examining 2 jobs...
1414
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.
1515
ERROR: validation failed

pkg/cli/testdata/doctor/test_examine_zipdir_verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Examining 37 descriptors and 42 namespace entries...
5050
ParentID 52, ParentSchemaID 29: relation "user_promo_codes" (58): referenced database ID 52: referenced descriptor not found
5151
ParentID 52, ParentSchemaID 29: relation "user_promo_codes" (58): processed
5252
ParentID 0, ParentSchemaID 0: namespace entry "defaultdb" (50): processed
53-
ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced descriptor not found
53+
ParentID 0, ParentSchemaID 0: namespace entry "movr" (52): referenced schema ID 52: referenced descriptor not found
5454
ParentID 0, ParentSchemaID 0: namespace entry "postgres" (51): processed
5555
ParentID 0, ParentSchemaID 0: namespace entry "system" (1): processed
5656
ParentID 1, ParentSchemaID 0: namespace entry "public" (29): processed

pkg/sql/catalog/descs/descriptor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func getDescriptorsByID(
201201
if flags.layerFilters.withoutStorage {
202202
// Some descriptors are still missing and there's nowhere left to get
203203
// them from.
204-
return catalog.ErrDescriptorNotFound
204+
return errors.Wrapf(catalog.ErrDescriptorNotFound, "looking up descriptor(s) %v", readIDs)
205205
}
206206
const isDescriptorRequired = true
207207
read, err := tc.cr.GetByIDs(ctx, txn, readIDs.Ordered(), isDescriptorRequired, catalog.Any)
@@ -235,7 +235,7 @@ func getDescriptorsByID(
235235
func filterDescriptor(desc catalog.Descriptor, flags getterFlags) error {
236236
if expected := flags.descFilters.maybeParentID; expected != descpb.InvalidID {
237237
if actual := desc.GetParentID(); actual != descpb.InvalidID && actual != expected {
238-
return catalog.ErrDescriptorNotFound
238+
return errors.Wrapf(catalog.ErrDescriptorNotFound, "expected %d, got %d", expected, actual)
239239
}
240240
}
241241
if flags.descFilters.withoutDropped {
@@ -371,7 +371,7 @@ func (q *byIDLookupContext) lookupLeased(
371371
// If we have already read all of the descriptors, use it as a negative
372372
// cache to short-circuit a lookup we know will be doomed to fail.
373373
if q.tc.cr.IsDescIDKnownToNotExist(id, q.flags.descFilters.maybeParentID) {
374-
return nil, catalog.NoValidation, catalog.ErrDescriptorNotFound
374+
return nil, catalog.NoValidation, catalog.NewDescriptorNotFoundError(id)
375375
}
376376
desc, shouldReadFromStore, err := q.tc.leased.getByID(q.ctx, q.tc.deadlineHolder(q.txn), id)
377377
if err != nil || shouldReadFromStore {

pkg/sql/catalog/descs/hydrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func HydrateCatalog(ctx context.Context, c nstree.MutableCatalog) error {
190190
defer sp.Finish()
191191

192192
fakeLookupFunc := func(_ context.Context, id descpb.ID, skipHydration bool) (catalog.Descriptor, error) {
193-
return nil, catalog.WrapDescRefErr(id, catalog.ErrDescriptorNotFound)
193+
return nil, catalog.NewDescriptorNotFoundError(id)
194194
}
195195
typeLookupFunc := makeTypeLookupFuncForHydration(c, fakeLookupFunc)
196196
var hydratable []catalog.Descriptor

pkg/sql/catalog/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func HasInactiveDescriptorError(err error) bool {
9090
// found with the given id.
9191
var ErrDescriptorNotFound = errors.New("descriptor not found")
9292

93+
func NewDescriptorNotFoundError(id descpb.ID) error {
94+
return errors.Wrapf(ErrDescriptorNotFound, "looking up ID %d", errors.Safe(id))
95+
}
96+
9397
// ErrReferencedDescriptorNotFound is like ErrDescriptorNotFound but for
9498
// descriptors referenced within another descriptor.
9599
var ErrReferencedDescriptorNotFound = errors.New("referenced descriptor not found")

pkg/sql/catalog/internal/catkv/catalog_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,5 @@ func requiredError(expectedType catalog.DescriptorType, id descpb.ID) (err error
214214
default:
215215
err = errors.Errorf("failed to find descriptor [%d]", id)
216216
}
217-
return errors.CombineErrors(catalog.ErrDescriptorNotFound, err)
217+
return errors.CombineErrors(catalog.NewDescriptorNotFoundError(id), err)
218218
}

pkg/sql/catalog/internal/validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ var _ catalog.ValidationDescGetter = (*validationDescGetterImpl)(nil)
294294
func (vdg *validationDescGetterImpl) GetDescriptor(id descpb.ID) (catalog.Descriptor, error) {
295295
desc, found := vdg.descriptors[id]
296296
if !found || desc == nil {
297-
return nil, catalog.NewReferencedDescriptorNotFoundError("object", id)
297+
return nil, catalog.NewReferencedDescriptorNotFoundError("descriptor", id)
298298
}
299299
return desc, nil
300300
}

pkg/sql/catalog/lease/lease.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ func (m *Manager) AcquireByName(
933933
// If the name we had doesn't match the newest descriptor in the DB, then
934934
// we're trying to use an old name.
935935
desc.Release(ctx)
936-
return nil, catalog.ErrDescriptorNotFound
936+
return nil, catalog.NewDescriptorNotFoundError(id)
937937
}
938938
}
939939
return validateDescriptorForReturn(desc)
@@ -974,7 +974,10 @@ func (m *Manager) resolveName(
974974
return id, err
975975
}
976976
if id == descpb.InvalidID {
977-
return id, catalog.ErrDescriptorNotFound
977+
return id, errors.Wrapf(catalog.ErrDescriptorNotFound,
978+
"resolving name %s with parentID %d and parentSchemaID %d",
979+
name, parentID, parentSchemaID,
980+
)
978981
}
979982
return id, nil
980983
}

pkg/sql/crdb_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,9 @@ UPDATE system.namespace SET id = %d WHERE id = %d;
522522
{fmt.Sprintf("%d", schemaID), fmt.Sprintf("[%d]", databaseID), "public", "",
523523
fmt.Sprintf(`schema "public" (%d): referenced database ID %d: referenced descriptor not found`, schemaID, databaseID),
524524
},
525-
{fmt.Sprintf("%d", databaseID), "t", "", "", `referenced descriptor not found`},
526-
{fmt.Sprintf("%d", tableFkTblID), "defaultdb", "public", "fktbl", `referenced descriptor not found`},
527-
{fmt.Sprintf("%d", fakeID), fmt.Sprintf("[%d]", databaseID), "public", "test", `referenced descriptor not found`},
525+
{fmt.Sprintf("%d", databaseID), "t", "", "", `referenced schema ID 104: referenced descriptor not found`},
526+
{fmt.Sprintf("%d", tableFkTblID), "defaultdb", "public", "fktbl", `referenced schema ID 107: referenced descriptor not found`},
527+
{fmt.Sprintf("%d", fakeID), fmt.Sprintf("[%d]", databaseID), "public", "test", `referenced schema ID 12345: referenced descriptor not found`},
528528
})
529529
}
530530

0 commit comments

Comments
 (0)