From a39452bd95f82915c66951d1b21740ea5d23c2bc Mon Sep 17 00:00:00 2001 From: Marius Posta Date: Wed, 4 Jan 2023 16:12:07 -0500 Subject: [PATCH] descs,*: refactor by-ID descriptor lookups This commit refactors the by-ID getters and builders API with sane defaults for leasing. Access to leased descriptors is now explicitly opted in. Informs #87753. Release note: None --- pkg/ccl/backupccl/backup_test.go | 8 ++-- pkg/ccl/backupccl/restore_job.go | 32 +++++++------- pkg/ccl/backupccl/restore_planning.go | 10 ++--- pkg/ccl/backupccl/targets.go | 2 +- .../cdcevent/rowfetcher_cache.go | 4 +- pkg/ccl/changefeedccl/changefeed_dist.go | 2 +- pkg/ccl/changefeedccl/changefeed_stmt.go | 4 +- .../changefeedccl/schemafeed/schema_feed.go | 2 +- pkg/ccl/multiregionccl/region_util_test.go | 4 +- pkg/scheduledjobs/schedulebase/util.go | 4 +- pkg/server/status.go | 6 +-- .../spanconfigreconciler/reconciler.go | 2 +- .../spanconfigsqltranslator/sqltranslator.go | 4 +- .../spanconfigtestcluster/tenant_state.go | 2 +- pkg/sql/alter_database.go | 24 +++++------ pkg/sql/alter_default_privileges.go | 2 +- pkg/sql/alter_function.go | 6 +-- pkg/sql/alter_schema.go | 9 ++-- pkg/sql/alter_table.go | 2 +- pkg/sql/alter_table_locality.go | 10 ++--- pkg/sql/alter_type.go | 6 +-- pkg/sql/authorization.go | 6 +-- pkg/sql/backfill.go | 28 ++++++------ pkg/sql/catalog/descriptor.go | 6 +-- pkg/sql/catalog/descs/collection_test.go | 34 +++++++-------- .../catalog/descs/dist_sql_type_resolver.go | 2 +- pkg/sql/catalog/descs/getters.go | 43 +++++++++++-------- pkg/sql/catalog/descs/helpers.go | 2 +- .../hydrateddesccache/hydratedcache.go | 2 +- pkg/sql/catalog/ingesting/privileges.go | 4 +- pkg/sql/catalog/ingesting/write_descs.go | 4 +- pkg/sql/catalog/lease/lease_test.go | 4 +- pkg/sql/catalog/schemadesc/schema_desc.go | 2 +- pkg/sql/check.go | 8 ++-- pkg/sql/check_test.go | 2 +- pkg/sql/comment_on_schema.go | 2 +- pkg/sql/crdb_internal.go | 18 ++++---- pkg/sql/create_function.go | 6 +-- pkg/sql/create_function_test.go | 6 +-- pkg/sql/create_schema.go | 2 +- pkg/sql/create_stats.go | 2 +- pkg/sql/create_table.go | 6 +-- pkg/sql/create_view.go | 8 ++-- pkg/sql/database.go | 2 +- pkg/sql/database_region_change_finalizer.go | 4 +- pkg/sql/database_test.go | 2 +- pkg/sql/delete_preserving_index_test.go | 4 +- pkg/sql/descmetadata/metadata_updater.go | 2 +- pkg/sql/descriptor.go | 4 +- pkg/sql/drop_cascade.go | 2 +- pkg/sql/drop_database.go | 6 +-- pkg/sql/drop_function.go | 6 +-- pkg/sql/drop_function_test.go | 12 +++--- pkg/sql/drop_schema.go | 2 +- pkg/sql/drop_sequence.go | 2 +- pkg/sql/drop_table.go | 6 +-- pkg/sql/drop_test.go | 10 ++--- pkg/sql/drop_type.go | 14 +++--- pkg/sql/drop_view.go | 6 +-- pkg/sql/evalcatalog/encode_table_index_key.go | 2 +- .../evalcatalog/geo_inverted_index_entries.go | 2 +- pkg/sql/evalcatalog/pg_updatable.go | 4 +- pkg/sql/gcjob/gc_job.go | 2 +- pkg/sql/gcjob/index_garbage_collection.go | 4 +- pkg/sql/gcjob/refresh_statuses.go | 2 +- pkg/sql/gcjob/table_garbage_collection.go | 4 +- pkg/sql/gcjob_test/gc_job_test.go | 8 ++-- pkg/sql/grant_revoke.go | 2 +- pkg/sql/importer/import_job.go | 30 ++++++------- pkg/sql/importer/import_planning.go | 6 +-- pkg/sql/importer/import_stmt_test.go | 6 +-- pkg/sql/importer/read_import_pgdump.go | 4 +- pkg/sql/indexbackfiller_test.go | 4 +- pkg/sql/information_schema.go | 4 +- pkg/sql/opt_catalog.go | 4 +- pkg/sql/pg_catalog.go | 26 +++++------ pkg/sql/planner.go | 2 +- pkg/sql/privileged_accessor.go | 2 +- pkg/sql/reassign_owned_by.go | 12 +++--- pkg/sql/region_util.go | 23 +++++----- pkg/sql/rename_database.go | 20 ++++----- pkg/sql/rename_table.go | 8 ++-- pkg/sql/repair.go | 10 ++--- pkg/sql/resolver.go | 28 ++++++------ pkg/sql/row/row_converter.go | 2 +- pkg/sql/rowexec/backfiller.go | 2 +- pkg/sql/schema_change_plan_node.go | 2 +- pkg/sql/schema_changer.go | 42 +++++++++--------- pkg/sql/schema_changer_test.go | 2 +- pkg/sql/schema_resolver.go | 19 ++++---- pkg/sql/schemachanger/scdeps/build_deps.go | 2 +- pkg/sql/schemachanger/scdeps/exec_deps.go | 8 ++-- pkg/sql/schemachanger/scdeps/run_deps.go | 2 +- pkg/sql/scrub.go | 2 +- pkg/sql/sequence.go | 14 +++--- pkg/sql/stats/automatic_stats.go | 2 +- pkg/sql/table_test.go | 2 +- pkg/sql/temporary_schema.go | 9 ++-- pkg/sql/temporary_schema_test.go | 2 +- pkg/sql/truncate.go | 4 +- pkg/sql/ttl/ttljob/ttljob.go | 2 +- pkg/sql/ttl/ttljob/ttljob_processor.go | 4 +- pkg/sql/ttl/ttlschedule/ttlschedule.go | 8 ++-- pkg/sql/type_change.go | 24 +++++------ pkg/sql/user.go | 2 +- .../fix_userfile_descriptor_corruption.go | 6 +-- pkg/upgrade/upgrades/helpers_test.go | 4 +- pkg/upgrade/upgrades/schema_changes.go | 2 +- ..._column_ids_in_sequence_back_references.go | 4 +- ...upgrade_sequence_to_be_referenced_by_ID.go | 4 +- 110 files changed, 412 insertions(+), 409 deletions(-) diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index fed81f2c4249..cafb5c22b4f1 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -10387,7 +10387,7 @@ $$; require.NoError(t, err) require.Equal(t, 110, int(tbDesc.GetID())) - fnDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, descpb.ID(udfID)) + fnDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, descpb.ID(udfID)) require.NoError(t, err) require.Equal(t, 111, int(fnDesc.GetID())) require.Equal(t, 104, int(fnDesc.GetParentID())) @@ -10443,7 +10443,7 @@ $$; require.NoError(t, err) require.Equal(t, 118, int(tbDesc.GetID())) - fnDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, descpb.ID(udfID)) + fnDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, descpb.ID(udfID)) require.NoError(t, err) require.Equal(t, 119, int(fnDesc.GetID())) require.Equal(t, 112, int(fnDesc.GetParentID())) @@ -10534,7 +10534,7 @@ $$; require.NoError(t, err) require.Equal(t, 110, int(tbDesc.GetID())) - fnDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, descpb.ID(udfID)) + fnDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, descpb.ID(udfID)) require.NoError(t, err) require.Equal(t, 111, int(fnDesc.GetID())) require.Equal(t, 104, int(fnDesc.GetParentID())) @@ -10592,7 +10592,7 @@ $$; require.NoError(t, err) require.Equal(t, 129, int(tbDesc.GetID())) - fnDesc, err := col.ByID(txn)..WithPublic().Immutable().Function(ctx, descpb.ID(udfID)) + fnDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, descpb.ID(udfID)) require.NoError(t, err) require.Equal(t, 130, int(fnDesc.GetID())) require.Equal(t, 107, int(fnDesc.GetParentID())) diff --git a/pkg/ccl/backupccl/restore_job.go b/pkg/ccl/backupccl/restore_job.go index e9d348f78296..aa5883605116 100644 --- a/pkg/ccl/backupccl/restore_job.go +++ b/pkg/ccl/backupccl/restore_job.go @@ -1073,7 +1073,7 @@ func createImportingDescriptors( // Write the updated databases. for dbID, schemas := range existingDBsWithNewSchemas { log.Infof(ctx, "writing %d schema entries to database %d", len(schemas), dbID) - desc, err := descsCol.ByID(txn).Mutable().Desc(ctx, dbID) + desc, err := descsCol.MutableByID(txn).Desc(ctx, dbID) if err != nil { return err } @@ -1093,7 +1093,7 @@ func createImportingDescriptors( // to the new tables being restored. for _, table := range mutableTables { // Collect all types used by this table. - dbDesc, err := descsCol.ByID(txn).WithoutDropped().WithoutLeased().Immutable().Database(ctx, table.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutDropped().Get().Database(ctx, table.GetParentID()) if err != nil { return err } @@ -1115,7 +1115,7 @@ func createImportingDescriptors( continue } // Otherwise, add a backreference to this table. - typDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, id) + typDesc, err := descsCol.MutableByID(txn).Type(ctx, id) if err != nil { return err } @@ -1139,7 +1139,7 @@ func createImportingDescriptors( if details.DescriptorCoverage != tree.AllDescriptors { for _, table := range tableDescs { if lc := table.GetLocalityConfig(); lc != nil { - desc, err := descsCol.ByID(txn).WithoutDropped().WithoutLeased().Immutable().Database(ctx, table.ParentID) + desc, err := descsCol.ByID(txn).WithoutDropped().Get().Database(ctx, table.ParentID) if err != nil { return err } @@ -1149,7 +1149,7 @@ func createImportingDescriptors( table.ID, table.ParentID) } - mutTable, err := descsCol.ByID(txn).Mutable().Table(ctx, table.GetID()) + mutTable, err := descsCol.MutableByID(txn).Table(ctx, table.GetID()) if err != nil { return err } @@ -2228,7 +2228,7 @@ func prefetchDescriptors( // and we're going to write them to KV very soon as part of a // single batch). ids := allDescIDs.Ordered() - got, err := descsCol.ByID(txn).Mutable().Descs(ctx, ids) + got, err := descsCol.MutableByID(txn).Descs(ctx, ids) if err != nil { return nstree.Catalog{}, errors.Wrap(err, "prefetch descriptors") } @@ -2360,7 +2360,7 @@ func (r *restoreResumer) dropDescriptors( mutableTables := make([]*tabledesc.Mutable, len(details.TableDescs)) for i := range details.TableDescs { var err error - mutableTables[i], err = descsCol.ByID(txn).Mutable().Table(ctx, details.TableDescs[i].ID) + mutableTables[i], err = descsCol.MutableByID(txn).Table(ctx, details.TableDescs[i].ID) if err != nil { return err } @@ -2439,7 +2439,7 @@ func (r *restoreResumer) dropDescriptors( // TypeDescriptors don't have a GC job process, so we can just write them // as dropped here. typDesc := details.TypeDescs[i] - mutType, err := descsCol.ByID(txn).Mutable().Type(ctx, typDesc.ID) + mutType, err := descsCol.MutableByID(txn).Type(ctx, typDesc.ID) if err != nil { return err } @@ -2455,7 +2455,7 @@ func (r *restoreResumer) dropDescriptors( for i := range details.FunctionDescs { fnDesc := details.FunctionDescs[i] - mutFn, err := descsCol.ByID(txn).Mutable().Function(ctx, fnDesc.ID) + mutFn, err := descsCol.MutableByID(txn).Function(ctx, fnDesc.ID) if err != nil { return err } @@ -2527,13 +2527,13 @@ func (r *restoreResumer) dropDescriptors( continue } - mutSchema, err := descsCol.ByID(txn).Mutable().Desc(ctx, schemaDesc.GetID()) + mutSchema, err := descsCol.MutableByID(txn).Desc(ctx, schemaDesc.GetID()) if err != nil { return err } entry, hasEntry := dbsWithDeletedSchemas[schemaDesc.GetParentID()] if !hasEntry { - mutParent, err := descsCol.ByID(txn).Mutable().Desc(ctx, schemaDesc.GetParentID()) + mutParent, err := descsCol.MutableByID(txn).Desc(ctx, schemaDesc.GetParentID()) if err != nil { return err } @@ -2604,7 +2604,7 @@ func (r *restoreResumer) dropDescriptors( continue } - db, err := descsCol.ByID(txn).Mutable().Desc(ctx, dbDesc.GetID()) + db, err := descsCol.MutableByID(txn).Desc(ctx, dbDesc.GetID()) if err != nil { return err } @@ -2658,12 +2658,12 @@ func setGCTTLForDroppingTable( log.VInfof(ctx, 2, "lowering TTL for table %q (%d)", tableToDrop.GetName(), tableToDrop.GetID()) // We get a mutable descriptor here because we are going to construct a // synthetic descriptor collection in which they are online. - dbDesc, err := descsCol.ByID(txn).WithoutLeased().Immutable().Database(ctx, tableToDrop.GetParentID()) + dbDesc, err := descsCol.ByID(txn).Get().Database(ctx, tableToDrop.GetParentID()) if err != nil { return err } - schemaDesc, err := descsCol.ByID(txn).WithoutLeased().Immutable().Schema(ctx, tableToDrop.GetParentSchemaID()) + schemaDesc, err := descsCol.ByID(txn).Get().Schema(ctx, tableToDrop.GetParentSchemaID()) if err != nil { return err } @@ -2722,7 +2722,7 @@ func (r *restoreResumer) removeExistingTypeBackReferences( return restored, nil } // Finally, look it up using the transaction. - typ, err := descsCol.ByID(txn).Mutable().Type(ctx, id) + typ, err := descsCol.MutableByID(txn).Type(ctx, id) if err != nil { return nil, err } @@ -2730,7 +2730,7 @@ func (r *restoreResumer) removeExistingTypeBackReferences( return typ, nil } - dbDesc, err := descsCol.ByID(txn).WithoutDropped().WithoutLeased().Immutable().Database(ctx, tbl.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutDropped().Get().Database(ctx, tbl.GetParentID()) if err != nil { return err } diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index 224a64975830..06ea10fa7796 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -332,7 +332,7 @@ func allocateDescriptorRewrites( } else { // If we found an existing schema, then we need to remap all references // to this schema to the existing one. - desc, err := col.ByID(txn).WithoutLeased().Immutable().Schema(ctx, id) + desc, err := col.ByID(txn).Get().Schema(ctx, id) if err != nil { return err } @@ -381,7 +381,7 @@ func allocateDescriptorRewrites( } // Check privileges. - parentDB, err := col.ByID(txn).WithoutLeased().Immutable().Database(ctx, parentID) + parentDB, err := col.ByID(txn).Get().Database(ctx, parentID) if err != nil { return errors.Wrapf(err, "failed to lookup parent DB %d", errors.Safe(parentID)) @@ -446,7 +446,7 @@ func allocateDescriptorRewrites( targetDB, typ.Name) } // Check privileges on the parent DB. - parentDB, err := col.ByID(txn).WithoutLeased().Immutable().Database(ctx, parentID) + parentDB, err := col.ByID(txn).Get().Database(ctx, parentID) if err != nil { return errors.Wrapf(err, "failed to lookup parent DB %d", errors.Safe(parentID)) @@ -694,7 +694,7 @@ func getDatabaseIDAndDesc( return dbID, nil, errors.Errorf("a database named %q needs to exist", targetDB) } // Check privileges on the parent DB. - dbDesc, err = col.ByID(txn).WithoutLeased().Immutable().Database(ctx, dbID) + dbDesc, err = col.ByID(txn).Get().Database(ctx, dbID) if err != nil { return 0, nil, errors.Wrapf(err, "failed to lookup parent DB %d", errors.Safe(dbID)) @@ -2034,7 +2034,7 @@ func renameTargetDatabaseDescriptor( } db, ok := restoreDBs[0].(*dbdesc.Mutable) if !ok { - return errors.AssertionFailedf("expected *dbdesc.Mutable but found %T", db) + return errors.AssertionFailedf("expected *dbdesc.mutable but found %T", db) } db.SetName(newDBName) return nil diff --git a/pkg/ccl/backupccl/targets.go b/pkg/ccl/backupccl/targets.go index 088a7fbc91ed..cb6b1c9de4f7 100644 --- a/pkg/ccl/backupccl/targets.go +++ b/pkg/ccl/backupccl/targets.go @@ -595,7 +595,7 @@ func checkMultiRegionCompatible( // For REGION BY TABLE IN tables, allow the restore if the // database has the region. regionEnumID := database.GetRegionConfig().RegionEnumID - regionEnum, err := col.ByID(txn).WithoutLeased().Immutable().Type(ctx, regionEnumID) + regionEnum, err := col.ByID(txn).Get().Type(ctx, regionEnumID) if err != nil { return err } diff --git a/pkg/ccl/changefeedccl/cdcevent/rowfetcher_cache.go b/pkg/ccl/changefeedccl/cdcevent/rowfetcher_cache.go index 53c0b0cb26b8..7e7e2ac3cb48 100644 --- a/pkg/ccl/changefeedccl/cdcevent/rowfetcher_cache.go +++ b/pkg/ccl/changefeedccl/cdcevent/rowfetcher_cache.go @@ -106,7 +106,7 @@ func refreshUDT( if err != nil { return err } - tableDesc, err = collection.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, tableID) + tableDesc, err = collection.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, tableID) return err }); err != nil { // Manager can return all kinds of errors during chaos, but based on @@ -189,7 +189,7 @@ func (c *rowFetcherCache) RowFetcherForColumnFamily( // version and the desired version to use the cache. It is safe to use // UserDefinedTypeColsHaveSameVersion if we have a hit because we are // guaranteed that the tables have the same version. Additionally, these - // fetchers are always initialized with a single tabledesc.Immutable. + // fetchers are always initialized with a single tabledesc.Get. if safe, err := catalog.UserDefinedTypeColsInFamilyHaveSameVersion(tableDesc, f.tableDesc, family); err != nil { return nil, nil, err } else if safe { diff --git a/pkg/ccl/changefeedccl/changefeed_dist.go b/pkg/ccl/changefeedccl/changefeed_dist.go index f235d2dddde0..bc4c60366524 100644 --- a/pkg/ccl/changefeedccl/changefeed_dist.go +++ b/pkg/ccl/changefeedccl/changefeed_dist.go @@ -148,7 +148,7 @@ func fetchTableDescriptors( // and lie within the primary index span. Deduplication is important // here as requesting the same span twice will deadlock. return targets.EachTableID(func(id catid.DescID) error { - tableDesc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, id) + tableDesc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, id) if err != nil { return err } diff --git a/pkg/ccl/changefeedccl/changefeed_stmt.go b/pkg/ccl/changefeedccl/changefeed_stmt.go index debbc431ba12..9c43e5907ac6 100644 --- a/pkg/ccl/changefeedccl/changefeed_stmt.go +++ b/pkg/ccl/changefeedccl/changefeed_stmt.go @@ -1177,11 +1177,11 @@ func getQualifiedTableNameObj( ctx context.Context, execCfg *sql.ExecutorConfig, txn *kv.Txn, desc catalog.TableDescriptor, ) (tree.TableName, error) { col := execCfg.CollectionFactory.NewCollection(ctx) - db, err := col.ByID(txn).WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + db, err := col.ByID(txn).Get().Database(ctx, desc.GetParentID()) if err != nil { return tree.TableName{}, err } - sc, err := col.ByID(txn).WithoutLeased().Immutable().Schema(ctx, desc.GetParentSchemaID()) + sc, err := col.ByID(txn).Get().Schema(ctx, desc.GetParentSchemaID()) if err != nil { return tree.TableName{}, err } diff --git a/pkg/ccl/changefeedccl/schemafeed/schema_feed.go b/pkg/ccl/changefeedccl/schemafeed/schema_feed.go index 064b7415f402..e30e6f34dfa4 100644 --- a/pkg/ccl/changefeedccl/schemafeed/schema_feed.go +++ b/pkg/ccl/changefeedccl/schemafeed/schema_feed.go @@ -272,7 +272,7 @@ func (tf *schemaFeed) primeInitialTableDescs(ctx context.Context) error { } // Note that all targets are currently guaranteed to be tables. return tf.targets.EachTableID(func(id descpb.ID) error { - tableDesc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, id) + tableDesc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, id) if err != nil { return err } diff --git a/pkg/ccl/multiregionccl/region_util_test.go b/pkg/ccl/multiregionccl/region_util_test.go index 76f037b777a6..2b767c39c002 100644 --- a/pkg/ccl/multiregionccl/region_util_test.go +++ b/pkg/ccl/multiregionccl/region_util_test.go @@ -123,11 +123,11 @@ func getEnumMembers( t.Helper() enumMembers := make(map[string][]byte) err := sql.TestingDescsTxn(ctx, ts, func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, dbID) + dbDesc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, dbID) require.NoError(t, err) regionEnumID, err := dbDesc.MultiRegionEnumID() require.NoError(t, err) - regionEnumDesc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Type(ctx, regionEnumID) + regionEnumDesc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Type(ctx, regionEnumID) require.NoError(t, err) for ord := 0; ord < regionEnumDesc.NumEnumMembers(); ord++ { enumMembers[regionEnumDesc.GetMemberLogicalRepresentation(ord)] = regionEnumDesc.GetMemberPhysicalRepresentation(ord) diff --git a/pkg/scheduledjobs/schedulebase/util.go b/pkg/scheduledjobs/schedulebase/util.go index ee0458422ded..c4928f1e2ef3 100644 --- a/pkg/scheduledjobs/schedulebase/util.go +++ b/pkg/scheduledjobs/schedulebase/util.go @@ -191,13 +191,13 @@ func FullyQualifyTables( } // Resolve the database. - dbDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, tableDesc.GetParentID()) + dbDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, tableDesc.GetParentID()) if err != nil { return err } // Resolve the schema. - schemaDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Schema(ctx, tableDesc.GetParentSchemaID()) + schemaDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Schema(ctx, tableDesc.GetParentSchemaID()) if err != nil { return err } diff --git a/pkg/server/status.go b/pkg/server/status.go index 3a223b4643e9..f71b82a3eb41 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -2469,7 +2469,7 @@ func (s *statusServer) HotRangesV2( } else { if err = s.sqlServer.distSQLServer.InternalExecutorFactory.DescsTxnWithExecutor( ctx, s.db, nil, func(ctx context.Context, txn *kv.Txn, col *descs.Collection, ie sqlutil.InternalExecutor) error { - desc, err := col.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, descpb.ID(tableID)) + desc, err := col.ByID(txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(tableID)) if err != nil { return errors.Wrapf(err, "cannot get table descriptor with tableID: %d, %s", tableID, r.Desc) } @@ -2487,13 +2487,13 @@ func (s *statusServer) HotRangesV2( } } - if dbDesc, err := col.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, desc.GetParentID()); err != nil { + if dbDesc, err := col.ByID(txn).WithoutNonPublic().Get().Database(ctx, desc.GetParentID()); err != nil { log.Warningf(ctx, "cannot get database by descriptor ID: %s: %v", r.Desc, err) } else { dbName = dbDesc.GetName() } - if schemaDesc, err := col.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Schema(ctx, desc.GetParentSchemaID()); err != nil { + if schemaDesc, err := col.ByID(txn).WithoutNonPublic().Get().Schema(ctx, desc.GetParentSchemaID()); err != nil { log.Warningf(ctx, "cannot get schema name for range descriptor: %s: %v", r.Desc, err) } else { schemaName = schemaDesc.GetName() diff --git a/pkg/spanconfig/spanconfigreconciler/reconciler.go b/pkg/spanconfig/spanconfigreconciler/reconciler.go index 952cd401599e..c290e70cf2c3 100644 --- a/pkg/spanconfig/spanconfigreconciler/reconciler.go +++ b/pkg/spanconfig/spanconfigreconciler/reconciler.go @@ -642,7 +642,7 @@ func (r *incrementalReconciler) filterForMissingTableIDs( continue // nothing to do } - desc, err := descsCol.ByID(txn).WithoutLeased().Immutable().Desc(ctx, descriptorUpdate.ID) + desc, err := descsCol.ByID(txn).Get().Desc(ctx, descriptorUpdate.ID) considerAsMissing := false if errors.Is(err, catalog.ErrDescriptorNotFound) { diff --git a/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go b/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go index ba97cbeaec1d..8a082173ced7 100644 --- a/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go +++ b/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go @@ -248,7 +248,7 @@ func (s *SQLTranslator) generateSpanConfigurations( } // We're dealing with a SQL object. - desc, err := descsCol.ByID(txn).WithoutLeased().Immutable().Desc(ctx, id) + desc, err := descsCol.ByID(txn).Get().Desc(ctx, id) if err != nil { if errors.Is(err, catalog.ErrDescriptorNotFound) { return nil, nil // the descriptor has been deleted; nothing to do here @@ -529,7 +529,7 @@ func (s *SQLTranslator) findDescendantLeafIDs( func (s *SQLTranslator) findDescendantLeafIDsForDescriptor( ctx context.Context, id descpb.ID, txn *kv.Txn, descsCol *descs.Collection, ) (descpb.IDs, error) { - desc, err := descsCol.ByID(txn).WithoutLeased().Immutable().Desc(ctx, id) + desc, err := descsCol.ByID(txn).Get().Desc(ctx, id) if err != nil { if errors.Is(err, catalog.ErrDescriptorNotFound) { return nil, nil // the descriptor has been deleted; nothing to do here diff --git a/pkg/spanconfig/spanconfigtestutils/spanconfigtestcluster/tenant_state.go b/pkg/spanconfig/spanconfigtestutils/spanconfigtestcluster/tenant_state.go index d6a1cfea0bd3..15fb612ed2fa 100644 --- a/pkg/spanconfig/spanconfigtestutils/spanconfigtestcluster/tenant_state.go +++ b/pkg/spanconfig/spanconfigtestutils/spanconfigtestcluster/tenant_state.go @@ -212,7 +212,7 @@ func (s *Tenant) LookupTableDescriptorByID( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { var err error - desc, err = descsCol.ByID(txn).WithoutLeased().Immutable().Table(ctx, id) + desc, err = descsCol.ByID(txn).Get().Table(ctx, id) return err })) return desc diff --git a/pkg/sql/alter_database.go b/pkg/sql/alter_database.go index a504879557b6..603b28dcb01d 100644 --- a/pkg/sql/alter_database.go +++ b/pkg/sql/alter_database.go @@ -221,7 +221,7 @@ func (n *alterDatabaseAddRegionNode) startExec(params runParams) error { } // Get the type descriptor for the multi-region enum. - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, n.desc.RegionConfig.RegionEnumID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, n.desc.RegionConfig.RegionEnumID) if err != nil { return err } @@ -380,7 +380,7 @@ func (p *planner) AlterDatabaseDropRegion( if err != nil { return nil, err } - typeDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeID) + typeDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeID) if err != nil { return nil, err } @@ -419,7 +419,7 @@ func (p *planner) AlterDatabaseDropRegion( // detritus multi-region type descriptor. This includes both the // type descriptor and its array counterpart. toDrop = append(toDrop, typeDesc) - arrayTypeDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeDesc.ArrayTypeID) + arrayTypeDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeDesc.ArrayTypeID) if err != nil { return nil, err } @@ -588,7 +588,7 @@ func (n *alterDatabaseDropRegionNode) startExec(params runParams) error { if n.n == nil { return nil } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, n.desc.RegionConfig.RegionEnumID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, n.desc.RegionConfig.RegionEnumID) if err != nil { return err } @@ -742,7 +742,7 @@ func (n *alterDatabasePrimaryRegionNode) switchPrimaryRegion(params runParams) e } // Get the type descriptor for the multi-region enum. - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, n.desc.RegionConfig.RegionEnumID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, n.desc.RegionConfig.RegionEnumID) if err != nil { return err } @@ -1399,7 +1399,7 @@ func (n *alterDatabaseAddSuperRegion) startExec(params runParams) error { if err != nil { return err } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, typeID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, typeID) if err != nil { return err } @@ -1478,7 +1478,7 @@ func (n *alterDatabaseDropSuperRegion) startExec(params runParams) error { if err != nil { return err } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, typeID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, typeID) if err != nil { return err } @@ -1543,7 +1543,7 @@ func (p *planner) getSuperRegionsForDatabase( if err != nil { return nil, err } - typeDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeID) + typeDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeID) if err != nil { return nil, err } @@ -1606,7 +1606,7 @@ func (n *alterDatabaseAlterSuperRegion) startExec(params runParams) error { if err != nil { return err } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, typeID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, typeID) if err != nil { return err } @@ -1798,7 +1798,7 @@ func (n *alterDatabaseSecondaryRegion) startExec(params runParams) error { } // Get the type descriptor for the multi-region enum. - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, n.desc.RegionConfig.RegionEnumID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, n.desc.RegionConfig.RegionEnumID) if err != nil { return err } @@ -1908,7 +1908,7 @@ func (n *alterDatabaseDropSecondaryRegion) startExec(params runParams) error { if err != nil { return err } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, typeID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, typeID) if err != nil { return err } @@ -2085,7 +2085,7 @@ func (n *alterDatabaseSetZoneConfigExtensionNode) startExec(params runParams) er if err != nil { return err } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, typeID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, typeID) if err != nil { return err } diff --git a/pkg/sql/alter_default_privileges.go b/pkg/sql/alter_default_privileges.go index fd55dcf1a525..ae6349d0ff7b 100644 --- a/pkg/sql/alter_default_privileges.go +++ b/pkg/sql/alter_default_privileges.go @@ -89,7 +89,7 @@ func (p *planner) alterDefaultPrivileges( if immSchema.SchemaKind() != catalog.SchemaUserDefined { return nil, pgerror.Newf(pgcode.InvalidParameterValue, "%s is not a physical schema", immSchema.GetName()) } - mutableSchemaDesc, err := p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, immSchema.GetID()) + mutableSchemaDesc, err := p.Descriptors().MutableByID(p.txn).Schema(ctx, immSchema.GetID()) if err != nil { return nil, err } diff --git a/pkg/sql/alter_function.go b/pkg/sql/alter_function.go index 470ddc936038..95df79da02b5 100644 --- a/pkg/sql/alter_function.go +++ b/pkg/sql/alter_function.go @@ -133,7 +133,7 @@ func (n *alterFunctionRenameNode) startExec(params runParams) error { return err } - scDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Schema(params.ctx, fnDesc.GetParentSchemaID()) + scDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Schema(params.ctx, fnDesc.GetParentSchemaID()) if err != nil { return err } @@ -302,7 +302,7 @@ func (n *alterFunctionSetSchemaNode) startExec(params runParams) error { // No-op if moving to the same schema. return nil } - targetSc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Schema(params.ctx, sc.GetID()) + targetSc, err := params.p.Descriptors().MutableByID(params.p.txn).Schema(params.ctx, sc.GetID()) if err != nil { return err } @@ -322,7 +322,7 @@ func (n *alterFunctionSetSchemaNode) startExec(params runParams) error { ) } - sourceSc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Schema(params.ctx, fnDesc.GetParentSchemaID()) + sourceSc, err := params.p.Descriptors().MutableByID(params.p.txn).Schema(params.ctx, fnDesc.GetParentSchemaID()) if err != nil { return err } diff --git a/pkg/sql/alter_schema.go b/pkg/sql/alter_schema.go index 5133cd12b152..c0386b613c0b 100644 --- a/pkg/sql/alter_schema.go +++ b/pkg/sql/alter_schema.go @@ -18,7 +18,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc" "github.com/cockroachdb/cockroach/pkg/sql/decodeusername" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" @@ -74,7 +73,7 @@ func (p *planner) AlterSchema(ctx context.Context, n *tree.AlterSchema) (planNod case catalog.SchemaPublic, catalog.SchemaVirtual, catalog.SchemaTemporary: return nil, pgerror.Newf(pgcode.InvalidSchemaName, "cannot modify schema %q", n.Schema.String()) case catalog.SchemaUserDefined: - desc, err := p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, schema.GetID()) + desc, err := p.Descriptors().MutableByID(p.txn).Schema(ctx, schema.GetID()) if err != nil { return nil, err } @@ -124,9 +123,7 @@ func (n *alterSchemaNode) startExec(params runParams) error { } if err := maybeFailOnDependentDescInRename( - params.ctx, params.p, n.db, n.desc, func(b descs.ByIDGetterBuilder) descs.ByIDGetterBuilder { - return b.WithoutNonPublic().WithoutLeased() - }, catalog.Schema, + params.ctx, params.p, n.db, n.desc, false /* withLeased */, catalog.Schema, ); err != nil { return err } @@ -174,7 +171,7 @@ func (p *planner) alterSchemaOwner( } // The user must also have CREATE privilege on the schema's database. - parentDBDesc, err := p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, scDesc.GetParentID()) + parentDBDesc, err := p.Descriptors().MutableByID(p.txn).Desc(ctx, scDesc.GetParentID()) if err != nil { return err } diff --git a/pkg/sql/alter_table.go b/pkg/sql/alter_table.go index 6a67290ef502..d4d089b04773 100644 --- a/pkg/sql/alter_table.go +++ b/pkg/sql/alter_table.go @@ -1493,7 +1493,7 @@ func (p *planner) updateFKBackReferenceName( if tableDesc.ID == ref.ReferencedTableID { referencedTableDesc = tableDesc } else { - lookup, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, ref.ReferencedTableID) + lookup, err := p.Descriptors().MutableByID(p.txn).Table(ctx, ref.ReferencedTableID) if err != nil { return errors.Wrapf(err, "error resolving referenced table ID %d", ref.ReferencedTableID) } diff --git a/pkg/sql/alter_table_locality.go b/pkg/sql/alter_table_locality.go index dadf6d905298..63883ef7cadf 100644 --- a/pkg/sql/alter_table_locality.go +++ b/pkg/sql/alter_table_locality.go @@ -70,7 +70,7 @@ func (p *planner) AlterTableLocality( } // Ensure that the database is multi-region enabled. - dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, tableDesc.GetParentID()) + dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, tableDesc.GetParentID()) if err != nil { return nil, err } @@ -114,7 +114,7 @@ func (n *alterTableSetLocalityNode) alterTableLocalityGlobalToRegionalByTable( ) } - dbDesc, err := params.p.Descriptors().ByID(params.p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(params.ctx, n.tableDesc.ParentID) + dbDesc, err := params.p.Descriptors().ByID(params.p.txn).WithoutNonPublic().Get().Database(params.ctx, n.tableDesc.ParentID) if err != nil { return err } @@ -176,7 +176,7 @@ func (n *alterTableSetLocalityNode) alterTableLocalityRegionalByTableToRegionalB ) } - dbDesc, err := params.p.Descriptors().ByID(params.p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(params.ctx, n.tableDesc.ParentID) + dbDesc, err := params.p.Descriptors().ByID(params.p.txn).WithoutNonPublic().Get().Database(params.ctx, n.tableDesc.ParentID) if err != nil { return err } @@ -653,7 +653,7 @@ func setNewLocalityConfig( descsCol *descs.Collection, ) error { getMultiRegionTypeDesc := func() (*typedesc.Mutable, error) { - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, desc.GetParentID()) if err != nil { return nil, err } @@ -662,7 +662,7 @@ func setNewLocalityConfig( if err != nil { return nil, err } - return descsCol.ByID(txn).Mutable().Type(ctx, regionEnumID) + return descsCol.MutableByID(txn).Type(ctx, regionEnumID) } // If there was a dependency before on the multi-region enum before the // new locality is set, we must unlink the dependency. diff --git a/pkg/sql/alter_type.go b/pkg/sql/alter_type.go index 8575804a523b..9faf3a4cc3ae 100644 --- a/pkg/sql/alter_type.go +++ b/pkg/sql/alter_type.go @@ -253,7 +253,7 @@ func (p *planner) renameType(ctx context.Context, n *alterTypeNode, newName stri if err != nil { return err } - arrayDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, n.desc.ArrayTypeID) + arrayDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, n.desc.ArrayTypeID) if err != nil { return err } @@ -373,7 +373,7 @@ func (p *planner) setTypeSchema(ctx context.Context, n *alterTypeNode, schema st return err } - arrayDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, n.desc.ArrayTypeID) + arrayDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, n.desc.ArrayTypeID) if err != nil { return err } @@ -405,7 +405,7 @@ func (p *planner) alterTypeOwner( typeDesc := n.desc oldOwner := typeDesc.GetPrivileges().Owner() - arrayDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeDesc.ArrayTypeID) + arrayDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeDesc.ArrayTypeID) if err != nil { return err } diff --git a/pkg/sql/authorization.go b/pkg/sql/authorization.go index a4ebd966fd58..93b677e723bd 100644 --- a/pkg/sql/authorization.go +++ b/pkg/sql/authorization.go @@ -745,7 +745,7 @@ func (p *planner) canCreateOnSchema( user username.SQLUsername, checkPublicSchema shouldCheckPublicSchema, ) error { - scDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Schema(ctx, schemaID) + scDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Schema(ctx, schemaID) if err != nil { return err } @@ -757,7 +757,7 @@ func (p *planner) canCreateOnSchema( // The caller wishes to skip this check. return nil } - dbDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Database(ctx, dbID) + dbDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Database(ctx, dbID) if err != nil { return err } @@ -849,7 +849,7 @@ func (p *planner) HasOwnershipOnSchema( // Only the node user has ownership over the system database. return p.User().IsNodeUser(), nil } - scDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Schema(ctx, schemaID) + scDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Schema(ctx, schemaID) if err != nil { return false, err } diff --git a/pkg/sql/backfill.go b/pkg/sql/backfill.go index 1d502fc01b83..8b017976f1e8 100644 --- a/pkg/sql/backfill.go +++ b/pkg/sql/backfill.go @@ -450,7 +450,7 @@ func (sc *SchemaChanger) dropConstraints( // Create update closure for the table and all other tables with backreferences. if err := sc.txn(ctx, func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - scTable, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + scTable, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } @@ -480,7 +480,7 @@ func (sc *SchemaChanger) dropConstraints( if def.Name != constraint.GetName() { continue } - backrefTable, err := descsCol.ByID(txn).Mutable().Table(ctx, fk.GetReferencedTableID()) + backrefTable, err := descsCol.MutableByID(txn).Table(ctx, fk.GetReferencedTableID()) if err != nil { return err } @@ -543,11 +543,11 @@ func (sc *SchemaChanger) dropConstraints( if err := sc.txn(ctx, func( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) (err error) { - if tableDescs[sc.descID], err = descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, sc.descID); err != nil { + if tableDescs[sc.descID], err = descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, sc.descID); err != nil { return err } for id := range fksByBackrefTable { - desc, err := descsCol.ByID(txn).WithoutOffline().Immutable().Table(ctx, id) + desc, err := descsCol.ByIDWithLeased(txn).WithoutOffline().Get().Table(ctx, id) if err != nil { return err } @@ -586,7 +586,7 @@ func (sc *SchemaChanger) addConstraints( if err := sc.txn(ctx, func( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { - scTable, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + scTable, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } @@ -635,7 +635,7 @@ func (sc *SchemaChanger) addConstraints( } if !foundExisting { scTable.OutboundFKs = append(scTable.OutboundFKs, *fk.ForeignKeyDesc()) - backrefTable, err := descsCol.ByID(txn).Mutable().Table(ctx, fk.GetReferencedTableID()) + backrefTable, err := descsCol.MutableByID(txn).Table(ctx, fk.GetReferencedTableID()) if err != nil { return err } @@ -732,7 +732,7 @@ func (sc *SchemaChanger) validateConstraints( if err := sc.fixedTimestampTxn(ctx, readAsOf, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { - tableDesc, err = descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, sc.descID) + tableDesc, err = descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, sc.descID) return err }); err != nil { return err @@ -816,7 +816,7 @@ func (sc *SchemaChanger) validateConstraints( func (sc *SchemaChanger) getTableVersion( ctx context.Context, txn *kv.Txn, tc *descs.Collection, version descpb.DescriptorVersion, ) (catalog.TableDescriptor, error) { - tableDesc, err := tc.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, sc.descID) + tableDesc, err := tc.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, sc.descID) if err != nil { return nil, err } @@ -1369,7 +1369,7 @@ func (sc *SchemaChanger) updateJobRunningStatus( ) (tableDesc catalog.TableDescriptor, err error) { err = DescsTxn(ctx, sc.execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { // Read table descriptor without holding a lease. - tableDesc, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, sc.descID) + tableDesc, err = col.ByID(txn).Get().Table(ctx, sc.descID) if err != nil { return err } @@ -1427,7 +1427,7 @@ func (sc *SchemaChanger) validateIndexes(ctx context.Context) error { if err := sc.fixedTimestampTxn(ctx, readAsOf, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - tableDesc, err = descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, sc.descID) + tableDesc, err = descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, sc.descID) return err }); err != nil { return err @@ -2208,7 +2208,7 @@ func (sc *SchemaChanger) mergeFromTemporaryIndex( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { var err error - tbl, err = descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + tbl, err = descsCol.MutableByID(txn).Table(ctx, sc.descID) return err }); err != nil { return err @@ -2229,7 +2229,7 @@ func (sc *SchemaChanger) runStateMachineAfterTempIndexMerge(ctx context.Context) return sc.txn(ctx, func( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { - tbl, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + tbl, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } @@ -2534,7 +2534,7 @@ func runSchemaChangesInTxn( if selfReference { referencedTableDesc = tableDesc } else { - lookup, err := planner.Descriptors().ByID(planner.Txn()).Mutable().Table(ctx, fk.GetReferencedTableID()) + lookup, err := planner.Descriptors().MutableByID(planner.Txn()).Table(ctx, fk.GetReferencedTableID()) if err != nil { return errors.Wrapf(err, "error resolving referenced table ID %d", fk.GetReferencedTableID()) } @@ -2623,7 +2623,7 @@ func getTargetTablesAndFk( if fk == nil { return nil, nil, nil, errors.AssertionFailedf("foreign key %s does not exist", fkName) } - targetTable, err = descsCol.ByID(txn).WithoutLeased().Immutable().Table(ctx, fk.ReferencedTableID) + targetTable, err = descsCol.ByID(txn).Get().Table(ctx, fk.ReferencedTableID) if err != nil { return nil, nil, nil, err } diff --git a/pkg/sql/catalog/descriptor.go b/pkg/sql/catalog/descriptor.go index 1de753eb48b8..4ee814d2d588 100644 --- a/pkg/sql/catalog/descriptor.go +++ b/pkg/sql/catalog/descriptor.go @@ -591,13 +591,13 @@ type TableDescriptor interface { // HasColumnBackfillMutation returns whether the table has any queued column // mutations that require a backfill. HasColumnBackfillMutation() bool - // MakeFirstMutationPublic creates a Mutable from the - // immutable by making the first mutation public. + // MakeFirstMutationPublic creates a descriptor by making the first + // mutation public. // This is super valuable when trying to run SQL over data associated // with a schema mutation that is still not yet public: Data validation, // error reporting. MakeFirstMutationPublic(...MutationPublicationFilter) (TableDescriptor, error) - // MakePublic creates a Mutable from the immutable by making the it public. + // MakePublic creates a descriptor by making the state public. MakePublic() TableDescriptor // AllMutations returns all of the table descriptor's mutations. AllMutations() []Mutation diff --git a/pkg/sql/catalog/descs/collection_test.go b/pkg/sql/catalog/descs/collection_test.go index e6c858645135..723c8e99eff3 100644 --- a/pkg/sql/catalog/descs/collection_test.go +++ b/pkg/sql/catalog/descs/collection_test.go @@ -237,7 +237,7 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { require.NoError(t, err) dbID := mut.GetID() - byID, err := descriptors.ByID(txn).Mutable().Desc(ctx, dbID) + byID, err := descriptors.MutableByID(txn).Desc(ctx, dbID) require.NoError(t, err) require.Same(t, mut, byID) @@ -252,7 +252,7 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { require.Equal(t, dbID, immByName.GetID()) require.Equal(t, mut.OriginalVersion(), immByName.GetVersion()) - immByID, err := descriptors.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, dbID) + immByID, err := descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, dbID) require.NoError(t, err) require.Same(t, immByName, immByID) @@ -282,7 +282,7 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { require.Equal(t, mut.GetVersion(), immByNameAfter.GetVersion()) require.Equal(t, mut.ImmutableCopy().DescriptorProto(), immByNameAfter.DescriptorProto()) - immByIDAfter, err := descriptors.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, dbID) + immByIDAfter, err := descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, dbID) require.NoError(t, err) require.Same(t, immByNameAfter, immByIDAfter) @@ -310,7 +310,7 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { require.Same(t, schema, resolved) - byID, err := descriptors.ByID(txn).Mutable().Desc(ctx, schema.GetID()) + byID, err := descriptors.MutableByID(txn).Desc(ctx, schema.GetID()) require.NoError(t, err) require.Same(t, schema, byID) @@ -334,7 +334,7 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { require.Same(t, tab, resolved) - byID, err := descriptors.ByID(txn).Mutable().Desc(ctx, tab.GetID()) + byID, err := descriptors.MutableByID(txn).Desc(ctx, tab.GetID()) require.NoError(t, err) require.Same(t, tab, byID) @@ -357,7 +357,7 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { require.Same(t, typ, resolved) - byID, err := descriptors.ByID(txn).Mutable().Type(ctx, typ.GetID()) + byID, err := descriptors.MutableByID(txn).Type(ctx, typ.GetID()) require.NoError(t, err) require.Same(t, typ, byID) @@ -413,12 +413,12 @@ func TestSyntheticDescriptorResolution(t *testing.T) { // Resolution by ID. - desc, err = descriptors.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, tableID) + desc, err = descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, tableID) require.NoError(t, err) require.Equal(t, "bar", desc.PublicColumns()[0].GetName()) // Attempting to resolve the table mutably is not allowed. - _, err = descriptors.ByID(txn).Mutable().Table(ctx, tableID) + _, err = descriptors.MutableByID(txn).Table(ctx, tableID) require.EqualError(t, err, fmt.Sprintf("attempted mutable access of synthetic descriptor %d", tableID)) return nil @@ -558,7 +558,7 @@ func TestCollectionPreservesPostDeserializationChanges(t *testing.T) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, col *descs.Collection, ) error { - descs, err := col.ByID(txn).Mutable().Descs(ctx, []descpb.ID{dbID, scID, typID, tabID}) + descs, err := col.MutableByID(txn).Descs(ctx, []descpb.ID{dbID, scID, typID, tabID}) if err != nil { return err } @@ -576,7 +576,7 @@ func TestCollectionPreservesPostDeserializationChanges(t *testing.T) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, col *descs.Collection, ) error { - immuts, err := col.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Descs(ctx, []descpb.ID{dbID, scID, typID, tabID}) + immuts, err := col.ByID(txn).WithoutNonPublic().Get().Descs(ctx, []descpb.ID{dbID, scID, typID, tabID}) if err != nil { return err } @@ -593,7 +593,7 @@ func TestCollectionPreservesPostDeserializationChanges(t *testing.T) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, col *descs.Collection, ) error { - muts, err := col.ByID(txn).Mutable().Descs(ctx, []descpb.ID{dbID, scID, typID, tabID}) + muts, err := col.MutableByID(txn).Descs(ctx, []descpb.ID{dbID, scID, typID, tabID}) if err != nil { return err } @@ -1143,7 +1143,7 @@ SELECT id ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ie sqlutil.InternalExecutor, ) error { checkImmutableDescriptor := func(id descpb.ID, expName string, f func(t *testing.T, desc catalog.Descriptor)) error { - tabImm, err := descriptors.ByID(txn).WithoutOffline().Immutable().Table(ctx, id) + tabImm, err := descriptors.ByIDWithLeased(txn).WithoutOffline().Get().Table(ctx, id) require.NoError(t, err) require.Equal(t, expName, tabImm.GetName()) f(t, tabImm) @@ -1157,7 +1157,7 @@ SELECT id // Modify the table to have the name "bar", synthetically { - tab, err := descriptors.ByID(txn).Mutable().Table(ctx, tabID) + tab, err := descriptors.MutableByID(txn).Table(ctx, tabID) if err != nil { return err } @@ -1174,13 +1174,13 @@ SELECT id return err } // Attempt to retrieve the mutable descriptor, validate the error. - _, err := descriptors.ByID(txn).Mutable().Table(ctx, tabID) + _, err := descriptors.MutableByID(txn).Table(ctx, tabID) require.Regexp(t, `attempted mutable access of synthetic descriptor \d+`, err) descriptors.ResetSyntheticDescriptors() // Retrieve the mutable descriptor, find the unmodified "foo". // Then modify the name to "baz" and write it. { - tabMut, err := descriptors.ByID(txn).Mutable().Table(ctx, tabID) + tabMut, err := descriptors.MutableByID(txn).Table(ctx, tabID) require.NoError(t, err) require.Equal(t, "foo", tabMut.GetName()) tabMut.Name = "baz" @@ -1213,7 +1213,7 @@ SELECT id newDB := dbdesc.NewInitial(newDBID, "newDB", username.RootUserName()) descriptors.AddSyntheticDescriptor(newDB) - curDatabase, err := descriptors.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, curDatabaseID) + curDatabase, err := descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, curDatabaseID) if err != nil { return err } @@ -1237,7 +1237,7 @@ SELECT id } // Rename a schema synthetically, make sure that that propagates. - scDesc, err := descriptors.ByID(txn).Mutable().Schema(ctx, scID) + scDesc, err := descriptors.MutableByID(txn).Schema(ctx, scID) if err != nil { return err } diff --git a/pkg/sql/catalog/descs/dist_sql_type_resolver.go b/pkg/sql/catalog/descs/dist_sql_type_resolver.go index 72e5c93df503..1e5676bceafd 100644 --- a/pkg/sql/catalog/descs/dist_sql_type_resolver.go +++ b/pkg/sql/catalog/descs/dist_sql_type_resolver.go @@ -34,7 +34,7 @@ type DistSQLTypeResolver struct { // NewDistSQLTypeResolver creates a new DistSQLTypeResolver. func NewDistSQLTypeResolver(descs *Collection, txn *kv.Txn) DistSQLTypeResolver { return DistSQLTypeResolver{ - g: descs.ByID(txn).Immutable(), + g: descs.ByIDWithLeased(txn).Get(), } } diff --git a/pkg/sql/catalog/descs/getters.go b/pkg/sql/catalog/descs/getters.go index e23a76f85d66..cc41fe37c205 100644 --- a/pkg/sql/catalog/descs/getters.go +++ b/pkg/sql/catalog/descs/getters.go @@ -519,20 +519,32 @@ func defaultUnleasedFlags() (f getterFlags) { return f } -// ByID returns a ByIDGetterBuilder. +// ByID returns a ByIDGetterBuilder set up to look up descriptors by ID +// in all layers except the leased descriptors layer. To opt in to the +// leased descriptors, use ByIDWithLeased instead. func (tc *Collection) ByID(txn *kv.Txn) ByIDGetterBuilder { - return ByIDGetterBuilder(makeGetterBase(txn, tc, defaultFlags())) + b := tc.ByIDWithLeased(txn) + b.flags.layerFilters.withoutLeased = true + return b } -// ByIDGetterBuilder is a builder object for ByIDGetter and MutableByIDGetter. -type ByIDGetterBuilder getterBase +// ByIDWithLeased is like ByID but also looks up in the leased descriptors +// layer. This may save a round-trip to KV at the expense of the descriptor +// being slightly stale (one version off). +func (tc *Collection) ByIDWithLeased(txn *kv.Txn) ByIDGetterBuilder { + return ByIDGetterBuilder(makeGetterBase(txn, tc, getterFlags{})) +} -// WithFlags configures the ByIDGetterBuilder with the given flags. -func (b ByIDGetterBuilder) WithFlags(flags tree.CommonLookupFlags) ByIDGetterBuilder { - b.flags = fromCommonFlags(flags) - return b +// MutableByID returns a MutableByIDGetter. +// This convenience method exists because mutable lookups never require +// any customization. +func (tc *Collection) MutableByID(txn *kv.Txn) MutableByIDGetter { + return tc.ByID(txn).mutable() } +// ByIDGetterBuilder is a builder object for ByIDGetter and MutableByIDGetter. +type ByIDGetterBuilder getterBase + // WithoutSynthetic configures the ByIDGetterBuilder to bypass the synthetic // layer. This is useful mainly for the declarative schema changer, which is // the main client of this layer. @@ -541,13 +553,6 @@ func (b ByIDGetterBuilder) WithoutSynthetic() ByIDGetterBuilder { return b } -// WithoutLeased configures the ByIDGetterBuilder to bypass the leasing layer. -// The leasing layer may contain descriptors which are slightly stale. -func (b ByIDGetterBuilder) WithoutLeased() ByIDGetterBuilder { - b.flags.layerFilters.withoutLeased = true - return b -} - // WithoutDropped configures the ByIDGetterBuilder to error on descriptors // which are in a dropped state. func (b ByIDGetterBuilder) WithoutDropped() ByIDGetterBuilder { @@ -578,8 +583,8 @@ func (b ByIDGetterBuilder) WithoutOtherParent(parentID catid.DescID) ByIDGetterB return b } -// Mutable builds a MutableByIDGetter. -func (b ByIDGetterBuilder) Mutable() MutableByIDGetter { +// mutable builds a MutableByIDGetter. +func (b ByIDGetterBuilder) mutable() MutableByIDGetter { b.flags.isOptional = false b.flags.isMutable = true b.flags.layerFilters.withoutLeased = true @@ -588,8 +593,8 @@ func (b ByIDGetterBuilder) Mutable() MutableByIDGetter { return MutableByIDGetter(b) } -// Immutable builds a ByIDGetter. -func (b ByIDGetterBuilder) Immutable() ByIDGetter { +// Get builds a ByIDGetter. +func (b ByIDGetterBuilder) Get() ByIDGetter { if b.flags.isMutable { b.flags.layerFilters.withoutLeased = true b.flags.isMutable = false diff --git a/pkg/sql/catalog/descs/helpers.go b/pkg/sql/catalog/descs/helpers.go index d11a04c2d4ee..0e6b7b42b01f 100644 --- a/pkg/sql/catalog/descs/helpers.go +++ b/pkg/sql/catalog/descs/helpers.go @@ -26,7 +26,7 @@ import ( func GetObjectName( ctx context.Context, txn *kv.Txn, tc *Collection, obj catalog.Descriptor, ) (tree.ObjectName, error) { - g := tc.ByID(txn).Immutable() + g := tc.ByIDWithLeased(txn).Get() sc, err := g.Schema(ctx, obj.GetParentSchemaID()) if err != nil { return nil, err diff --git a/pkg/sql/catalog/hydrateddesccache/hydratedcache.go b/pkg/sql/catalog/hydrateddesccache/hydratedcache.go index f974ec78cf2b..61dcb1a549de 100644 --- a/pkg/sql/catalog/hydrateddesccache/hydratedcache.go +++ b/pkg/sql/catalog/hydrateddesccache/hydratedcache.go @@ -242,7 +242,7 @@ func (c *Cache) GetHydratedSchemaDescriptor( return hydratedDesc.(catalog.SchemaDescriptor), nil } -// GetHydratedDescriptor returns an Immutable copy with the types hydrated. It +// GetHydratedDescriptor returns a descriptor copy with the types hydrated. It // may use a cached copy but all of the relevant type descriptors will be // retrieved via the TypeDescriptorResolver. Note that if the given descriptor // is modified, nil will be returned. If any of the types used by the descriptor diff --git a/pkg/sql/catalog/ingesting/privileges.go b/pkg/sql/catalog/ingesting/privileges.go index c34da0e6084b..0e4758090cec 100644 --- a/pkg/sql/catalog/ingesting/privileges.go +++ b/pkg/sql/catalog/ingesting/privileges.go @@ -115,7 +115,7 @@ func getIngestingPrivilegesForTableOrSchema( privilege.ListFromBitField(u.Privileges, privilegeType).ToBitField() } } else if descCoverage == tree.RequestedDescriptors { - parentDB, err := descsCol.ByID(txn).WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + parentDB, err := descsCol.ByID(txn).Get().Database(ctx, desc.GetParentID()) if err != nil { return nil, errors.Wrapf(err, "failed to lookup parent DB %d", errors.Safe(desc.GetParentID())) } @@ -141,7 +141,7 @@ func getIngestingPrivilegesForTableOrSchema( } else { // If we are restoring into an existing schema, resolve it, and fetch // its default privileges. - parentSchema, err := descsCol.ByID(txn).WithoutLeased().Immutable().Schema(ctx, desc.GetParentSchemaID()) + parentSchema, err := descsCol.ByID(txn).Get().Schema(ctx, desc.GetParentSchemaID()) if err != nil { return nil, errors.Wrapf(err, "failed to lookup parent schema %d", errors.Safe(desc.GetParentSchemaID())) diff --git a/pkg/sql/catalog/ingesting/write_descs.go b/pkg/sql/catalog/ingesting/write_descs.go index e55af5a0a8b7..f3da1865f58c 100644 --- a/pkg/sql/catalog/ingesting/write_descs.go +++ b/pkg/sql/catalog/ingesting/write_descs.go @@ -213,7 +213,7 @@ func WriteDescriptors( if mut, ok := fn.(*funcdesc.Mutable); ok { mut.Privileges = updatedPrivileges } else { - log.Fatalf(ctx, "wrong type for function %d, %T, expected funcdesc.Mutable", fn.GetID(), fn) + log.Fatalf(ctx, "wrong type for function %d, %T, expected Mutable", fn.GetID(), fn) } } if err := descsCol.WriteDescToBatch( @@ -239,7 +239,7 @@ func WriteDescriptors( func processTableForMultiRegion( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, table catalog.TableDescriptor, ) error { - dbDesc, err := descsCol.ByID(txn).WithoutDropped().WithoutLeased().Immutable().Database(ctx, table.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutDropped().Get().Database(ctx, table.GetParentID()) if err != nil { return err } diff --git a/pkg/sql/catalog/lease/lease_test.go b/pkg/sql/catalog/lease/lease_test.go index 355e0e248a36..c3a6b9a7545c 100644 --- a/pkg/sql/catalog/lease/lease_test.go +++ b/pkg/sql/catalog/lease/lease_test.go @@ -86,7 +86,7 @@ func init() { ctx context.Context, t *testing.T, s serverutils.TestServerInterface, id descpb.ID, ) { require.NoError(t, sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - t, err := col.ByID(txn).Mutable().Table(ctx, id) + t, err := col.MutableByID(txn).Table(ctx, id) if err != nil { return err } @@ -2437,7 +2437,7 @@ func TestLeaseWithOfflineTables(t *testing.T) { flags := tree.ObjectLookupFlagsWithRequiredTableKind(tree.ResolveRequireTableDesc) flags.CommonLookupFlags.IncludeOffline = true flags.CommonLookupFlags.IncludeDropped = true - desc, err := descsCol.ByID(txn).Mutable().Table(ctx, testTableID()) + desc, err := descsCol.MutableByID(txn).Table(ctx, testTableID()) require.NoError(t, err) require.Equal(t, desc.State, expected) desc.State = next diff --git a/pkg/sql/catalog/schemadesc/schema_desc.go b/pkg/sql/catalog/schemadesc/schema_desc.go index 4d8604bb07cc..05f6cacb0246 100644 --- a/pkg/sql/catalog/schemadesc/schema_desc.go +++ b/pkg/sql/catalog/schemadesc/schema_desc.go @@ -117,7 +117,7 @@ func formatSafeMessage(typeName string, desc catalog.SchemaDescriptor) string { // // Note: Today this isn't actually ever mutated but rather exists for a future // where we anticipate having a mutable copy of Schema descriptors. There's a -// large amount of space to question this `Mutable|ImmutableCopy` version of each +// large amount of space to question this version of each // descriptor type. Maybe it makes no sense but we're running with it for the // moment. This is an intermediate state on the road to descriptors being // handled outside of the catalog entirely as interfaces. diff --git a/pkg/sql/check.go b/pkg/sql/check.go index 9e53764c9668..c6322dbc5191 100644 --- a/pkg/sql/check.go +++ b/pkg/sql/check.go @@ -414,7 +414,7 @@ func (p *planner) RevalidateUniqueConstraintsInCurrentDB(ctx context.Context) er // rows in the table have unique values for every unique constraint defined on // the table. func (p *planner) RevalidateUniqueConstraintsInTable(ctx context.Context, tableID int) error { - tableDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(tableID)) + tableDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Table(ctx, descpb.ID(tableID)) if err != nil { return err } @@ -431,7 +431,7 @@ func (p *planner) RevalidateUniqueConstraintsInTable(ctx context.Context, tableI func (p *planner) RevalidateUniqueConstraint( ctx context.Context, tableID int, constraintName string, ) error { - tableDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(tableID)) + tableDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Table(ctx, descpb.ID(tableID)) if err != nil { return err } @@ -485,7 +485,7 @@ func (p *planner) RevalidateUniqueConstraint( func (p *planner) IsConstraintActive( ctx context.Context, tableID int, constraintName string, ) (bool, error) { - tableDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(tableID)) + tableDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Table(ctx, descpb.ID(tableID)) if err != nil { return false, err } @@ -755,7 +755,7 @@ func (p *planner) validateTTLScheduledJobInTable( // RepairTTLScheduledJobForTable is part of the EvalPlanner interface. func (p *planner) RepairTTLScheduledJobForTable(ctx context.Context, tableID int64) error { - tableDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, descpb.ID(tableID)) + tableDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, descpb.ID(tableID)) if err != nil { return err } diff --git a/pkg/sql/check_test.go b/pkg/sql/check_test.go index ae8b5957ace6..42d601330640 100644 --- a/pkg/sql/check_test.go +++ b/pkg/sql/check_test.go @@ -56,7 +56,7 @@ func TestValidateTTLScheduledJobs(t *testing.T) { require.NoError(t, sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { // We need the collection to read the descriptor from storage for // the subsequent write to succeed. - tableDesc, err = col.ByID(txn).Mutable().Table(ctx, tableDesc.GetID()) + tableDesc, err = col.MutableByID(txn).Table(ctx, tableDesc.GetID()) tableDesc.RowLevelTTL.ScheduleID = 0 tableDesc.Version++ if err != nil { diff --git a/pkg/sql/comment_on_schema.go b/pkg/sql/comment_on_schema.go index ec4c7c8c3224..978d243d0493 100644 --- a/pkg/sql/comment_on_schema.go +++ b/pkg/sql/comment_on_schema.go @@ -57,7 +57,7 @@ func (p *planner) CommentOnSchema(ctx context.Context, n *tree.CommentOnSchema) return nil, err } - schemaDesc, err := p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, db.GetSchemaID(n.Name.Schema())) + schemaDesc, err := p.Descriptors().MutableByID(p.txn).Schema(ctx, db.GetSchemaID(n.Name.Schema())) if err != nil { return nil, err } diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index 1c416842e351..7e738179c971 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -394,7 +394,7 @@ CREATE TABLE crdb_internal.super_regions ( if err != nil { return err } - typeDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Type(ctx, typeID) + typeDesc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Type(ctx, typeID) if err != nil { return err } @@ -499,7 +499,7 @@ CREATE TABLE crdb_internal.tables ( // INDEX(parent_id) WHERE drop_time IS NULL populate: func(ctx context.Context, unwrappedConstraint tree.Datum, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) (matched bool, err error) { dbID := descpb.ID(tree.MustBeDInt(unwrappedConstraint)) - db, err := p.byIDGetterBuilder().WithoutDropped().Immutable().Database(ctx, dbID) + db, err := p.byIDGetterBuilder().WithoutDropped().Get().Database(ctx, dbID) if err != nil { return false, err } @@ -2958,7 +2958,7 @@ CREATE TABLE crdb_internal.create_function_statements ( } } - fnDescs, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Descs(ctx, fnIDs) + fnDescs, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Descs(ctx, fnIDs) if err != nil { return err } @@ -4032,7 +4032,7 @@ CREATE TABLE crdb_internal.zones ( var table catalog.TableDescriptor if zs.Database != "" { - database, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, descpb.ID(id)) + database, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, descpb.ID(id)) if err != nil { return err } @@ -6462,7 +6462,7 @@ CREATE TABLE crdb_internal.index_spans ( // forEachTableDescAll() below. So we can't use p.LookupByID() // which only considers online tables. p.runWithOptions(resolveFlags{skipCache: true}, func() { - table, err = p.byIDGetterBuilder().Immutable().Table(ctx, descID) + table, err = p.byIDGetterBuilder().Get().Table(ctx, descID) }) if err != nil { return false, err @@ -6514,7 +6514,7 @@ CREATE TABLE crdb_internal.table_spans ( // forEachTableDescAll() below. So we can't use p.LookupByID() // which only considers online tables. p.runWithOptions(resolveFlags{skipCache: true}, func() { - table, err = p.byIDGetterBuilder().Immutable().Table(ctx, descID) + table, err = p.byIDGetterBuilder().Get().Table(ctx, descID) }) if err != nil { return false, err @@ -7064,7 +7064,7 @@ func convertContentionEventsToJSON( desc := p.Descriptors() var tableDesc catalog.TableDescriptor - tableDesc, err = desc.ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(tableID)) + tableDesc, err = desc.ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(tableID)) if err != nil { return nil, err } @@ -7074,12 +7074,12 @@ func convertContentionEventsToJSON( return nil, err } - dbDesc, err := desc.ByID(p.txn).WithoutNonPublic().Immutable().Database(ctx, tableDesc.GetParentID()) + dbDesc, err := desc.ByIDWithLeased(p.txn).WithoutNonPublic().Get().Database(ctx, tableDesc.GetParentID()) if err != nil { return nil, err } - schemaDesc, err := desc.ByID(p.txn).WithoutNonPublic().Immutable().Schema(ctx, tableDesc.GetParentSchemaID()) + schemaDesc, err := desc.ByIDWithLeased(p.txn).WithoutNonPublic().Get().Schema(ctx, tableDesc.GetParentSchemaID()) if err != nil { return nil, err } diff --git a/pkg/sql/create_function.go b/pkg/sql/create_function.go index 8126561d51f5..e3b6317b24d6 100644 --- a/pkg/sql/create_function.go +++ b/pkg/sql/create_function.go @@ -197,7 +197,7 @@ func (n *createFunctionNode) replaceFunction(udfDesc *funcdesc.Mutable, params r // Removing all existing references before adding new references. for _, id := range udfDesc.DependsOn { - backRefMutable, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Table(params.ctx, id) + backRefMutable, err := params.p.Descriptors().MutableByID(params.p.txn).Table(params.ctx, id) if err != nil { return err } @@ -326,7 +326,7 @@ func (n *createFunctionNode) addUDFReferences(udfDesc *funcdesc.Mutable, params // Read all referenced tables and update their dependencies. backRefMutables := make(map[descpb.ID]*tabledesc.Mutable) for _, id := range backrefTblIDs.Ordered() { - backRefMutable, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Table(params.ctx, id) + backRefMutable, err := params.p.Descriptors().MutableByID(params.p.txn).Table(params.ctx, id) if err != nil { return err } @@ -467,7 +467,7 @@ func makeFunctionParam( } func (p *planner) descIsTable(ctx context.Context, id descpb.ID) (bool, error) { - desc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Desc(ctx, id) + desc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Desc(ctx, id) if err != nil { return false, err } diff --git a/pkg/sql/create_function_test.go b/pkg/sql/create_function_test.go index b73716715349..afe4d0d03f20 100644 --- a/pkg/sql/create_function_test.go +++ b/pkg/sql/create_function_test.go @@ -65,7 +65,7 @@ CREATE SCHEMA test_sc; ) err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - funcDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 110) + funcDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 110) require.NoError(t, err) require.Equal(t, funcDesc.GetName(), "f") @@ -250,7 +250,7 @@ $$; ) err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - funcDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 112) + funcDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 112) require.NoError(t, err) require.Equal(t, funcDesc.GetName(), "f") @@ -293,7 +293,7 @@ $$; `) err = sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - funcDesc, err := col.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Function(ctx, 112) + funcDesc, err := col.ByID(txn).WithoutNonPublic().Get().Function(ctx, 112) require.NoError(t, err) require.Equal(t, funcDesc.GetName(), "f") diff --git a/pkg/sql/create_schema.go b/pkg/sql/create_schema.go index 70352ddbaa67..e2c36c810541 100644 --- a/pkg/sql/create_schema.go +++ b/pkg/sql/create_schema.go @@ -82,7 +82,7 @@ func CreateUserDefinedSchemaDescriptor( // and can't be in a dropping state. if schemaID != descpb.InvalidID { // Check if the object already exists in a dropped state - sc, err := descriptors.ByID(txn).WithoutLeased().Immutable().Schema(ctx, schemaID) + sc, err := descriptors.ByID(txn).Get().Schema(ctx, schemaID) if err != nil || sc.SchemaKind() != catalog.SchemaUserDefined { return nil, nil, err } diff --git a/pkg/sql/create_stats.go b/pkg/sql/create_stats.go index 3b5b9bb37a3d..f5e1c3af181a 100644 --- a/pkg/sql/create_stats.go +++ b/pkg/sql/create_stats.go @@ -204,7 +204,7 @@ func (n *createStatsNode) makeJobRecord(ctx context.Context) (*jobs.Record, erro fqTableName = n.p.ResolvedName(t).FQString() case *tree.TableRef: - tableDesc, err = n.p.byIDGetterBuilder().WithoutNonPublic().Immutable().Table(ctx, descpb.ID(t.TableID)) + tableDesc, err = n.p.byIDGetterBuilder().WithoutNonPublic().Get().Table(ctx, descpb.ID(t.TableID)) if err != nil { return nil, err } diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index 4d344afba780..2ca9db502412 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -92,7 +92,7 @@ func (p *planner) getNonTemporarySchemaForCreate( case catalog.SchemaPublic: return sc, nil case catalog.SchemaUserDefined: - return p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, sc.GetID()) + return p.Descriptors().MutableByID(p.txn).Schema(ctx, sc.GetID()) case catalog.SchemaVirtual: return nil, pgerror.Newf(pgcode.InsufficientPrivilege, "schema cannot be modified: %q", scName) default: @@ -445,7 +445,7 @@ func (n *createTableNode) startExec(params runParams) error { } if desc.LocalityConfig != nil { - dbDesc, err := params.p.Descriptors().ByID(params.p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(params.ctx, desc.ParentID) + dbDesc, err := params.p.Descriptors().ByID(params.p.txn).WithoutNonPublic().Get().Database(params.ctx, desc.ParentID) if err != nil { return errors.Wrap(err, "error resolving database for multi-region") } @@ -474,7 +474,7 @@ func (n *createTableNode) startExec(params runParams) error { if err != nil { return err } - typeDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, regionEnumID) + typeDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, regionEnumID) if err != nil { return errors.Wrap(err, "error resolving multi-region enum") } diff --git a/pkg/sql/create_view.go b/pkg/sql/create_view.go index 75ca544f9dd9..0030fe29f60e 100644 --- a/pkg/sql/create_view.go +++ b/pkg/sql/create_view.go @@ -112,11 +112,11 @@ func (n *createViewNode) startExec(params runParams) error { ids.Add(id) } // Lookup the dependent tables in bulk to minimize round-trips to KV. - if _, err := params.p.Descriptors().ByID(params.p.Txn()).WithoutNonPublic().WithoutSynthetic().WithoutLeased().Immutable().Descs(params.ctx, ids.Ordered()); err != nil { + if _, err := params.p.Descriptors().ByID(params.p.Txn()).WithoutNonPublic().WithoutSynthetic().Get().Descs(params.ctx, ids.Ordered()); err != nil { return err } for id := range n.planDeps { - backRefMutable, err := params.p.Descriptors().ByID(params.p.Txn()).Mutable().Table(params.ctx, id) + backRefMutable, err := params.p.Descriptors().MutableByID(params.p.Txn()).Table(params.ctx, id) if err != nil { return err } @@ -158,7 +158,7 @@ func (n *createViewNode) startExec(params runParams) error { if err != nil { return err } - desc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Table(params.ctx, id) + desc, err := params.p.Descriptors().MutableByID(params.p.txn).Table(params.ctx, id) if err != nil { return err } @@ -617,7 +617,7 @@ func (p *planner) replaceViewDesc( desc, ok := backRefMutables[id] if !ok { var err error - desc, err = p.Descriptors().ByID(p.txn).Mutable().Table(ctx, id) + desc, err = p.Descriptors().MutableByID(p.txn).Table(ctx, id) if err != nil { return nil, err } diff --git a/pkg/sql/database.go b/pkg/sql/database.go index 01f5d8005b32..6bf506ee155e 100644 --- a/pkg/sql/database.go +++ b/pkg/sql/database.go @@ -120,7 +120,7 @@ func (p *planner) forEachMutableTableInDatabase( } droppedRemoved = append(droppedRemoved, tbID) } - descs, err := p.Descriptors().ByID(p.Txn()).Mutable().Descs(ctx, droppedRemoved) + descs, err := p.Descriptors().MutableByID(p.Txn()).Descs(ctx, droppedRemoved) if err != nil { return err } diff --git a/pkg/sql/database_region_change_finalizer.go b/pkg/sql/database_region_change_finalizer.go index c622cf5731cc..2c048fa9eb59 100644 --- a/pkg/sql/database_region_change_finalizer.go +++ b/pkg/sql/database_region_change_finalizer.go @@ -60,7 +60,7 @@ func newDatabaseRegionChangeFinalizer( var regionalByRowTables []*tabledesc.Mutable if err := func() error { - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, dbID) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, dbID) if err != nil { return err } @@ -164,7 +164,7 @@ func (r *databaseRegionChangeFinalizer) updateGlobalTablesZoneConfig( descsCol := r.localPlanner.Descriptors() - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, r.dbID) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, r.dbID) if err != nil { return err } diff --git a/pkg/sql/database_test.go b/pkg/sql/database_test.go index f296eb88dd20..40b7e013b2f8 100644 --- a/pkg/sql/database_test.go +++ b/pkg/sql/database_test.go @@ -33,7 +33,7 @@ func TestDatabaseAccessors(t *testing.T) { defer s.Stopper().Stop(context.Background()) if err := TestingDescsTxn(context.Background(), s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - _, err := col.ByID(txn).WithoutLeased().Immutable().Database(ctx, keys.SystemDatabaseID) + _, err := col.ByID(txn).Get().Database(ctx, keys.SystemDatabaseID) return err }); err != nil { t.Fatal(err) diff --git a/pkg/sql/delete_preserving_index_test.go b/pkg/sql/delete_preserving_index_test.go index 4b73c0449165..8fbb66a7d4ce 100644 --- a/pkg/sql/delete_preserving_index_test.go +++ b/pkg/sql/delete_preserving_index_test.go @@ -677,7 +677,7 @@ func TestMergeProcessor(t *testing.T) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection) error { - mut, err := descriptors.ByID(txn).Mutable().Table(ctx, tableDesc.GetID()) + mut, err := descriptors.MutableByID(txn).Table(ctx, tableDesc.GetID()) if err != nil { return err } @@ -710,7 +710,7 @@ func TestMergeProcessor(t *testing.T) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection) error { - mut, err := descriptors.ByID(txn).Mutable().Table(ctx, tableDesc.GetID()) + mut, err := descriptors.MutableByID(txn).Table(ctx, tableDesc.GetID()) if err != nil { return err } diff --git a/pkg/sql/descmetadata/metadata_updater.go b/pkg/sql/descmetadata/metadata_updater.go index e009c6c8f897..c733e3c1b127 100644 --- a/pkg/sql/descmetadata/metadata_updater.go +++ b/pkg/sql/descmetadata/metadata_updater.go @@ -79,7 +79,7 @@ func (mu metadataUpdater) DeleteDatabaseRoleSettings(ctx context.Context, dbID d return nil } // Bump the table version for the role settings table when we modify it. - desc, err := mu.descriptors.ByID(mu.txn).Mutable().Table(ctx, keys.DatabaseRoleSettingsTableID) + desc, err := mu.descriptors.MutableByID(mu.txn).Table(ctx, keys.DatabaseRoleSettingsTableID) if err != nil { return err } diff --git a/pkg/sql/descriptor.go b/pkg/sql/descriptor.go index be1ad345b9b9..8c2b3cf6dc57 100644 --- a/pkg/sql/descriptor.go +++ b/pkg/sql/descriptor.go @@ -70,7 +70,7 @@ func (p *planner) createDatabase( if dbID, err := p.Descriptors().LookupDatabaseID(ctx, p.txn, dbName); err == nil && dbID != descpb.InvalidID { if database.IfNotExists { // Check if the database is in a dropping state - desc, err := p.Descriptors().ByID(p.txn).WithoutLeased().Immutable().Database(ctx, dbID) + desc, err := p.Descriptors().ByID(p.txn).Get().Database(ctx, dbID) if err != nil { return nil, false, err } @@ -363,7 +363,7 @@ func (p *planner) maybeInitializeMultiRegionMetadata( // GetImmutableTableInterfaceByID is part of the EvalPlanner interface. func (p *planner) GetImmutableTableInterfaceByID(ctx context.Context, id int) (interface{}, error) { - desc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(id)) + desc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(id)) if err != nil { return nil, err } diff --git a/pkg/sql/drop_cascade.go b/pkg/sql/drop_cascade.go index 28a4dc40996b..140bf48b9b2f 100644 --- a/pkg/sql/drop_cascade.go +++ b/pkg/sql/drop_cascade.go @@ -72,7 +72,7 @@ func (d *dropCascadeState) collectObjectsInSchema( // objectNamesToDelete. Instead, we need to go through each schema descriptor // to collect function descriptors by function ids. err = schema.ForEachFunctionOverload(func(overload descpb.SchemaDescriptor_FunctionOverload) error { - fnDesc, err := p.Descriptors().ByID(p.txn).Mutable().Function(ctx, overload.ID) + fnDesc, err := p.Descriptors().MutableByID(p.txn).Function(ctx, overload.ID) if err != nil { return err } diff --git a/pkg/sql/drop_database.go b/pkg/sql/drop_database.go index 4445fd239b58..697b22f3d1f8 100644 --- a/pkg/sql/drop_database.go +++ b/pkg/sql/drop_database.go @@ -167,7 +167,7 @@ func (n *dropDatabaseNode) startExec(params runParams) error { } case catalog.SchemaUserDefined: // For user defined schemas, we have to do a bit more work. - mutDesc, err := p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, schemaToDelete.GetID()) + mutDesc, err := p.Descriptors().MutableByID(p.txn).Schema(ctx, schemaToDelete.GetID()) if err != nil { return err } @@ -294,7 +294,7 @@ func (p *planner) accumulateOwnedSequences( ) error { for colID := range desc.GetColumns() { for _, seqID := range desc.GetColumns()[colID].OwnsSequenceIds { - ownedSeqDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, seqID) + ownedSeqDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, seqID) if err != nil { // Special case error swallowing for #50711 and #50781, which can // cause columns to own sequences that have been dropped/do not @@ -321,7 +321,7 @@ func (p *planner) accumulateCascadingViews( ctx context.Context, dependentObjects map[descpb.ID]*tabledesc.Mutable, desc *tabledesc.Mutable, ) error { for _, ref := range desc.DependedOnBy { - desc, err := p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, ref.ID) + desc, err := p.Descriptors().MutableByID(p.txn).Desc(ctx, ref.ID) if err != nil { return err } diff --git a/pkg/sql/drop_function.go b/pkg/sql/drop_function.go index 2ce130ae51f5..943f6ec9fd83 100644 --- a/pkg/sql/drop_function.go +++ b/pkg/sql/drop_function.go @@ -134,7 +134,7 @@ func (p *planner) matchUDF( func (p *planner) checkPrivilegesForDropFunction( ctx context.Context, fnID descpb.ID, ) (*funcdesc.Mutable, error) { - mutable, err := p.Descriptors().ByID(p.Txn()).Mutable().Function(ctx, fnID) + mutable, err := p.Descriptors().MutableByID(p.Txn()).Function(ctx, fnID) if err != nil { return nil, err } @@ -179,7 +179,7 @@ func (p *planner) dropFunctionImpl(ctx context.Context, fnMutable *funcdesc.Muta // TODO(chengxiong): remove backreference from UDFs that this UDF has // reference to. This is needed when we allow UDFs being referenced by // UDFs. - refMutable, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, id) + refMutable, err := p.Descriptors().MutableByID(p.txn).Table(ctx, id) if err != nil { return err } @@ -209,7 +209,7 @@ func (p *planner) dropFunctionImpl(ctx context.Context, fnMutable *funcdesc.Muta } // Remove function signature from schema. - scDesc, err := p.Descriptors().ByID(p.Txn()).Mutable().Schema(ctx, fnMutable.ParentSchemaID) + scDesc, err := p.Descriptors().MutableByID(p.Txn()).Schema(ctx, fnMutable.ParentSchemaID) if err != nil { return err } diff --git a/pkg/sql/drop_function_test.go b/pkg/sql/drop_function_test.go index 76dc662e1981..636b7daa5473 100644 --- a/pkg/sql/drop_function_test.go +++ b/pkg/sql/drop_function_test.go @@ -62,7 +62,7 @@ CREATE SCHEMA test_sc; ) err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - funcDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 109) + funcDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 109) require.NoError(t, err) require.Equal(t, funcDesc.GetName(), "f") @@ -145,7 +145,7 @@ SELECT nextval(105:::REGCLASS);`, // DROP the function and make sure dependencies are cleared. tDB.Exec(t, "DROP FUNCTION f") err = sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - _, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 109) + _, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 109) require.Error(t, err) require.Regexp(t, "descriptor is being dropped", err.Error()) @@ -374,7 +374,7 @@ $$; tDB.Exec(t, "SET use_declarative_schema_changer = off;") err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - fnDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 113) + fnDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 113) require.NoError(t, err) require.Equal(t, "f", fnDesc.GetName()) require.True(t, fnDesc.Public()) @@ -385,7 +385,7 @@ $$; tDB.Exec(t, tc.stmt) err = sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - _, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 113) + _, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 113) require.Error(t, err) require.Regexp(t, "descriptor is being dropped", err.Error()) return nil @@ -407,7 +407,7 @@ $$; tDB.Exec(t, "SET use_declarative_schema_changer = on;") err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - fnDesc, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 113) + fnDesc, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 113) require.NoError(t, err) require.Equal(t, "f", fnDesc.GetName()) require.True(t, fnDesc.Public()) @@ -418,7 +418,7 @@ $$; tDB.Exec(t, tc.stmt) err = sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - _, err := col.ByID(txn).WithoutNonPublic().Immutable().Function(ctx, 113) + _, err := col.ByIDWithLeased(txn).WithoutNonPublic().Get().Function(ctx, 113) require.Error(t, err) require.Regexp(t, "descriptor is being dropped", err.Error()) return nil diff --git a/pkg/sql/drop_schema.go b/pkg/sql/drop_schema.go index 9016b77229ee..3ffb86ee9309 100644 --- a/pkg/sql/drop_schema.go +++ b/pkg/sql/drop_schema.go @@ -146,7 +146,7 @@ func (n *dropSchemaNode) startExec(params runParams) error { sc := n.d.schemasToDelete[i].schema schemaIDs[i] = sc.GetID() db := n.d.schemasToDelete[i].dbDesc - mutDesc, err := p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, sc.GetID()) + mutDesc, err := p.Descriptors().MutableByID(p.txn).Schema(ctx, sc.GetID()) if err != nil { return err } diff --git a/pkg/sql/drop_sequence.go b/pkg/sql/drop_sequence.go index b86722007664..8f2caf3efab7 100644 --- a/pkg/sql/drop_sequence.go +++ b/pkg/sql/drop_sequence.go @@ -237,7 +237,7 @@ func dropDependentOnSequence(ctx context.Context, p *planner, seqDesc *tabledesc numDependedOnByTablesToSkip := 0 for len(seqDesc.DependedOnBy) > numDependedOnByTablesToSkip { dependent := seqDesc.DependedOnBy[numDependedOnByTablesToSkip] - desc, err := p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, dependent.ID) + desc, err := p.Descriptors().MutableByID(p.txn).Desc(ctx, dependent.ID) if err != nil { return err } diff --git a/pkg/sql/drop_table.go b/pkg/sql/drop_table.go index ce49457b6566..99cf7a3860c9 100644 --- a/pkg/sql/drop_table.go +++ b/pkg/sql/drop_table.go @@ -203,7 +203,7 @@ func (p *planner) canDropTable( func (p *planner) canRemoveFKBackreference( ctx context.Context, from string, ref catalog.ForeignKeyConstraint, behavior tree.DropBehavior, ) error { - table, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, ref.GetOriginTableID()) + table, err := p.Descriptors().MutableByID(p.txn).Table(ctx, ref.GetOriginTableID()) if err != nil { return err } @@ -459,7 +459,7 @@ func (p *planner) removeFKForBackReference( if tableDesc.ID == ref.GetOriginTableID() { originTableDesc = tableDesc } else { - lookup, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, ref.GetOriginTableID()) + lookup, err := p.Descriptors().MutableByID(p.txn).Table(ctx, ref.GetOriginTableID()) if err != nil { return errors.Wrapf(err, "error resolving origin table ID %d", ref.GetOriginTableID()) } @@ -523,7 +523,7 @@ func (p *planner) removeFKBackReference( if tableDesc.ID == ref.ReferencedTableID { referencedTableDesc = tableDesc } else { - lookup, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, ref.ReferencedTableID) + lookup, err := p.Descriptors().MutableByID(p.txn).Table(ctx, ref.ReferencedTableID) if err != nil { return errors.Wrapf(err, "error resolving referenced table ID %d", ref.ReferencedTableID) } diff --git a/pkg/sql/drop_test.go b/pkg/sql/drop_test.go index 3529ff056a1c..f43cd4ea435d 100644 --- a/pkg/sql/drop_test.go +++ b/pkg/sql/drop_test.go @@ -133,7 +133,7 @@ INSERT INTO t.kv VALUES ('c', 'e'), ('a', 'c'), ('b', 'd'); tbDesc := desctestutils.TestingGetPublicTableDescriptor(kvDB, keys.SystemSQLCodec, "t", "kv") var dbDesc catalog.DatabaseDescriptor require.NoError(t, sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - dbDesc, err = col.ByID(txn).WithoutLeased().Immutable().Database(ctx, tbDesc.GetParentID()) + dbDesc, err = col.ByID(txn).Get().Database(ctx, tbDesc.GetParentID()) return err })) @@ -299,7 +299,7 @@ INSERT INTO t.kv2 VALUES ('c', 'd'), ('a', 'b'), ('e', 'a'); tb2Desc := desctestutils.TestingGetPublicTableDescriptor(kvDB, keys.SystemSQLCodec, "t", "kv2") var dbDesc catalog.DatabaseDescriptor require.NoError(t, sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - dbDesc, err = col.ByID(txn).WithoutLeased().Immutable().Database(ctx, tbDesc.GetParentID()) + dbDesc, err = col.ByID(txn).Get().Database(ctx, tbDesc.GetParentID()) return err })) @@ -868,7 +868,7 @@ func TestDropTableWhileUpgradingFormat(t *testing.T) { // Simulate a migration upgrading the table descriptor's format version after // the table has been dropped but before the truncation has occurred. if err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - tbl, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableDesc.ID) + tbl, err := col.ByID(txn).Get().Table(ctx, tableDesc.ID) if err != nil { return err } @@ -1212,7 +1212,7 @@ func TestDropIndexOnHashShardedIndexWithStoredShardColumn(t *testing.T) { tdb.QueryRow(t, query).Scan(&tableID) require.NoError(t, sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - tableDesc, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableID) + tableDesc, err = col.ByID(txn).Get().Table(ctx, tableID) return err })) shardIdx, err := tableDesc.FindIndexWithName("idx") @@ -1230,7 +1230,7 @@ func TestDropIndexOnHashShardedIndexWithStoredShardColumn(t *testing.T) { // Assert that the index is dropped but the shard column remains after dropping the index. require.NoError(t, sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - tableDesc, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableID) + tableDesc, err = col.ByID(txn).Get().Table(ctx, tableID) return err })) _, err = tableDesc.FindIndexWithName("idx") diff --git a/pkg/sql/drop_type.go b/pkg/sql/drop_type.go index 122eab7e9aa4..95f696b08bc2 100644 --- a/pkg/sql/drop_type.go +++ b/pkg/sql/drop_type.go @@ -99,7 +99,7 @@ func (p *planner) DropType(ctx context.Context, n *tree.DropType) (planNode, err } // Get the array type that needs to be dropped as well. - mutArrayDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeDesc.ArrayTypeID) + mutArrayDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeDesc.ArrayTypeID) if err != nil { return nil, err } @@ -162,7 +162,7 @@ func (n *dropTypeNode) startExec(params runParams) error { func (p *planner) addTypeBackReference( ctx context.Context, typeID, ref descpb.ID, jobDesc string, ) error { - mutDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeID) + mutDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeID) if err != nil { return err } @@ -182,7 +182,7 @@ func (p *planner) removeTypeBackReferences( ctx context.Context, typeIDs []descpb.ID, ref descpb.ID, jobDesc string, ) error { for _, typeID := range typeIDs { - mutDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, typeID) + mutDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, typeID) if err != nil { return err } @@ -197,12 +197,12 @@ func (p *planner) removeTypeBackReferences( func (p *planner) addBackRefsFromAllTypesInTable( ctx context.Context, desc *tabledesc.Mutable, ) error { - dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, desc.GetParentID()) if err != nil { return err } typeIDs, _, err := desc.GetAllReferencedTypeIDs(dbDesc, func(id descpb.ID) (catalog.TypeDescriptor, error) { - mutDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, id) + mutDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, id) if err != nil { return nil, err } @@ -223,12 +223,12 @@ func (p *planner) addBackRefsFromAllTypesInTable( func (p *planner) removeBackRefsFromAllTypesInTable( ctx context.Context, desc *tabledesc.Mutable, ) error { - dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, desc.GetParentID()) if err != nil { return err } typeIDs, _, err := desc.GetAllReferencedTypeIDs(dbDesc, func(id descpb.ID) (catalog.TypeDescriptor, error) { - mutDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, id) + mutDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, id) if err != nil { return nil, err } diff --git a/pkg/sql/drop_view.go b/pkg/sql/drop_view.go index 5b1c9340d179..dd0ea192ab4a 100644 --- a/pkg/sql/drop_view.go +++ b/pkg/sql/drop_view.go @@ -145,7 +145,7 @@ func (p *planner) canRemoveDependent( ref descpb.TableDescriptor_Reference, behavior tree.DropBehavior, ) error { - desc, err := p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, ref.ID) + desc, err := p.Descriptors().MutableByID(p.txn).Desc(ctx, ref.ID) if err != nil { return err } @@ -239,7 +239,7 @@ func (p *planner) dropViewImpl( // Remove back-references from the tables/views this view depends on. dependedOn := append([]descpb.ID(nil), viewDesc.DependsOn...) for _, depID := range dependedOn { - dependencyDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, depID) + dependencyDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, depID) if err != nil { return cascadeDroppedViews, errors.Wrapf(err, "error resolving dependency relation ID %d", depID) @@ -323,7 +323,7 @@ func (p *planner) getDescForCascade( parentID, descID descpb.ID, behavior tree.DropBehavior, ) (catalog.MutableDescriptor, error) { - desc, err := p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, descID) + desc, err := p.Descriptors().MutableByID(p.txn).Desc(ctx, descID) if err != nil { log.Warningf(ctx, "unable to retrieve descriptor for %d: %v", descID, err) return nil, errors.Wrapf(err, "error resolving dependent ID %d", descID) diff --git a/pkg/sql/evalcatalog/encode_table_index_key.go b/pkg/sql/evalcatalog/encode_table_index_key.go index f9a7cc4788db..528d59ca9dae 100644 --- a/pkg/sql/evalcatalog/encode_table_index_key.go +++ b/pkg/sql/evalcatalog/encode_table_index_key.go @@ -33,7 +33,7 @@ func (ec *Builtins) EncodeTableIndexKey( performCast func(context.Context, tree.Datum, *types.T) (tree.Datum, error), ) ([]byte, error) { // Get the referenced table and index. - tableDesc, err := ec.dc.ByID(ec.txn).WithoutNonPublic().Immutable().Table(ctx, tableID) + tableDesc, err := ec.dc.ByIDWithLeased(ec.txn).WithoutNonPublic().Get().Table(ctx, tableID) if err != nil { return nil, err } diff --git a/pkg/sql/evalcatalog/geo_inverted_index_entries.go b/pkg/sql/evalcatalog/geo_inverted_index_entries.go index 0eca86de5399..f979857e05a2 100644 --- a/pkg/sql/evalcatalog/geo_inverted_index_entries.go +++ b/pkg/sql/evalcatalog/geo_inverted_index_entries.go @@ -74,7 +74,7 @@ func getIndexGeoConfig( tableID catid.DescID, indexID catid.IndexID, ) (geoindex.Config, error) { - tableDesc, err := dc.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, tableID) + tableDesc, err := dc.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, tableID) if err != nil { return geoindex.Config{}, err } diff --git a/pkg/sql/evalcatalog/pg_updatable.go b/pkg/sql/evalcatalog/pg_updatable.go index b4ec2860dd86..f7e7da8f1319 100644 --- a/pkg/sql/evalcatalog/pg_updatable.go +++ b/pkg/sql/evalcatalog/pg_updatable.go @@ -92,7 +92,7 @@ func (b *Builtins) DescriptorWithPostDeserializationChanges( func (b *Builtins) PGRelationIsUpdatable( ctx context.Context, oidArg *tree.DOid, ) (*tree.DInt, error) { - tableDesc, err := b.dc.ByID(b.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(oidArg.Oid)) + tableDesc, err := b.dc.ByIDWithLeased(b.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(oidArg.Oid)) if err != nil { // For postgres compatibility, it is expected that rather returning // an error this return nonUpdatableEvents (Zero) because there could @@ -122,7 +122,7 @@ func (b *Builtins) PGColumnIsUpdatable( return tree.DBoolFalse, nil } attNum := descpb.PGAttributeNum(attNumArg) - tableDesc, err := b.dc.ByID(b.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(oidArg.Oid)) + tableDesc, err := b.dc.ByIDWithLeased(b.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(oidArg.Oid)) if err != nil { if sqlerrors.IsUndefinedRelationError(err) { // For postgres compatibility, it is expected that rather returning diff --git a/pkg/sql/gcjob/gc_job.go b/pkg/sql/gcjob/gc_job.go index 600b45550ade..97676d6ef65c 100644 --- a/pkg/sql/gcjob/gc_job.go +++ b/pkg/sql/gcjob/gc_job.go @@ -134,7 +134,7 @@ func deleteTableData( for _, droppedTable := range progress.Tables { var table catalog.TableDescriptor if err := sql.DescsTxn(ctx, cfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - table, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, droppedTable.ID) + table, err = col.ByID(txn).Get().Table(ctx, droppedTable.ID) return err }); err != nil { if errors.Is(err, catalog.ErrDescriptorNotFound) { diff --git a/pkg/sql/gcjob/index_garbage_collection.go b/pkg/sql/gcjob/index_garbage_collection.go index 43215efb0663..29311183bc97 100644 --- a/pkg/sql/gcjob/index_garbage_collection.go +++ b/pkg/sql/gcjob/index_garbage_collection.go @@ -121,7 +121,7 @@ func gcIndexes( removeIndexZoneConfigs := func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { - freshParentTableDesc, err := descriptors.ByID(txn).Mutable().Table(ctx, parentID) + freshParentTableDesc, err := descriptors.MutableByID(txn).Table(ctx, parentID) if err != nil { return err } @@ -202,7 +202,7 @@ func deleteIndexZoneConfigsAfterGC( removeIndexZoneConfigs := func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { - freshParentTableDesc, err := descriptors.ByID(txn).Mutable().Table(ctx, parentID) + freshParentTableDesc, err := descriptors.MutableByID(txn).Table(ctx, parentID) if err != nil { return err } diff --git a/pkg/sql/gcjob/refresh_statuses.go b/pkg/sql/gcjob/refresh_statuses.go index 218519d9eea5..6886d9b48c3e 100644 --- a/pkg/sql/gcjob/refresh_statuses.go +++ b/pkg/sql/gcjob/refresh_statuses.go @@ -104,7 +104,7 @@ func updateStatusForGCElements( earliestDeadline := timeutil.Unix(0, int64(math.MaxInt64)) if err := sql.DescsTxn(ctx, execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - table, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableID) + table, err := col.ByID(txn).Get().Table(ctx, tableID) if err != nil { return err } diff --git a/pkg/sql/gcjob/table_garbage_collection.go b/pkg/sql/gcjob/table_garbage_collection.go index 8e22ee863aed..c57aafcb1edf 100644 --- a/pkg/sql/gcjob/table_garbage_collection.go +++ b/pkg/sql/gcjob/table_garbage_collection.go @@ -49,7 +49,7 @@ func gcTables( var table catalog.TableDescriptor if err := sql.DescsTxn(ctx, execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - table, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, droppedTable.ID) + table, err = col.ByID(txn).Get().Table(ctx, droppedTable.ID) return err }); err != nil { if errors.Is(err, catalog.ErrDescriptorNotFound) { @@ -287,7 +287,7 @@ func deleteTableDescriptorsAfterGC( var table catalog.TableDescriptor if err := sql.DescsTxn(ctx, execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - table, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, droppedTable.ID) + table, err = col.ByID(txn).Get().Table(ctx, droppedTable.ID) return err }); err != nil { if errors.Is(err, catalog.ErrDescriptorNotFound) { diff --git a/pkg/sql/gcjob_test/gc_job_test.go b/pkg/sql/gcjob_test/gc_job_test.go index f58c76ac6b61..6d9dd82dd8ae 100644 --- a/pkg/sql/gcjob_test/gc_job_test.go +++ b/pkg/sql/gcjob_test/gc_job_test.go @@ -109,12 +109,12 @@ func TestSchemaChangeGCJob(t *testing.T) { var myTableDesc *tabledesc.Mutable var myOtherTableDesc *tabledesc.Mutable if err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - myImm, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, myTableID) + myImm, err := col.ByID(txn).Get().Table(ctx, myTableID) if err != nil { return err } myTableDesc = tabledesc.NewBuilder(myImm.TableDesc()).BuildExistingMutableTable() - myOtherImm, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, myOtherTableID) + myOtherImm, err := col.ByID(txn).Get().Table(ctx, myOtherTableID) if err != nil { return err } @@ -238,7 +238,7 @@ func TestSchemaChangeGCJob(t *testing.T) { } if err := sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - myImm, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, myTableID) + myImm, err := col.ByID(txn).Get().Table(ctx, myTableID) if err != nil { return err } @@ -248,7 +248,7 @@ func TestSchemaChangeGCJob(t *testing.T) { return nil } myTableDesc = tabledesc.NewBuilder(myImm.TableDesc()).BuildExistingMutableTable() - myOtherImm, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, myOtherTableID) + myOtherImm, err := col.ByID(txn).Get().Table(ctx, myOtherTableID) if err != nil { return err } diff --git a/pkg/sql/grant_revoke.go b/pkg/sql/grant_revoke.go index 39eed0053598..cfbb8da210b7 100644 --- a/pkg/sql/grant_revoke.go +++ b/pkg/sql/grant_revoke.go @@ -586,7 +586,7 @@ func (p *planner) getTablePatternsComposition( } // Note that part of the reason the code is structured this way is that // resolving mutable descriptors for virtual table IDs results in an error. - muts, err := p.Descriptors().ByID(p.txn).Mutable().Descs(ctx, nonVirtualIDs) + muts, err := p.Descriptors().MutableByID(p.txn).Descs(ctx, nonVirtualIDs) if err != nil { return unknownComposition, err } diff --git a/pkg/sql/importer/import_job.go b/pkg/sql/importer/import_job.go index 161c6e5af5e8..4c686c5d7759 100644 --- a/pkg/sql/importer/import_job.go +++ b/pkg/sql/importer/import_job.go @@ -134,7 +134,7 @@ func (r *importResumer) Resume(ctx context.Context, execCtx interface{}) error { } // The public schema is expected to always be present in the database for 22.2+. - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, details.ParentID) + dbDesc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, details.ParentID) if err != nil { return err } @@ -149,7 +149,7 @@ func (r *importResumer) Resume(ctx context.Context, execCtx interface{}) error { // Telemetry for multi-region. for _, table := range preparedDetails.Tables { - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, table.Desc.GetParentID()) + dbDesc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, table.Desc.GetParentID()) if err != nil { return err } @@ -472,7 +472,7 @@ func prepareExistingTablesForIngestion( } // Note that desc is just used to verify that the version matches. - importing, err := descsCol.ByID(txn).Mutable().Table(ctx, desc.ID) + importing, err := descsCol.MutableByID(txn).Table(ctx, desc.ID) if err != nil { return nil, err } @@ -624,7 +624,7 @@ func (r *importResumer) prepareSchemasForIngestion( schemaMetadata.schemaPreparedDetails.Schemas = make([]jobspb.ImportDetails_Schema, len(details.Schemas)) - desc, err := descsCol.ByID(txn).Mutable().Desc(ctx, details.ParentID) + desc, err := descsCol.MutableByID(txn).Desc(ctx, details.ParentID) if err != nil { return nil, err } @@ -700,7 +700,7 @@ func bindImportStartTime( if err := sql.DescsTxn(ctx, p.ExecCfg(), func( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { - mutableDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, id) + mutableDesc, err := descsCol.MutableByID(txn).Table(ctx, id) if err != nil { return err } @@ -752,7 +752,7 @@ func (r *importResumer) parseBundleSchemaIfNeeded(ctx context.Context, phs inter if err := sql.DescsTxn(ctx, p.ExecCfg(), func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - dbDesc, err = descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, parentID) + dbDesc, err = descriptors.ByID(txn).WithoutNonPublic().Get().Database(ctx, parentID) if err != nil { return err } @@ -816,7 +816,7 @@ func getPublicSchemaDescForDatabase( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { publicSchemaID := db.GetSchemaID(tree.PublicSchema) - scDesc, err = descriptors.ByID(txn).WithoutNonPublic().Immutable().Schema(ctx, publicSchemaID) + scDesc, err = descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Schema(ctx, publicSchemaID) return err }); err != nil { return nil, err @@ -942,7 +942,7 @@ func (r *importResumer) publishTables( ) error { b := txn.NewBatch() for _, tbl := range details.Tables { - newTableDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, tbl.Desc.ID) + newTableDesc, err := descsCol.MutableByID(txn).Table(ctx, tbl.Desc.ID) if err != nil { return err } @@ -1063,7 +1063,7 @@ func (r *importResumer) publishSchemas(ctx context.Context, execCfg *sql.Executo ) error { b := txn.NewBatch() for _, schema := range details.Schemas { - newDesc, err := descsCol.ByID(txn).Mutable().Desc(ctx, schema.Desc.GetID()) + newDesc, err := descsCol.MutableByID(txn).Desc(ctx, schema.Desc.GetID()) if err != nil { return err } @@ -1175,7 +1175,7 @@ func (r *importResumer) checkForUDTModification( ctx context.Context, txn *kv.Txn, col *descs.Collection, savedTypeDesc *descpb.TypeDescriptor, ) error { - typeDesc, err := col.ByID(txn).WithoutLeased().Immutable().Type(ctx, savedTypeDesc.GetID()) + typeDesc, err := col.ByID(txn).Get().Type(ctx, savedTypeDesc.GetID()) if err != nil { return errors.Wrap(err, "resolving type descriptor when checking version mismatch") } @@ -1449,7 +1449,7 @@ func (r *importResumer) dropTables( var intoTable catalog.TableDescriptor for _, tbl := range details.Tables { if !tbl.IsNew { - desc, err := descsCol.ByID(txn).Mutable().Table(ctx, tbl.Desc.ID) + desc, err := descsCol.MutableByID(txn).Table(ctx, tbl.Desc.ID) if err != nil { return err } @@ -1526,7 +1526,7 @@ func (r *importResumer) dropTables( // Bring the IMPORT INTO table back online b := txn.NewBatch() - intoDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, intoTable.GetID()) + intoDesc, err := descsCol.MutableByID(txn).Table(ctx, intoTable.GetID()) if err != nil { return err } @@ -1551,7 +1551,7 @@ func (r *importResumer) dropNewTables( tablesToGC := make([]descpb.ID, 0, len(details.Tables)) toWrite := make([]*tabledesc.Mutable, 0, len(details.Tables)) for _, tbl := range details.Tables { - newTableDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, tbl.Desc.ID) + newTableDesc, err := descsCol.MutableByID(txn).Table(ctx, tbl.Desc.ID) if err != nil { return err } @@ -1620,7 +1620,7 @@ func (r *importResumer) dropSchemas( } // Resolve the database descriptor. - desc, err := descsCol.ByID(txn).Mutable().Desc(ctx, details.ParentID) + desc, err := descsCol.MutableByID(txn).Desc(ctx, details.ParentID) if err != nil { return nil, err } @@ -1633,7 +1633,7 @@ func (r *importResumer) dropSchemas( droppedSchemaIDs := make([]descpb.ID, 0) for _, schema := range details.Schemas { - desc, err := descsCol.ByID(txn).Mutable().Desc(ctx, schema.Desc.ID) + desc, err := descsCol.MutableByID(txn).Desc(ctx, schema.Desc.ID) if err != nil { return nil, err } diff --git a/pkg/sql/importer/import_planning.go b/pkg/sql/importer/import_planning.go index e768ce944279..b737acf4bf02 100644 --- a/pkg/sql/importer/import_planning.go +++ b/pkg/sql/importer/import_planning.go @@ -297,13 +297,13 @@ func resolveUDTsUsedByImportInto( err := sql.DescsTxn(ctx, p.ExecCfg(), func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - dbDesc, err = descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, table.GetParentID()) + dbDesc, err = descriptors.ByID(txn).WithoutNonPublic().Get().Database(ctx, table.GetParentID()) if err != nil { return err } typeIDs, _, err := table.GetAllReferencedTypeIDs(dbDesc, func(id descpb.ID) (catalog.TypeDescriptor, error) { - immutDesc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Type(ctx, id) + immutDesc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Type(ctx, id) if err != nil { return nil, err } @@ -314,7 +314,7 @@ func resolveUDTsUsedByImportInto( } for _, typeID := range typeIDs { - immutDesc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Type(ctx, typeID) + immutDesc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Type(ctx, typeID) if err != nil { return err } diff --git a/pkg/sql/importer/import_stmt_test.go b/pkg/sql/importer/import_stmt_test.go index 89352c0a347a..225695cb92bc 100644 --- a/pkg/sql/importer/import_stmt_test.go +++ b/pkg/sql/importer/import_stmt_test.go @@ -2061,7 +2061,7 @@ func TestFailedImportGC(t *testing.T) { tableID := descpb.ID(dbID + 2) var td catalog.TableDescriptor if err := sql.TestingDescsTxn(ctx, tc.Server(0), func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - td, err = col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableID) + td, err = col.ByID(txn).Get().Table(ctx, tableID) return err }); err != nil { t.Fatal(err) @@ -6412,7 +6412,7 @@ func TestImportPgDumpSchemas(t *testing.T) { for _, schemaID := range schemaIDs { // Expect that the schema descriptor is deleted. if err := sql.TestingDescsTxn(ctx, tc.Server(0), func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - _, err := col.ByID(txn).WithoutLeased().Immutable().Schema(ctx, schemaID) + _, err := col.ByID(txn).Get().Schema(ctx, schemaID) if pgerror.GetPGCode(err) == pgcode.InvalidSchemaName { return nil } @@ -6428,7 +6428,7 @@ func TestImportPgDumpSchemas(t *testing.T) { for _, tableID := range tableIDs { // Expect that the table descriptor is deleted. if err := sql.TestingDescsTxn(ctx, tc.Server(0), func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - _, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableID) + _, err := col.ByID(txn).Get().Table(ctx, tableID) if !testutils.IsError(err, "descriptor not found") { return err } diff --git a/pkg/sql/importer/read_import_pgdump.go b/pkg/sql/importer/read_import_pgdump.go index 457fdddd94ac..a18bdb027cca 100644 --- a/pkg/sql/importer/read_import_pgdump.go +++ b/pkg/sql/importer/read_import_pgdump.go @@ -278,7 +278,7 @@ func createPostgresSchemas( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { schemaDescs = nil // reset for retries - dbDesc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, parentID) + dbDesc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Database(ctx, parentID) if err != nil { return err } @@ -874,7 +874,7 @@ func readPostgresStmt( for _, name := range names { tableName := name.ToUnresolvedObjectName().String() if err := sql.DescsTxn(ctx, p.ExecCfg(), func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - dbDesc, err := col.ByID(txn).WithoutLeased().Immutable().Database(ctx, parentID) + dbDesc, err := col.ByID(txn).Get().Database(ctx, parentID) if err != nil { return err } diff --git a/pkg/sql/indexbackfiller_test.go b/pkg/sql/indexbackfiller_test.go index 957cda6b4f93..8933a05d8e76 100644 --- a/pkg/sql/indexbackfiller_test.go +++ b/pkg/sql/indexbackfiller_test.go @@ -487,7 +487,7 @@ INSERT INTO foo VALUES (1), (10), (100); require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - mut, err := descriptors.ByID(txn).Mutable().Table(ctx, tableID) + mut, err := descriptors.MutableByID(txn).Table(ctx, tableID) if err != nil { return err } @@ -539,7 +539,7 @@ INSERT INTO foo VALUES (1), (10), (100); require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { - table, err := descriptors.ByID(txn).Mutable().Table(ctx, tableID) + table, err := descriptors.MutableByID(txn).Table(ctx, tableID) if err != nil { return err } diff --git a/pkg/sql/information_schema.go b/pkg/sql/information_schema.go index 72ad708c134e..37ad14947143 100644 --- a/pkg/sql/information_schema.go +++ b/pkg/sql/information_schema.go @@ -1673,12 +1673,12 @@ var informationSchemaRoleRoutineGrantsTable = virtualSchemaTable{ } err := db.ForEachSchema(func(id descpb.ID, name string) error { - sc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Schema(ctx, id) + sc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Schema(ctx, id) if err != nil { return err } return sc.ForEachFunctionOverload(func(overload descpb.SchemaDescriptor_FunctionOverload) error { - fn, err := p.Descriptors().ByID(p.txn).Mutable().Function(ctx, overload.ID) + fn, err := p.Descriptors().MutableByID(p.txn).Function(ctx, overload.ID) if err != nil { return err } diff --git a/pkg/sql/opt_catalog.go b/pkg/sql/opt_catalog.go index 0532a2336eea..27722df7a010 100644 --- a/pkg/sql/opt_catalog.go +++ b/pkg/sql/opt_catalog.go @@ -438,7 +438,7 @@ func (oc *optCatalog) fullyQualifiedNameWithTxn( } dbID := desc.GetParentID() - dbDesc, err := oc.planner.Descriptors().ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, dbID) + dbDesc, err := oc.planner.Descriptors().ByID(txn).WithoutNonPublic().Get().Database(ctx, dbID) if err != nil { return cat.DataSourceName{}, err } @@ -448,7 +448,7 @@ func (oc *optCatalog) fullyQualifiedNameWithTxn( if scID == keys.PublicSchemaID { scName = tree.PublicSchemaName } else { - scDesc, err := oc.planner.Descriptors().ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Schema(ctx, scID) + scDesc, err := oc.planner.Descriptors().ByID(txn).WithoutNonPublic().Get().Schema(ctx, scID) if err != nil { return cat.DataSourceName{}, err } diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 4046348213e9..81848f747d05 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -1063,7 +1063,7 @@ type oneAtATimeSchemaResolver struct { func (r oneAtATimeSchemaResolver) getDatabaseByID( id descpb.ID, ) (catalog.DatabaseDescriptor, error) { - desc, err := r.p.Descriptors().ByID(r.p.txn).WithoutNonPublic().Immutable().Database(r.ctx, id) + desc, err := r.p.Descriptors().ByIDWithLeased(r.p.txn).WithoutNonPublic().Get().Database(r.ctx, id) return desc, err } @@ -1076,7 +1076,7 @@ func (r oneAtATimeSchemaResolver) getTableByID(id descpb.ID) (catalog.TableDescr } func (r oneAtATimeSchemaResolver) getSchemaByID(id descpb.ID) (catalog.SchemaDescriptor, error) { - return r.p.Descriptors().ByID(r.p.txn).WithoutLeased().Immutable().Schema(r.ctx, id) + return r.p.Descriptors().ByID(r.p.txn).Get().Schema(r.ctx, id) } // makeAllRelationsVirtualTableWithDescriptorIDIndex creates a virtual table that searches through @@ -1144,7 +1144,7 @@ func makeAllRelationsVirtualTableWithDescriptorIDIndex( } h := makeOidHasher() scResolver := oneAtATimeSchemaResolver{p: p, ctx: ctx} - sc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Schema(ctx, table.GetParentSchemaID()) + sc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Schema(ctx, table.GetParentSchemaID()) if err != nil { return false, err } @@ -1596,11 +1596,11 @@ https://www.postgresql.org/docs/9.5/catalog-pg-description.html`, objID = tree.NewDOid(oid.Oid(tree.MustBeDInt(objID))) classOid = tree.NewDOid(catconstants.PgCatalogClassTableID) case catalogkeys.ConstraintCommentType: - tableDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(tree.MustBeDInt(objID))) + tableDesc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(tree.MustBeDInt(objID))) if err != nil { return err } - schema, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Schema(ctx, tableDesc.GetParentSchemaID()) + schema, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Schema(ctx, tableDesc.GetParentSchemaID()) if err != nil { return err } @@ -2093,7 +2093,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-namespace.html`, if sc, ok := schemadesc.GetVirtualSchemaByID(descpb.ID(ooid)); ok { return sc, true, nil } - if sc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Schema(ctx, descpb.ID(ooid)); err == nil { + if sc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Schema(ctx, descpb.ID(ooid)); err == nil { return sc, true, nil } else if !sqlerrors.IsUndefinedSchemaError(err) { return nil, false, err @@ -2548,7 +2548,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-proc.html`, func(dbDesc catalog.DatabaseDescriptor) error { return forEachSchema(ctx, p, dbDesc, true /* requiresPrivileges */, func(scDesc catalog.SchemaDescriptor) error { return scDesc.ForEachFunctionOverload(func(overload descpb.SchemaDescriptor_FunctionOverload) error { - fnDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().WithoutLeased().Immutable().Function(ctx, overload.ID) + fnDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Get().Function(ctx, overload.ID) if err != nil { return err } @@ -2576,12 +2576,12 @@ https://www.postgresql.org/docs/9.5/catalog-pg-proc.html`, } if overload.IsUDF { - fnDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().WithoutLeased().Immutable().Function(ctx, descpb.ID(overload.Oid)) + fnDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Get().Function(ctx, descpb.ID(overload.Oid)) if err != nil { return false, err } - scDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Schema(ctx, descpb.ID(ooid)) + scDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Schema(ctx, descpb.ID(ooid)) if err != nil { return false, err } @@ -3178,7 +3178,7 @@ func addPGTypeRow( func getSchemaAndTypeByTypeID( ctx context.Context, p *planner, id descpb.ID, ) (catalog.SchemaDescriptor, catalog.TypeDescriptor, error) { - typDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Type(ctx, id) + typDesc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Type(ctx, id) if err != nil { // If the type was not found, it may be a table. if !(errors.Is(err, catalog.ErrDescriptorNotFound) || pgerror.GetPGCode(err) == pgcode.UndefinedObject) { @@ -3187,7 +3187,7 @@ func getSchemaAndTypeByTypeID( return nil, nil, nil } - sc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Schema(ctx, typDesc.GetParentSchemaID()) + sc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Schema(ctx, typDesc.GetParentSchemaID()) if err != nil { return nil, nil, err } @@ -3286,7 +3286,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-type.html`, // It's an entry for the implicit record type created on behalf of each // table. We have special logic for this case. if typDesc.GetKind() == descpb.TypeDescriptor_TABLE_IMPLICIT_RECORD_TYPE { - table, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, id) + table, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, id) if err != nil { if errors.Is(err, catalog.ErrDescriptorNotFound) || pgerror.GetPGCode(err) == pgcode.UndefinedObject || @@ -3520,7 +3520,7 @@ https://www.postgresql.org/docs/13/catalog-pg-statistic-ext.html`, h.writeUInt64(uint64(statisticsID)) statisticsOID := h.getOid() - tbl, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(tableID)) + tbl, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Table(ctx, descpb.ID(tableID)) if err != nil { return err } diff --git a/pkg/sql/planner.go b/pkg/sql/planner.go index 9407482d52e5..d72862059a94 100644 --- a/pkg/sql/planner.go +++ b/pkg/sql/planner.go @@ -604,7 +604,7 @@ func (p *planner) ResolveTableName(ctx context.Context, tn *tree.TableName) (tre func (p *planner) LookupTableByID( ctx context.Context, tableID descpb.ID, ) (catalog.TableDescriptor, error) { - table, err := p.byIDGetterBuilder().WithoutNonPublic().Immutable().Table(ctx, tableID) + table, err := p.byIDGetterBuilder().WithoutNonPublic().Get().Table(ctx, tableID) if err != nil { return nil, err } diff --git a/pkg/sql/privileged_accessor.go b/pkg/sql/privileged_accessor.go index c5642a62f8c0..c93a5d4e16a6 100644 --- a/pkg/sql/privileged_accessor.go +++ b/pkg/sql/privileged_accessor.go @@ -80,7 +80,7 @@ func (p *planner) LookupZoneConfigByNamespaceID( // to check the permissions of a descriptor given its ID, or the id given // is not a descriptor of a table or database. func (p *planner) checkDescriptorPermissions(ctx context.Context, id descpb.ID) error { - desc, err := p.Descriptors().ByID(p.txn).Immutable().Desc(ctx, id) + desc, err := p.Descriptors().ByIDWithLeased(p.txn).Get().Desc(ctx, id) if err != nil { // Filter the error due to the descriptor not existing. if errors.Is(err, catalog.ErrDescriptorNotFound) { diff --git a/pkg/sql/reassign_owned_by.go b/pkg/sql/reassign_owned_by.go index 8a42e35c3b79..e3ee919012c3 100644 --- a/pkg/sql/reassign_owned_by.go +++ b/pkg/sql/reassign_owned_by.go @@ -201,7 +201,7 @@ func (n *reassignOwnedByNode) startExec(params runParams) error { func (n *reassignOwnedByNode) reassignDatabaseOwner( dbDesc catalog.DatabaseDescriptor, params runParams, ) error { - mutableDbDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Desc(params.ctx, dbDesc.GetID()) + mutableDbDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Desc(params.ctx, dbDesc.GetID()) if err != nil { return err } @@ -230,7 +230,7 @@ func (n *reassignOwnedByNode) reassignDatabaseOwner( func (n *reassignOwnedByNode) reassignSchemaOwner( schemaDesc catalog.SchemaDescriptor, dbDesc *dbdesc.Mutable, params runParams, ) error { - mutableSchemaDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Desc(params.ctx, schemaDesc.GetID()) + mutableSchemaDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Desc(params.ctx, schemaDesc.GetID()) if err != nil { return err } @@ -259,7 +259,7 @@ func (n *reassignOwnedByNode) reassignSchemaOwner( func (n *reassignOwnedByNode) reassignTableOwner( tbDesc catalog.TableDescriptor, params runParams, ) error { - mutableTbDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Desc(params.ctx, tbDesc.GetID()) + mutableTbDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Desc(params.ctx, tbDesc.GetID()) if err != nil { return err } @@ -292,14 +292,14 @@ func (n *reassignOwnedByNode) reassignTableOwner( func (n *reassignOwnedByNode) reassignTypeOwner( typDesc catalog.TypeDescriptor, params runParams, ) error { - mutableTypDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Desc(params.ctx, typDesc.GetID()) + mutableTypDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Desc(params.ctx, typDesc.GetID()) if err != nil { return err } if mutableTypDesc.Dropped() { return nil } - arrayDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Type(params.ctx, typDesc.GetArrayTypeID()) + arrayDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Type(params.ctx, typDesc.GetArrayTypeID()) if err != nil { return err } @@ -340,7 +340,7 @@ func (n *reassignOwnedByNode) reassignTypeOwner( func (n *reassignOwnedByNode) reassignFunctionOwner( fnDesc catalog.FunctionDescriptor, params runParams, ) error { - mutableDesc, err := params.p.Descriptors().ByID(params.p.txn).Mutable().Function(params.ctx, fnDesc.GetID()) + mutableDesc, err := params.p.Descriptors().MutableByID(params.p.txn).Function(params.ctx, fnDesc.GetID()) if err != nil { return err } diff --git a/pkg/sql/region_util.go b/pkg/sql/region_util.go index b4e7ee1326d8..5bfd9297f61b 100644 --- a/pkg/sql/region_util.go +++ b/pkg/sql/region_util.go @@ -1243,7 +1243,7 @@ func (p *planner) ValidateAllMultiRegionZoneConfigsInCurrentDatabase(ctx context // zone configurations to match what would have originally been set by the // multi-region syntax. func (p *planner) ResetMultiRegionZoneConfigsForTable(ctx context.Context, id int64) error { - desc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, descpb.ID(id)) + desc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, descpb.ID(id)) if err != nil { return errors.Wrapf(err, "error resolving referenced table ID %d", id) } @@ -1278,7 +1278,7 @@ func (p *planner) ResetMultiRegionZoneConfigsForTable(ctx context.Context, id in // database's zone configuration to match what would have originally been set by // the multi-region syntax. func (p *planner) ResetMultiRegionZoneConfigsForDatabase(ctx context.Context, id int64) error { - dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, descpb.ID(id)) + dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, descpb.ID(id)) if err != nil { return err } @@ -1584,14 +1584,17 @@ func getDBAndRegionEnumDescs( useCache bool, includeOffline bool, ) (dbDesc catalog.DatabaseDescriptor, regionEnumDesc catalog.TypeDescriptor, _ error) { - b := descsCol.ByID(txn).WithoutDropped() + var b descs.ByIDGetterBuilder + if useCache { + b = descsCol.ByIDWithLeased(txn) + } else { + b = descsCol.ByID(txn) + } if !includeOffline { b = b.WithoutOffline() } - if !useCache { - b = b.WithoutLeased() - } - dbDesc, err := b.Immutable().Database(ctx, dbID) + g := b.Get() + dbDesc, err := g.Database(ctx, dbID) if err != nil { return nil, nil, err } @@ -1602,7 +1605,7 @@ func getDBAndRegionEnumDescs( if err != nil { return nil, nil, err } - regionEnumDesc, err = b.Immutable().Type(ctx, regionEnumID) + regionEnumDesc, err = g.Type(ctx, regionEnumID) if err != nil { return nil, nil, err } @@ -2462,7 +2465,7 @@ func (p *planner) OptimizeSystemDatabase(ctx context.Context) error { // Retrieve the system database descriptor and ensure it supports // multi-region - systemDB, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, keys.SystemDatabaseID) + systemDB, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, keys.SystemDatabaseID) if err != nil { return err } @@ -2470,7 +2473,7 @@ func (p *planner) OptimizeSystemDatabase(ctx context.Context) error { if err != nil { return errors.Wrap(err, "system database is not multi-region") } - enumTypeDesc, err := p.Descriptors().ByID(p.txn).Mutable().Type(ctx, regionEnumID) + enumTypeDesc, err := p.Descriptors().MutableByID(p.txn).Type(ctx, regionEnumID) if err != nil { return err } diff --git a/pkg/sql/rename_database.go b/pkg/sql/rename_database.go index 234a0dd10072..d0a0e899dff6 100644 --- a/pkg/sql/rename_database.go +++ b/pkg/sql/rename_database.go @@ -132,12 +132,7 @@ func (n *renameDatabaseNode) startExec(params runParams) error { if err != nil { return err } - if err := maybeFailOnDependentDescInRename(ctx, p, dbDesc, sc, func(b descs.ByIDGetterBuilder) descs.ByIDGetterBuilder { - if p.skipDescriptorCache { - b = b.WithoutLeased() - } - return b.WithoutNonPublic() - }, catalog.Database); err != nil { + if err := maybeFailOnDependentDescInRename(ctx, p, dbDesc, sc, !p.skipDescriptorCache, catalog.Database); err != nil { return err } } @@ -209,15 +204,20 @@ func maybeFailOnDependentDescInRename( p *planner, db catalog.DatabaseDescriptor, sc catalog.SchemaDescriptor, - lookupFilters func(builder descs.ByIDGetterBuilder) descs.ByIDGetterBuilder, + withLeased bool, renameDescType catalog.DescriptorType, ) error { _, ids, err := p.GetObjectNamesAndIDs(ctx, db, sc) if err != nil { return err } - b := lookupFilters(p.Descriptors().ByID(p.txn)) - descs, err := b.Immutable().Descs(ctx, ids) + var b descs.ByIDGetterBuilder + if withLeased { + b = p.Descriptors().ByIDWithLeased(p.txn) + } else { + b = p.Descriptors().ByID(p.txn) + } + descs, err := b.WithoutNonPublic().Get().Descs(ctx, ids) if err != nil { return err } @@ -235,7 +235,7 @@ func maybeFailOnDependentDescInRename( } if err := tbDesc.ForeachDependedOnBy(func(dependedOn *descpb.TableDescriptor_Reference) error { - dependentDesc, err := p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, dependedOn.ID) + dependentDesc, err := p.Descriptors().MutableByID(p.txn).Desc(ctx, dependedOn.ID) if err != nil { return err } diff --git a/pkg/sql/rename_table.go b/pkg/sql/rename_table.go index 844b5803acf8..2a6eafc4a767 100644 --- a/pkg/sql/rename_table.go +++ b/pkg/sql/rename_table.go @@ -252,7 +252,7 @@ func (n *renameTableNode) Close(context.Context) {} func (p *planner) dependentError( ctx context.Context, typeName string, objName string, parentID descpb.ID, id descpb.ID, op string, ) error { - desc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Desc(ctx, id) + desc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Desc(ctx, id) if err != nil { return err } @@ -324,7 +324,7 @@ func (n *renameTableNode) checkForCrossDbReferences( tableID = fk.GetOriginTableID() } - referencedTable, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, tableID) + referencedTable, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Table(ctx, tableID) if err != nil { return err } @@ -348,7 +348,7 @@ func (n *renameTableNode) checkForCrossDbReferences( type crossDBDepType int const owner, reference crossDBDepType = 0, 1 checkDepForCrossDbRef := func(depID descpb.ID, depType crossDBDepType) error { - dependentObject, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, depID) + dependentObject, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Table(ctx, depID) if err != nil { return err } @@ -444,7 +444,7 @@ func (n *renameTableNode) checkForCrossDbReferences( if allowCrossDatabaseViews.Get(&p.execCfg.Settings.SV) { return nil } - dependentObject, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Type(ctx, depID) + dependentObject, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Type(ctx, depID) if err != nil { return err } diff --git a/pkg/sql/repair.go b/pkg/sql/repair.go index 6832887c51ad..66ee176bb295 100644 --- a/pkg/sql/repair.go +++ b/pkg/sql/repair.go @@ -418,7 +418,7 @@ func (p *planner) UnsafeUpsertNamespaceEntry( existingID = descpb.ID(val.ValueInt()) } validateDescriptor := func() error { - desc, err := p.byIDGetterBuilder().Immutable().Desc(ctx, descID) + desc, err := p.byIDGetterBuilder().Get().Desc(ctx, descID) if err != nil && descID != keys.PublicSchemaID { return errors.Wrapf(err, "failed to retrieve descriptor %d", descID) } @@ -452,7 +452,7 @@ func (p *planner) UnsafeUpsertNamespaceEntry( if parentID == descpb.InvalidID { return nil } - parent, err := p.byIDGetterBuilder().Immutable().Desc(ctx, parentID) + parent, err := p.byIDGetterBuilder().Get().Desc(ctx, parentID) if err != nil { return errors.Wrapf(err, "failed to look up parent %d", parentID) } @@ -466,7 +466,7 @@ func (p *planner) UnsafeUpsertNamespaceEntry( if parentSchemaID == descpb.InvalidID || parentSchemaID == keys.PublicSchemaID { return nil } - schema, err := p.byIDGetterBuilder().Immutable().Desc(ctx, parentSchemaID) + schema, err := p.byIDGetterBuilder().Get().Desc(ctx, parentSchemaID) if err != nil { return err } @@ -662,7 +662,7 @@ func (p *planner) UnsafeDeleteDescriptor(ctx context.Context, descID int64, forc func unsafeReadDescriptor( ctx context.Context, p *planner, id descpb.ID, force bool, ) (mut catalog.MutableDescriptor, notice error, err error) { - mut, err = p.Descriptors().ByID(p.txn).Mutable().Desc(ctx, id) + mut, err = p.Descriptors().MutableByID(p.txn).Desc(ctx, id) if mut != nil { return mut, nil, nil } @@ -714,7 +714,7 @@ func (p *planner) ForceDeleteTableData(ctx context.Context, descID int64) error // Validate no descriptor exists for this table id := descpb.ID(descID) - desc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, id) + desc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Table(ctx, id) if err != nil && pgerror.GetPGCode(err) != pgcode.UndefinedTable { return err } diff --git a/pkg/sql/resolver.go b/pkg/sql/resolver.go index c2a17d6294e0..94ebc2410b8e 100644 --- a/pkg/sql/resolver.go +++ b/pkg/sql/resolver.go @@ -195,7 +195,7 @@ func (p *planner) ResolveDescriptorForPrivilegeSpecifier( ctx, p.txn, *specifier.DatabaseName, tree.DatabaseLookupFlags{Required: true}, ) } else if specifier.DatabaseOID != nil { - database, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Database(ctx, descpb.ID(*specifier.DatabaseOID)) + database, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Database(ctx, descpb.ID(*specifier.DatabaseOID)) // When a DatabaseOID is specified and the database is not found, // we return NULL. if err != nil && sqlerrors.IsUndefinedDatabaseError(err) { @@ -236,7 +236,7 @@ func (p *planner) ResolveDescriptorForPrivilegeSpecifier( ctx, p.txn, tn, tree.ObjectLookupFlags{}, ) } else { - table, err = p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(*specifier.TableOID)) + table, err = p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(*specifier.TableOID)) // When a TableOID is specified and the relation is not found, we return NULL. if err != nil && sqlerrors.IsUndefinedRelationError(err) { // nolint:returnerrcheck @@ -263,7 +263,7 @@ func (p *planner) ResolveDescriptorForPrivilegeSpecifier( return table, nil } else if specifier.FunctionOID != nil { fnID := funcdesc.UserDefinedFunctionOIDToID(*specifier.FunctionOID) - return p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Function(ctx, fnID) + return p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Function(ctx, fnID) } return nil, errors.AssertionFailedf("invalid HasPrivilegeSpecifier") } @@ -375,7 +375,7 @@ func (p *planner) getDescriptorsFromTargetListForPrivilegeChange( continue } fnResolved.Add(fnID) - fnDesc, err := p.Descriptors().ByID(p.txn).Mutable().Function(ctx, fnID) + fnDesc, err := p.Descriptors().MutableByID(p.txn).Function(ctx, fnID) if err != nil { return nil, err } @@ -413,7 +413,7 @@ func (p *planner) getDescriptorsFromTargetListForPrivilegeChange( if err != nil { return nil, err } - muts, err := p.Descriptors().ByID(p.txn).Mutable().Descs(ctx, objectIDs) + muts, err := p.Descriptors().MutableByID(p.txn).Descs(ctx, objectIDs) if err != nil { return nil, err } @@ -468,7 +468,7 @@ func (p *planner) getDescriptorsFromTargetListForPrivilegeChange( return nil, err } err = sc.ForEachFunctionOverload(func(overload descpb.SchemaDescriptor_FunctionOverload) error { - fn, err := p.Descriptors().ByID(p.txn).Mutable().Function(ctx, overload.ID) + fn, err := p.Descriptors().MutableByID(p.txn).Function(ctx, overload.ID) if err != nil { return err } @@ -521,7 +521,7 @@ func (p *planner) getDescriptorsFromTargetListForPrivilegeChange( } switch resSchema.SchemaKind() { case catalog.SchemaUserDefined: - mutSchema, err := p.Descriptors().ByID(p.txn).Mutable().Schema(ctx, resSchema.GetID()) + mutSchema, err := p.Descriptors().MutableByID(p.txn).Schema(ctx, resSchema.GetID()) if err != nil { return nil, err } @@ -550,7 +550,7 @@ func (p *planner) getDescriptorsFromTargetListForPrivilegeChange( if err != nil { return nil, err } - muts, err := p.Descriptors().ByID(p.txn).Mutable().Descs(ctx, objectIDs) + muts, err := p.Descriptors().MutableByID(p.txn).Descs(ctx, objectIDs) if err != nil { return nil, err } @@ -592,7 +592,7 @@ func (p *planner) getFullyQualifiedTableNamesFromIDs( ctx context.Context, ids []descpb.ID, ) (fullyQualifiedNames []string, _ error) { for _, id := range ids { - desc, err := p.Descriptors().ByID(p.txn).WithoutLeased().Immutable().Desc(ctx, id) + desc, err := p.Descriptors().ByID(p.txn).Get().Desc(ctx, id) if err != nil { return nil, err } @@ -619,7 +619,7 @@ func (p *planner) getFullyQualifiedTableNamesFromIDs( func (p *planner) getQualifiedSchemaName( ctx context.Context, desc catalog.SchemaDescriptor, ) (*tree.ObjectNamePrefix, error) { - dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, desc.GetParentID()) if err != nil { return nil, err } @@ -636,13 +636,13 @@ func (p *planner) getQualifiedSchemaName( func (p *planner) getQualifiedTypeName( ctx context.Context, desc catalog.TypeDescriptor, ) (*tree.TypeName, error) { - dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + dbDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Get().Database(ctx, desc.GetParentID()) if err != nil { return nil, err } schemaID := desc.GetParentSchemaID() - scDesc, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Schema(ctx, schemaID) + scDesc, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Schema(ctx, schemaID) if err != nil { return nil, err } @@ -717,7 +717,7 @@ func expandIndexName( // Memoize the table name that was found. tn is a reference to the table name // stored in index.Table. *tn = tableName - tblMutable, err := p.Descriptors().ByID(p.Txn()).Mutable().Table(ctx, tbl.GetID()) + tblMutable, err := p.Descriptors().MutableByID(p.Txn()).Table(ctx, tbl.GetID()) if err != nil { return nil, nil, err } @@ -770,7 +770,7 @@ func (p *planner) getTableAndIndexImpl( // Use the descriptor collection to get a proper handle to the mutable // descriptor for the relevant table and use that mutable object to // get a handle to the corresponding index. - mut, err := p.Descriptors().ByID(p.Txn()).Mutable().Table(ctx, tbl.GetID()) + mut, err := p.Descriptors().MutableByID(p.Txn()).Table(ctx, tbl.GetID()) if err != nil { return catalog.ResolvedObjectPrefix{}, nil, nil, errors.NewAssertionErrorWithWrappedErrf(err, "failed to re-resolve table %d for index %s", tbl.GetID(), tableWithIndex) diff --git a/pkg/sql/row/row_converter.go b/pkg/sql/row/row_converter.go index caf66ae6c62f..43a8752e3ca1 100644 --- a/pkg/sql/row/row_converter.go +++ b/pkg/sql/row/row_converter.go @@ -277,7 +277,7 @@ func (c *DatumRowConverter) getSequenceAnnotation( if err := txn.SetFixedTimestamp(ctx, hlc.Timestamp{WallTime: evalCtx.TxnTimestamp.UnixNano()}); err != nil { return err } - seqs, err := descsCol.ByID(txn).WithoutLeased().Immutable().Descs(ctx, sequenceIDs.Ordered()) + seqs, err := descsCol.ByID(txn).Get().Descs(ctx, sequenceIDs.Ordered()) if err != nil { return err } diff --git a/pkg/sql/rowexec/backfiller.go b/pkg/sql/rowexec/backfiller.go index 87953cdcf1cc..ec0ec23eebbc 100644 --- a/pkg/sql/rowexec/backfiller.go +++ b/pkg/sql/rowexec/backfiller.go @@ -201,7 +201,7 @@ func GetResumeSpans( mutationID descpb.MutationID, filter backfill.MutationFilter, ) ([]roachpb.Span, *jobs.Job, int, error) { - tableDesc, err := col.ByID(txn).WithoutLeased().Immutable().Table(ctx, tableID) + tableDesc, err := col.ByID(txn).Get().Table(ctx, tableID) if err != nil { return nil, nil, 0, err } diff --git a/pkg/sql/schema_change_plan_node.go b/pkg/sql/schema_change_plan_node.go index 86c65489c53e..05b8ddc2930c 100644 --- a/pkg/sql/schema_change_plan_node.go +++ b/pkg/sql/schema_change_plan_node.go @@ -197,7 +197,7 @@ func (p *planner) waitForDescriptorSchemaChanges( if err := txn.SetFixedTimestamp(ctx, now); err != nil { return err } - desc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Desc(ctx, descID) + desc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Desc(ctx, descID) if err != nil { return err } diff --git a/pkg/sql/schema_changer.go b/pkg/sql/schema_changer.go index 29b243ccc95c..73edd81e4e68 100644 --- a/pkg/sql/schema_changer.go +++ b/pkg/sql/schema_changer.go @@ -448,7 +448,7 @@ func (sc *SchemaChanger) maybeMakeAddTablePublic( log.Info(ctx, "making table public") return sc.txn(ctx, func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - mut, err := descsCol.ByID(txn).Mutable().Table(ctx, table.GetID()) + mut, err := descsCol.MutableByID(txn).Table(ctx, table.GetID()) if err != nil { return err } @@ -489,7 +489,7 @@ func (sc *SchemaChanger) ignoreRevertedDropIndex( return nil } return sc.txn(ctx, func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - mut, err := descsCol.ByID(txn).Mutable().Table(ctx, table.GetID()) + mut, err := descsCol.MutableByID(txn).Table(ctx, table.GetID()) if err != nil { return err } @@ -583,7 +583,7 @@ func (sc *SchemaChanger) getTargetDescriptor(ctx context.Context) (catalog.Descr if err := sc.txn(ctx, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - desc, err = descriptors.ByID(txn).WithoutLeased().Immutable().Desc(ctx, sc.descID) + desc, err = descriptors.ByID(txn).Get().Desc(ctx, sc.descID) return err }); err != nil { return nil, err @@ -887,7 +887,7 @@ func (sc *SchemaChanger) handlePermanentSchemaChangeError( // initialize the job running status. func (sc *SchemaChanger) initJobRunningStatus(ctx context.Context) error { return sc.txn(ctx, func(ctx context.Context, txn *kv.Txn, descriptors *descs.Collection) error { - desc, err := descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, sc.descID) + desc, err := descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, sc.descID) if err != nil { return err } @@ -930,7 +930,7 @@ func (sc *SchemaChanger) dropViewDeps( // Remove back-references from the tables/views this view depends on. dependedOn := append([]descpb.ID(nil), viewDesc.DependsOn...) for _, depID := range dependedOn { - dependencyDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, depID) + dependencyDesc, err := descsCol.MutableByID(txn).Table(ctx, depID) if err != nil { log.Warningf(ctx, "error resolving dependency relation ID %d", depID) continue @@ -950,7 +950,7 @@ func (sc *SchemaChanger) dropViewDeps( // If anything depends on this table clean up references from that object as well. DependedOnBy := append([]descpb.TableDescriptor_Reference(nil), viewDesc.DependedOnBy...) for _, depRef := range DependedOnBy { - dependencyDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, depRef.ID) + dependencyDesc, err := descsCol.MutableByID(txn).Table(ctx, depRef.ID) if err != nil { log.Warningf(ctx, "error resolving dependency relation ID %d", depRef.ID) continue @@ -970,7 +970,7 @@ func (sc *SchemaChanger) dropViewDeps( return err } for id := range typeClosure { - typeDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, id) + typeDesc, err := descsCol.MutableByID(txn).Type(ctx, id) if err != nil { log.Warningf(ctx, "error resolving type dependency %d", id) continue @@ -983,7 +983,7 @@ func (sc *SchemaChanger) dropViewDeps( } for i := 0; i < col.NumUsesSequences(); i++ { id := col.GetUsesSequenceID(i) - seqDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, id) + seqDesc, err := descsCol.MutableByID(txn).Table(ctx, id) if err != nil { log.Warningf(ctx, "error resolving sequence dependency %d", id) continue @@ -1030,7 +1030,7 @@ func (sc *SchemaChanger) rollbackSchemaChange(ctx context.Context, err error) er // clean up the descriptor. gcJobID := sc.jobRegistry.MakeJobID() if err := sc.txn(ctx, func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - scTable, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + scTable, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } @@ -1091,11 +1091,11 @@ func (sc *SchemaChanger) RunStateMachineBeforeBackfill(ctx context.Context) erro if err := sc.txn(ctx, func( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { - tbl, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + tbl, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, tbl.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, tbl.GetParentID()) if err != nil { return err } @@ -1197,7 +1197,7 @@ func (sc *SchemaChanger) stepStateMachineAfterIndexBackfill(ctx context.Context) if err := sc.txn(ctx, func( ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { - tbl, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + tbl, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } @@ -1342,19 +1342,19 @@ func (sc *SchemaChanger) done(ctx context.Context) error { depMutationJobs = depMutationJobs[:0] otherJobIDs = otherJobIDs[:0] var err error - scTable, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + scTable, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, scTable.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, scTable.GetParentID()) if err != nil { return err } collectReferencedTypeIDs := func() (catalog.DescriptorIDSet, error) { typeLookupFn := func(id descpb.ID) (catalog.TypeDescriptor, error) { - desc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Type(ctx, id) + desc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Type(ctx, id) if err != nil { return nil, err } @@ -1410,7 +1410,7 @@ func (sc *SchemaChanger) done(ctx context.Context) error { if fk := m.AsForeignKey(); fk != nil && fk.Adding() && fk.GetConstraintValidity() == descpb.ConstraintValidity_Unvalidated { // Add backreference on the referenced table (which could be the same table) - backrefTable, err := descsCol.ByID(txn).Mutable().Table(ctx, fk.GetReferencedTableID()) + backrefTable, err := descsCol.MutableByID(txn).Table(ctx, fk.GetReferencedTableID()) if err != nil { return err } @@ -1682,7 +1682,7 @@ func (sc *SchemaChanger) done(ctx context.Context) error { // Update the set of back references. for id, isAddition := range update { - typ, err := descsCol.ByID(txn).Mutable().Type(ctx, id) + typ, err := descsCol.MutableByID(txn).Type(ctx, id) if err != nil { return err } @@ -1723,7 +1723,7 @@ func (sc *SchemaChanger) done(ctx context.Context) error { // Update the set of back references. for id, colIDSet := range update { - tbl, err := descsCol.ByID(txn).Mutable().Table(ctx, id) + tbl, err := descsCol.MutableByID(txn).Table(ctx, id) if err != nil { return err } @@ -1915,7 +1915,7 @@ func (sc *SchemaChanger) maybeReverseMutations(ctx context.Context, causingError alreadyReversed := false const kvTrace = true // TODO(ajwerner): figure this out err := sc.txn(ctx, func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - scTable, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + scTable, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } @@ -1988,7 +1988,7 @@ func (sc *SchemaChanger) maybeReverseMutations(ctx context.Context, causingError } // Get the foreign key backreferences to remove. if fk := constraint.AsForeignKey(); fk != nil { - backrefTable, err := descsCol.ByID(txn).Mutable().Table(ctx, fk.GetReferencedTableID()) + backrefTable, err := descsCol.MutableByID(txn).Table(ctx, fk.GetReferencedTableID()) if err != nil { return err } @@ -3062,7 +3062,7 @@ func (sc *SchemaChanger) preSplitHashShardedIndexRanges(ctx context.Context) err ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, ) error { hour := hlc.Timestamp{WallTime: timeutil.Now().Add(time.Hour).UnixNano()} - tableDesc, err := descsCol.ByID(txn).Mutable().Table(ctx, sc.descID) + tableDesc, err := descsCol.MutableByID(txn).Table(ctx, sc.descID) if err != nil { return err } diff --git a/pkg/sql/schema_changer_test.go b/pkg/sql/schema_changer_test.go index 1f14367a489b..393c043a9d24 100644 --- a/pkg/sql/schema_changer_test.go +++ b/pkg/sql/schema_changer_test.go @@ -1503,7 +1503,7 @@ CREATE TABLE t.test (k INT PRIMARY KEY, v INT); timeoutCtx, cancel := context.WithTimeout(ctx, base.DefaultDescriptorLeaseDuration/2) defer cancel() if err := sql.TestingDescsTxn(timeoutCtx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { - tbl, err := col.ByID(txn).Mutable().Table(ctx, tableDesc.GetID()) + tbl, err := col.MutableByID(txn).Table(ctx, tableDesc.GetID()) if err != nil { return err } diff --git a/pkg/sql/schema_resolver.go b/pkg/sql/schema_resolver.go index 7d498c8909fd..5aec6442136b 100644 --- a/pkg/sql/schema_resolver.go +++ b/pkg/sql/schema_resolver.go @@ -119,11 +119,10 @@ func (sr *schemaResolver) CommonLookupFlagsRequired() tree.CommonLookupFlags { } func (sr *schemaResolver) byIDGetterBuilder() descs.ByIDGetterBuilder { - b := sr.descCollection.ByID(sr.txn) if sr.skipDescriptorCache { - return b.WithoutLeased() + return sr.descCollection.ByID(sr.txn) } - return b + return sr.descCollection.ByIDWithLeased(sr.txn) } // LookupObject implements the tree.ObjectNameExistingResolver interface. @@ -226,7 +225,7 @@ func (sr *schemaResolver) CurrentDatabase() string { func (sr *schemaResolver) GetQualifiedTableNameByID( ctx context.Context, id int64, requiredType tree.RequiredTableKind, ) (*tree.TableName, error) { - table, err := sr.descCollection.ByID(sr.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(id)) + table, err := sr.descCollection.ByIDWithLeased(sr.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(id)) if err != nil { return nil, err } @@ -239,7 +238,7 @@ func (sr *schemaResolver) GetQualifiedTableNameByID( func (sr *schemaResolver) getQualifiedTableName( ctx context.Context, desc catalog.TableDescriptor, ) (*tree.TableName, error) { - dbDesc, err := sr.descCollection.ByID(sr.txn).WithoutLeased().Immutable().Database(ctx, desc.GetParentID()) + dbDesc, err := sr.descCollection.ByID(sr.txn).Get().Database(ctx, desc.GetParentID()) if err != nil { return nil, err } @@ -253,7 +252,7 @@ func (sr *schemaResolver) getQualifiedTableName( // information from the namespace table. var schemaName tree.Name schemaID := desc.GetParentSchemaID() - scDesc, err := sr.descCollection.ByID(sr.txn).WithoutLeased().Immutable().Schema(ctx, schemaID) + scDesc, err := sr.descCollection.ByID(sr.txn).Get().Schema(ctx, schemaID) switch { case scDesc != nil: schemaName = tree.Name(scDesc.GetName()) @@ -282,11 +281,11 @@ func (sr *schemaResolver) getQualifiedTableName( func (sr *schemaResolver) getQualifiedFunctionName( ctx context.Context, fnDesc catalog.FunctionDescriptor, ) (*tree.FunctionName, error) { - dbDesc, err := sr.descCollection.ByID(sr.txn).WithoutLeased().Immutable().Database(ctx, fnDesc.GetParentID()) + dbDesc, err := sr.descCollection.ByID(sr.txn).Get().Database(ctx, fnDesc.GetParentID()) if err != nil { return nil, err } - scDesc, err := sr.descCollection.ByID(sr.txn).WithoutLeased().Immutable().Schema(ctx, fnDesc.GetParentSchemaID()) + scDesc, err := sr.descCollection.ByID(sr.txn).Get().Schema(ctx, fnDesc.GetParentSchemaID()) if err != nil { return nil, err } @@ -346,7 +345,7 @@ func (sr *schemaResolver) ResolveTypeByOID(ctx context.Context, oid oid.Oid) (*t func (sr *schemaResolver) GetTypeDescriptor( ctx context.Context, id descpb.ID, ) (tree.TypeName, catalog.TypeDescriptor, error) { - g := sr.byIDGetterBuilder().WithoutNonPublic().WithoutOtherParent(sr.typeResolutionDbID).Immutable() + g := sr.byIDGetterBuilder().WithoutNonPublic().WithoutOtherParent(sr.typeResolutionDbID).Get() desc, err := g.Type(ctx, id) if err != nil { return tree.TypeName{}, nil, err @@ -566,7 +565,7 @@ func (sr *schemaResolver) ResolveFunctionByOID( } } - g := sr.byIDGetterBuilder().WithoutNonPublic().WithoutOtherParent(sr.typeResolutionDbID).Immutable() + g := sr.byIDGetterBuilder().WithoutNonPublic().WithoutOtherParent(sr.typeResolutionDbID).Get() descID := funcdesc.UserDefinedFunctionOIDToID(oid) funcDesc, err := g.Function(ctx, descID) if err != nil { diff --git a/pkg/sql/schemachanger/scdeps/build_deps.go b/pkg/sql/schemachanger/scdeps/build_deps.go index e1527e98b11a..b962faf537d9 100644 --- a/pkg/sql/schemachanger/scdeps/build_deps.go +++ b/pkg/sql/schemachanger/scdeps/build_deps.go @@ -230,7 +230,7 @@ func (d *buildDeps) CurrentDatabase() string { // MustReadDescriptor implements the scbuild.CatalogReader interface. func (d *buildDeps) MustReadDescriptor(ctx context.Context, id descpb.ID) catalog.Descriptor { - desc, err := d.descsCollection.ByID(d.txn).WithoutLeased().Immutable().Desc(ctx, id) + desc, err := d.descsCollection.ByID(d.txn).Get().Desc(ctx, id) if err != nil { panic(err) } diff --git a/pkg/sql/schemachanger/scdeps/exec_deps.go b/pkg/sql/schemachanger/scdeps/exec_deps.go index 496786a80b18..398190a81a14 100644 --- a/pkg/sql/schemachanger/scdeps/exec_deps.go +++ b/pkg/sql/schemachanger/scdeps/exec_deps.go @@ -132,12 +132,12 @@ var _ scexec.Catalog = (*txnDeps)(nil) func (d *txnDeps) MustReadImmutableDescriptors( ctx context.Context, ids ...descpb.ID, ) ([]catalog.Descriptor, error) { - return d.descsCollection.ByID(d.txn).WithoutSynthetic().WithoutLeased().Immutable().Descs(ctx, ids) + return d.descsCollection.ByID(d.txn).WithoutSynthetic().Get().Descs(ctx, ids) } // GetFullyQualifiedName implements the scmutationexec.CatalogReader interface func (d *txnDeps) GetFullyQualifiedName(ctx context.Context, id descpb.ID) (string, error) { - g := d.descsCollection.ByID(d.txn).WithoutSynthetic().WithoutLeased().Immutable() + g := d.descsCollection.ByID(d.txn).WithoutSynthetic().Get() objectDesc, err := g.Desc(ctx, id) if err != nil { return "", err @@ -176,7 +176,7 @@ func (d *txnDeps) GetFullyQualifiedName(ctx context.Context, id descpb.ID) (stri func (d *txnDeps) MustReadMutableDescriptor( ctx context.Context, id descpb.ID, ) (catalog.MutableDescriptor, error) { - return d.descsCollection.ByID(d.txn).Mutable().Desc(ctx, id) + return d.descsCollection.MutableByID(d.txn).Desc(ctx, id) } // AddSyntheticDescriptor is part of the @@ -314,7 +314,7 @@ func (d *txnDeps) MaybeSplitIndexSpans( func (d *txnDeps) GetResumeSpans( ctx context.Context, tableID descpb.ID, indexID descpb.IndexID, ) ([]roachpb.Span, error) { - table, err := d.descsCollection.ByID(d.txn).WithoutNonPublic().WithoutLeased().WithoutSynthetic().Immutable().Table(ctx, tableID) + table, err := d.descsCollection.ByID(d.txn).WithoutNonPublic().WithoutSynthetic().Get().Table(ctx, tableID) if err != nil { return nil, err } diff --git a/pkg/sql/schemachanger/scdeps/run_deps.go b/pkg/sql/schemachanger/scdeps/run_deps.go index 3b70c3bac65c..a9f8dd9de176 100644 --- a/pkg/sql/schemachanger/scdeps/run_deps.go +++ b/pkg/sql/schemachanger/scdeps/run_deps.go @@ -159,7 +159,7 @@ func (d *jobExecutionDeps) WithTxnInJob(ctx context.Context, fn scrun.JobTxnFunc ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { for _, id := range tableStatsToRefresh { - tbl, err := descriptors.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, id) + tbl, err := descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, id) if err != nil { return err } diff --git a/pkg/sql/scrub.go b/pkg/sql/scrub.go index 59dafac8e6ee..16581ac08b33 100644 --- a/pkg/sql/scrub.go +++ b/pkg/sql/scrub.go @@ -439,7 +439,7 @@ func createConstraintCheckOperations( if ck := constraint.AsCheck(); ck != nil { op = newSQLCheckConstraintCheckOperation(tableName, tableDesc, ck, asOf) } else if fk := constraint.AsForeignKey(); fk != nil { - referencedTable, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Immutable().Table(ctx, fk.GetReferencedTableID()) + referencedTable, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Table(ctx, fk.GetReferencedTableID()) if err != nil { return nil, err } diff --git a/pkg/sql/sequence.go b/pkg/sql/sequence.go index ff311cab7429..fe9e70fb9007 100644 --- a/pkg/sql/sequence.go +++ b/pkg/sql/sequence.go @@ -56,7 +56,7 @@ func (p *planner) GetSerialSequenceNameFromColumn( // as well as backward compatibility) so we're using this heuristic for now. // TODO(#52487): fix this up. if col.NumUsesSequences() == 1 { - seq, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, col.GetUsesSequenceID(0)) + seq, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, col.GetUsesSequenceID(0)) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func (p *planner) IncrementSequenceByID(ctx context.Context, seqID int64) (int64 if p.EvalContext().TxnReadOnly { return 0, readOnlyError("nextval()") } - descriptor, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(seqID)) + descriptor, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(seqID)) if err != nil { return 0, err } @@ -245,7 +245,7 @@ func boundsExceededError(descriptor catalog.TableDescriptor) error { func (p *planner) GetLatestValueInSessionForSequenceByID( ctx context.Context, seqID int64, ) (int64, error) { - descriptor, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(seqID)) + descriptor, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(seqID)) if err != nil { return 0, err } @@ -283,7 +283,7 @@ func (p *planner) SetSequenceValueByID( return readOnlyError("setval()") } - descriptor, err := p.Descriptors().ByID(p.txn).WithoutNonPublic().Immutable().Table(ctx, descpb.ID(seqID)) + descriptor, err := p.Descriptors().ByIDWithLeased(p.txn).WithoutNonPublic().Get().Table(ctx, descpb.ID(seqID)) if err != nil { return err } @@ -507,7 +507,7 @@ func removeSequenceOwnerIfExists( if !opts.HasOwner() { return nil } - tableDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, opts.SequenceOwner.OwnerTableID) + tableDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, opts.SequenceOwner.OwnerTableID) if err != nil { // Special case error swallowing for #50711 and #50781, which can cause a // column to own sequences that have been dropped/do not exist. @@ -754,7 +754,7 @@ func (p *planner) dropSequencesOwnedByCol( } for _, sequenceID := range colOwnsSequenceIDs { - seqDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, sequenceID) + seqDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, sequenceID) // Special case error swallowing for #50781, which can cause a // column to own sequences that do not exist. if err != nil { @@ -794,7 +794,7 @@ func (p *planner) removeSequenceDependencies( for i := 0; i < col.NumUsesSequences(); i++ { sequenceID := col.GetUsesSequenceID(i) // Get the sequence descriptor so we can remove the reference from it. - seqDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, sequenceID) + seqDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, sequenceID) if err != nil { return err } diff --git a/pkg/sql/stats/automatic_stats.go b/pkg/sql/stats/automatic_stats.go index b3a8ccea1dd5..8766afb46a53 100644 --- a/pkg/sql/stats/automatic_stats.go +++ b/pkg/sql/stats/automatic_stats.go @@ -354,7 +354,7 @@ func (r *Refresher) getTableDescriptor( if err := r.cache.internalExecutorFactory.DescsTxn(ctx, r.cache.ClientDB, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - if desc, err = descriptors.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, tableID); err != nil { + if desc, err = descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, tableID); err != nil { err = errors.Wrapf(err, "failed to get table descriptor for automatic stats on table id: %d", tableID) } diff --git a/pkg/sql/table_test.go b/pkg/sql/table_test.go index e1ef8a81ee9a..33c24f725238 100644 --- a/pkg/sql/table_test.go +++ b/pkg/sql/table_test.go @@ -442,7 +442,7 @@ CREATE TABLE test.tt (x test.t); typLookup := func(ctx context.Context, id descpb.ID) (tree.TypeName, catalog.TypeDescriptor, error) { var typeDesc catalog.TypeDescriptor if err := TestingDescsTxn(ctx, s, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) (err error) { - typeDesc, err = col.ByID(txn).WithoutLeased().Immutable().Type(ctx, id) + typeDesc, err = col.ByID(txn).Get().Type(ctx, id) return err }); err != nil { return tree.TypeName{}, nil, err diff --git a/pkg/sql/temporary_schema.go b/pkg/sql/temporary_schema.go index 3a2a03aa74cf..2d8054180c5f 100644 --- a/pkg/sql/temporary_schema.go +++ b/pkg/sql/temporary_schema.go @@ -122,8 +122,7 @@ func (p *planner) getOrCreateTemporarySchema( m.SetTemporarySchemaName(tempSchemaName) m.SetTemporarySchemaIDForDatabase(uint32(db.GetID()), uint32(id)) }) - g := p.byIDGetterBuilder().WithoutNonPublic().Immutable() - return g.Schema(ctx, id) + return p.byIDGetterBuilder().WithoutNonPublic().Get().Schema(ctx, id) } // temporarySchemaName returns the session specific temporary schema name given @@ -308,15 +307,15 @@ func cleanupTempSchemaObjects( if _, ok := tblDescsByID[d.ID]; ok { return nil } - dTableDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, d.ID) + dTableDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Table(ctx, d.ID) if err != nil { return err } - db, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, dTableDesc.GetParentID()) + db, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, dTableDesc.GetParentID()) if err != nil { return err } - sc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Schema(ctx, dTableDesc.GetParentSchemaID()) + sc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Schema(ctx, dTableDesc.GetParentSchemaID()) if err != nil { return err } diff --git a/pkg/sql/temporary_schema_test.go b/pkg/sql/temporary_schema_test.go index ee88682e487f..9682a0132e75 100644 --- a/pkg/sql/temporary_schema_test.go +++ b/pkg/sql/temporary_schema_test.go @@ -104,7 +104,7 @@ INSERT INTO perm_table VALUES (DEFAULT, 1); ) error { // Add a hack to not wait for one version on the descriptors. defer descsCol.ReleaseAll(ctx) - defaultDB, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, namesToID["defaultdb"]) + defaultDB, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, namesToID["defaultdb"]) if err != nil { return err } diff --git a/pkg/sql/truncate.go b/pkg/sql/truncate.go index ea9b8903240e..36f56b301efb 100644 --- a/pkg/sql/truncate.go +++ b/pkg/sql/truncate.go @@ -89,7 +89,7 @@ func (t *truncateNode) startExec(params runParams) error { if _, ok := toTruncate[tableID]; ok { return nil } - other, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, tableID) + other, err := p.Descriptors().MutableByID(p.txn).Table(ctx, tableID) if err != nil { return err } @@ -163,7 +163,7 @@ var PreservedSplitCountMultiple = settings.RegisterIntSetting( func (p *planner) truncateTable(ctx context.Context, id descpb.ID, jobDesc string) error { // Read the table descriptor because it might have changed // while another table in the truncation list was truncated. - tableDesc, err := p.Descriptors().ByID(p.txn).Mutable().Table(ctx, id) + tableDesc, err := p.Descriptors().MutableByID(p.txn).Table(ctx, id) if err != nil { return err } diff --git a/pkg/sql/ttl/ttljob/ttljob.go b/pkg/sql/ttl/ttljob/ttljob.go index 4a6d0dc1243d..208ab4a425da 100644 --- a/pkg/sql/ttl/ttljob/ttljob.go +++ b/pkg/sql/ttl/ttljob/ttljob.go @@ -113,7 +113,7 @@ func (t rowLevelTTLResumer) Resume(ctx context.Context, execCtx interface{}) err var relationName string var entirePKSpan roachpb.Span if err := db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { - desc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, details.TableID) + desc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, details.TableID) if err != nil { return err } diff --git a/pkg/sql/ttl/ttljob/ttljob_processor.go b/pkg/sql/ttl/ttljob/ttljob_processor.go index d6607ff1ab20..a9739cfd0cbb 100644 --- a/pkg/sql/ttl/ttljob/ttljob_processor.go +++ b/pkg/sql/ttl/ttljob/ttljob_processor.go @@ -69,7 +69,7 @@ func (t *ttlProcessor) work(ctx context.Context) error { var pkTypes []*types.T var labelMetrics bool if err := serverCfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { - desc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, details.TableID) + desc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, details.TableID) if err != nil { return err } @@ -297,7 +297,7 @@ func (t *ttlProcessor) runTTLOnSpan( if err := serverCfg.DB.TxnWithSteppingEnabled(ctx, sessiondatapb.TTLLow, func(ctx context.Context, txn *kv.Txn) error { // If we detected a schema change here, the DELETE will not succeed // (the SELECT still will because of the AOST). Early exit here. - desc, err := flowCtx.Descriptors.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, details.TableID) + desc, err := flowCtx.Descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, details.TableID) if err != nil { return err } diff --git a/pkg/sql/ttl/ttlschedule/ttlschedule.go b/pkg/sql/ttl/ttlschedule/ttlschedule.go index 8842411d8af9..6ef8e4853f3d 100644 --- a/pkg/sql/ttl/ttlschedule/ttlschedule.go +++ b/pkg/sql/ttl/ttlschedule/ttlschedule.go @@ -71,7 +71,7 @@ func (s rowLevelTTLExecutor) OnDrop( } if !canDrop { - tbl, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, args.TableID) + tbl, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, args.TableID) if err != nil { return 0, err } @@ -101,7 +101,7 @@ func canDropTTLSchedule( schedule *jobs.ScheduledJob, args catpb.ScheduledRowLevelTTLArgs, ) (bool, error) { - desc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, args.TableID) + desc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, args.TableID) if err != nil { // If the descriptor does not exist we can drop this schedule. if sqlerrors.IsUndefinedRelationError(err) { @@ -208,7 +208,7 @@ func (s rowLevelTTLExecutor) GetCreateScheduleStatement( if err := pbtypes.UnmarshalAny(sj.ExecutionArgs().Args, args); err != nil { return "", err } - tbl, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, args.TableID) + tbl, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, args.TableID) if err != nil { return "", err } @@ -254,7 +254,7 @@ func createRowLevelTTLJob( jobRegistry *jobs.Registry, ttlArgs catpb.ScheduledRowLevelTTLArgs, ) (jobspb.JobID, error) { - tableDesc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, ttlArgs.TableID) + tableDesc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, ttlArgs.TableID) if err != nil { return 0, err } diff --git a/pkg/sql/type_change.go b/pkg/sql/type_change.go index d91bc9807fa8..584aeeeca495 100644 --- a/pkg/sql/type_change.go +++ b/pkg/sql/type_change.go @@ -199,7 +199,7 @@ func (t *typeSchemaChanger) getTypeDescFromStore( if err := DescsTxn(ctx, t.execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { // Avoid GetImmutableTypeByID, downstream logic relies on // catalog.ErrDescriptorNotFound. - desc, err := col.ByID(txn).WithoutLeased().Immutable().Desc(ctx, t.typeID) + desc, err := col.ByID(txn).Get().Desc(ctx, t.typeID) if err != nil { return err } @@ -302,7 +302,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { ctx context.Context, txn *kv.Txn, descsCol *descs.Collection, f func(finalizer *databaseRegionChangeFinalizer) error, ) error { - typeDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, t.typeID) + typeDesc, err := descsCol.MutableByID(txn).Type(ctx, t.typeID) if err != nil { return err } @@ -345,7 +345,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { // use and fail. This is done in a separate txn to the one that mutates the // descriptor, as this validation can take arbitrarily long. validateDrops := func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - typeDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, t.typeID) + typeDesc, err := descsCol.MutableByID(txn).Type(ctx, t.typeID) if err != nil { return err } @@ -402,7 +402,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { // have performed any necessary pre-drop work, we can actually go about // modifying the type descriptor. run := func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - typeDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, t.typeID) + typeDesc, err := descsCol.MutableByID(txn).Type(ctx, t.typeID) if err != nil { return err } @@ -448,7 +448,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { // The version of the array type needs to get bumped as well so that // changes to the underlying type are picked up. Simply reading the // mutable descriptor and writing it back should do the trick. - arrayTypeDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, typeDesc.ArrayTypeID) + arrayTypeDesc, err := descsCol.MutableByID(txn).Type(ctx, typeDesc.ArrayTypeID) if err != nil { return err } @@ -546,7 +546,7 @@ func (t *typeSchemaChanger) cleanupEnumValues(ctx context.Context) error { var regionChangeFinalizer *databaseRegionChangeFinalizer // Cleanup: cleanup := func(ctx context.Context, txn *kv.Txn, descsCol *descs.Collection) error { - typeDesc, err := descsCol.ByID(txn).Mutable().Type(ctx, t.typeID) + typeDesc, err := descsCol.MutableByID(txn).Type(ctx, t.typeID) if err != nil { return err } @@ -757,7 +757,7 @@ func (t *typeSchemaChanger) canRemoveEnumValue( descsCol *descs.Collection, ) error { for _, ID := range typeDesc.ReferencingDescriptorIDs { - desc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, ID) + desc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Table(ctx, ID) if err != nil { return errors.Wrapf(err, "could not validate enum value removal for %q", member.LogicalRepresentation) @@ -912,7 +912,7 @@ func (t *typeSchemaChanger) canRemoveEnumValue( // be unset by default) when executing the query constructed above. This is // because the enum value may be used in a view expression, which is // name resolved in the context of the type's database. - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, typeDesc.ParentID) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, typeDesc.ParentID) const validationErr = "could not validate removal of enum value %q" if err != nil { return errors.Wrapf(err, validationErr, member.LogicalRepresentation) @@ -950,7 +950,7 @@ func (t *typeSchemaChanger) canRemoveEnumValue( } // Do validation for the array type now. - arrayTypeDesc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Type(ctx, typeDesc.ArrayTypeID) + arrayTypeDesc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Type(ctx, typeDesc.ArrayTypeID) if err != nil { return err } @@ -1084,7 +1084,7 @@ func (t *typeSchemaChanger) canRemoveEnumValueFromArrayUsages( const validationErr = "could not validate removal of enum value %q" for i := 0; i < arrayTypeDesc.NumReferencingDescriptors(); i++ { id := arrayTypeDesc.GetReferencingDescriptorID(i) - desc, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Table(ctx, id) + desc, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Table(ctx, id) if err != nil { return errors.Wrapf(err, validationErr, member.LogicalRepresentation) } @@ -1133,7 +1133,7 @@ func (t *typeSchemaChanger) canRemoveEnumValueFromArrayUsages( } query.WriteString(fmt.Sprintf(") WHERE unnest = %s", sqlPhysRep)) - dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Database(ctx, arrayTypeDesc.GetParentID()) + dbDesc, err := descsCol.ByID(txn).WithoutNonPublic().Get().Database(ctx, arrayTypeDesc.GetParentID()) if err != nil { return errors.Wrapf(err, validationErr, member.LogicalRepresentation) } @@ -1153,7 +1153,7 @@ func (t *typeSchemaChanger) canRemoveEnumValueFromArrayUsages( } if len(rows) > 0 { // Use an FQN in the error message. - parentSchema, err := descsCol.ByID(txn).WithoutNonPublic().Immutable().Schema(ctx, desc.GetParentSchemaID()) + parentSchema, err := descsCol.ByIDWithLeased(txn).WithoutNonPublic().Get().Schema(ctx, desc.GetParentSchemaID()) if err != nil { return err } diff --git a/pkg/sql/user.go b/pkg/sql/user.go index 25d176247298..79082b846eea 100644 --- a/pkg/sql/user.go +++ b/pkg/sql/user.go @@ -769,7 +769,7 @@ func updateUserPasswordHash( // Error, or no update took place. return err } - usersTable, err := d.ByID(txn).Mutable().Table(ctx, keys.UsersTableID) + usersTable, err := d.MutableByID(txn).Table(ctx, keys.UsersTableID) if err != nil { return err } diff --git a/pkg/upgrade/upgrades/fix_userfile_descriptor_corruption.go b/pkg/upgrade/upgrades/fix_userfile_descriptor_corruption.go index d247c69c0d2c..827bda23f3c5 100644 --- a/pkg/upgrade/upgrades/fix_userfile_descriptor_corruption.go +++ b/pkg/upgrade/upgrades/fix_userfile_descriptor_corruption.go @@ -58,7 +58,7 @@ func fixInvalidObjectsThatLookLikeBadUserfileConstraint( errString := string(tree.MustBeDString(row[4])) if veryLikelyKnownUserfileBreakage(ctx, txn, descriptors, tableID, errString) { log.Infof(ctx, "attempting to fix invalid table descriptor %d assuming it is a userfile-related table", tableID) - mutTableDesc, err := descriptors.ByID(txn).Mutable().Table(ctx, tableID) + mutTableDesc, err := descriptors.MutableByID(txn).Table(ctx, tableID) if err != nil { return err } @@ -88,7 +88,7 @@ func veryLikelyKnownUserfileBreakage( return false } - tableDesc, err := descriptors.ByID(txn).Immutable().Table(ctx, id) + tableDesc, err := descriptors.ByIDWithLeased(txn).Get().Table(ctx, id) if err != nil { return false } @@ -130,7 +130,7 @@ func mutationsLookLikeuserfilePayloadCorruption( mutation := tableDesc.AllMutations()[0] if mutation.Adding() && mutation.DeleteOnly() { if fkConstraint := mutation.AsForeignKey(); fkConstraint != nil { - targetTableDesc, err := descriptors.ByID(txn).Immutable().Table(ctx, fkConstraint.GetReferencedTableID()) + targetTableDesc, err := descriptors.ByIDWithLeased(txn).Get().Table(ctx, fkConstraint.GetReferencedTableID()) if err != nil { return false } diff --git a/pkg/upgrade/upgrades/helpers_test.go b/pkg/upgrade/upgrades/helpers_test.go index 2e4d34993743..4e9aecee3164 100644 --- a/pkg/upgrade/upgrades/helpers_test.go +++ b/pkg/upgrade/upgrades/helpers_test.go @@ -78,7 +78,7 @@ func InjectLegacyTable( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) error { id := table.GetID() - tab, err := descriptors.ByID(txn).Mutable().Table(ctx, id) + tab, err := descriptors.MutableByID(txn).Table(ctx, id) if err != nil { return err } @@ -142,7 +142,7 @@ func GetTable( err := s.InternalExecutorFactory().(descs.TxnManager).DescsTxn(ctx, s.DB(), func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - table, err = descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, tableID) + table, err = descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, tableID) return err }) require.NoError(t, err) diff --git a/pkg/upgrade/upgrades/schema_changes.go b/pkg/upgrade/upgrades/schema_changes.go index 9bf4ee3b4c6b..7d5dcd70913f 100644 --- a/pkg/upgrade/upgrades/schema_changes.go +++ b/pkg/upgrade/upgrades/schema_changes.go @@ -144,7 +144,7 @@ func readTableDescriptor( if err := d.InternalExecutorFactory.DescsTxn(ctx, d.DB, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, ) (err error) { - t, err = descriptors.ByID(txn).WithoutNonPublic().WithoutLeased().Immutable().Table(ctx, tableID) + t, err = descriptors.ByID(txn).WithoutNonPublic().Get().Table(ctx, tableID) return err }); err != nil { return nil, err diff --git a/pkg/upgrade/upgrades/update_invalid_column_ids_in_sequence_back_references.go b/pkg/upgrade/upgrades/update_invalid_column_ids_in_sequence_back_references.go index 3b591cb13d93..dcbdb8098988 100644 --- a/pkg/upgrade/upgrades/update_invalid_column_ids_in_sequence_back_references.go +++ b/pkg/upgrade/upgrades/update_invalid_column_ids_in_sequence_back_references.go @@ -94,7 +94,7 @@ func maybeUpdateInvalidColumnIdsInSequenceBackReferences( ctx context.Context, txn *kv.Txn, idToUpgrade descpb.ID, descriptors *descs.Collection, ) (hasUpgraded bool, err error) { // Get the sequence descriptor that we are going to upgrade. - seqDesc, err := descriptors.ByID(txn).Mutable().Table(ctx, idToUpgrade) + seqDesc, err := descriptors.MutableByID(txn).Table(ctx, idToUpgrade) if err != nil { return false, err } @@ -107,7 +107,7 @@ func maybeUpdateInvalidColumnIdsInSequenceBackReferences( // `ref.ColumnIDs` if the actual value is not equal to the // expected value. expectedColumnIDsInRef := make([]descpb.ColumnID, 0) - tableDesc, err := descriptors.ByID(txn).Mutable().Table(ctx, ref.ID) + tableDesc, err := descriptors.MutableByID(txn).Table(ctx, ref.ID) if err != nil { return false, err } diff --git a/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go b/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go index 07dec3df1098..0e42c5a79295 100644 --- a/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go +++ b/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go @@ -148,13 +148,13 @@ func upgradeSetUpForTableOrView( idToUpgrade descpb.ID, ) (*tabledesc.Mutable, resolver.SchemaResolver, func(), error) { // Get the table descriptor that we are going to upgrade. - tableDesc, err := descriptors.ByID(txn).Mutable().Table(ctx, idToUpgrade) + tableDesc, err := descriptors.MutableByID(txn).Table(ctx, idToUpgrade) if err != nil { return nil, nil, nil, err } // Get the database of the table to pass to the planner constructor. - dbDesc, err := descriptors.ByID(txn).WithoutNonPublic().Immutable().Database(ctx, tableDesc.GetParentID()) + dbDesc, err := descriptors.ByIDWithLeased(txn).WithoutNonPublic().Get().Database(ctx, tableDesc.GetParentID()) if err != nil { return nil, nil, nil, err }