cockroach: github.com/cockroachdb/cockroach/pkg/sql/catalog/descs Index | Files

package descs

import "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"

Package descs provides abstractions for dealing with sets of descriptors. It is utilized during schema changes and by catalog.Accessor implementations.

Index

Package Files

collection.go

Variables

var ErrSchemaChangeDisallowedInMixedState = errors.New("schema change cannot be initiated in this version until the version upgrade is finalized")

ErrSchemaChangeDisallowedInMixedState signifies that an attempted schema change was disallowed from running in a mixed-version

func MigrationSchemaChangeRequiredContext Uses

func MigrationSchemaChangeRequiredContext(ctx context.Context) context.Context

MigrationSchemaChangeRequiredContext flags a schema change as necessary to run even in a mixed-version 19.2/20.1 state where schema changes are normally banned, because the schema change is being run in a startup migration. It's the caller's responsibility to ensure that the schema change job is safe to run in a mixed-version state.

TODO (lucy): Remove this in 20.2.

func MigrationSchemaChangeRequiredFromContext Uses

func MigrationSchemaChangeRequiredFromContext(ctx context.Context) bool

MigrationSchemaChangeRequiredFromContext returns true if the context indicates that a schema change should be run despite a mixed 19.2/20.1 cluster version.

type Collection Uses

type Collection struct {
    // contains filtered or unexported fields
}

Collection is a collection of descriptors held by a single session that serves SQL requests, or a background job using descriptors. The collection is cleared using ReleaseAll() which is called at the end of each transaction on the session, or on hitting conditions such as errors, or retries that result in transaction timestamp changes.

func MakeCollection Uses

func MakeCollection(
    leaseMgr *lease.Manager,
    settings *cluster.Settings,
    dbCache *database.Cache,
    dbCacheSubscriber DatabaseCacheSubscriber,
) Collection

MakeCollection constructs a Collection.

func NewCollection Uses

func NewCollection(leaseMgr *lease.Manager, settings *cluster.Settings) *Collection

NewCollection constructs a new *Collection.

func (*Collection) AddUncommittedDatabase Uses

func (tc *Collection) AddUncommittedDatabase(name string, id descpb.ID, action DBAction)

AddUncommittedDatabase stages the database action for the relevant database.

func (*Collection) AddUncommittedDescriptor Uses

func (tc *Collection) AddUncommittedDescriptor(desc catalog.MutableDescriptor) error

AddUncommittedDescriptor adds an uncommitted descriptor modified in the transaction to the Collection.

func (*Collection) CopyModifiedObjects Uses

func (tc *Collection) CopyModifiedObjects(to *Collection)

CopyModifiedObjects copies the modified schema to the table collection. Used when initializing an InternalExecutor.

func (*Collection) DatabaseCache Uses

func (tc *Collection) DatabaseCache() *database.Cache

DatabaseCache returns the database.Cache.

func (*Collection) GetAllDatabaseDescriptors Uses

func (tc *Collection) GetAllDatabaseDescriptors(
    ctx context.Context, txn *kv.Txn,
) ([]*sqlbase.ImmutableDatabaseDescriptor, error)

GetAllDatabaseDescriptors returns all database descriptors visible by the transaction, first checking the Collection's cached descriptors for validity before scanning system.namespace and looking up the descriptors in the database cache, if necessary.

func (*Collection) GetAllDescriptors Uses

func (tc *Collection) GetAllDescriptors(
    ctx context.Context, txn *kv.Txn,
) ([]sqlbase.Descriptor, error)

GetAllDescriptors returns all descriptors visible by the transaction, first checking the Collection's cached descriptors for validity before defaulting to a key-value scan, if necessary.

func (*Collection) GetDescriptorsWithNewVersion Uses

func (tc *Collection) GetDescriptorsWithNewVersion() []lease.IDVersion

GetDescriptorsWithNewVersion returns all the IDVersion pairs that have undergone a schema change. Returns nil for no schema changes. The version returned for each schema change is ClusterVersion - 1, because that's the one that will be used when checking for table descriptor two version invariance.

func (*Collection) GetMutableTableDescriptor Uses

func (tc *Collection) GetMutableTableDescriptor(
    ctx context.Context, txn *kv.Txn, tn *tree.TableName, flags tree.ObjectLookupFlags,
) (*sqlbase.MutableTableDescriptor, error)

GetMutableTableDescriptor returns a mutable table descriptor.

If flags.required is false, GetMutableTableDescriptor() will gracefully return a nil descriptor and no error if the table does not exist.

func (*Collection) GetMutableTableVersionByID Uses

func (tc *Collection) GetMutableTableVersionByID(
    ctx context.Context, tableID descpb.ID, txn *kv.Txn,
) (*sqlbase.MutableTableDescriptor, error)

GetMutableTableVersionByID is a variant of sqlbase.getTableDescFromID which returns a mutable table descriptor of the table modified in the same transaction.

func (*Collection) GetMutableTypeDescriptor Uses

func (tc *Collection) GetMutableTypeDescriptor(
    ctx context.Context, txn *kv.Txn, tn *tree.TypeName, flags tree.ObjectLookupFlags,
) (*sqlbase.MutableTypeDescriptor, error)

GetMutableTypeDescriptor is the equivalent of GetMutableTableDescriptor but for accessing types.

func (*Collection) GetMutableTypeVersionByID Uses

func (tc *Collection) GetMutableTypeVersionByID(
    ctx context.Context, txn *kv.Txn, typeID descpb.ID,
) (*sqlbase.MutableTypeDescriptor, error)

GetMutableTypeVersionByID is the equivalent of GetMutableTableDescriptorByID but for accessing types.

func (*Collection) GetSchemasForDatabase Uses

func (tc *Collection) GetSchemasForDatabase(
    ctx context.Context, txn *kv.Txn, dbID descpb.ID,
) (map[descpb.ID]string, error)

GetSchemasForDatabase returns the schemas for a given database visible by the transaction. This uses the schema cache locally if possible, or else performs a scan on kv.

func (*Collection) GetTableVersion Uses

func (tc *Collection) GetTableVersion(
    ctx context.Context, txn *kv.Txn, tn *tree.TableName, flags tree.ObjectLookupFlags,
) (*sqlbase.ImmutableTableDescriptor, error)

GetTableVersion returns a table descriptor with a version suitable for the transaction: table.ModificationTime <= txn.Timestamp < expirationTime. The table must be released by calling tc.ReleaseAll().

If flags.required is false, GetTableVersion() will gracefully return a nil descriptor and no error if the table does not exist.

It might also add a transaction deadline to the transaction that is enforced at the KV layer to ensure that the transaction doesn't violate the validity window of the table descriptor version returned.

func (*Collection) GetTableVersionByID Uses

func (tc *Collection) GetTableVersionByID(
    ctx context.Context, txn *kv.Txn, tableID descpb.ID, flags tree.ObjectLookupFlags,
) (*sqlbase.ImmutableTableDescriptor, error)

GetTableVersionByID is a by-ID variant of GetTableVersion (i.e. uses same cache).

func (*Collection) GetTypeVersion Uses

func (tc *Collection) GetTypeVersion(
    ctx context.Context, txn *kv.Txn, tn *tree.TypeName, flags tree.ObjectLookupFlags,
) (*sqlbase.ImmutableTypeDescriptor, error)

GetTypeVersion is the equivalent of GetTableVersion but for accessing types.

func (*Collection) GetTypeVersionByID Uses

func (tc *Collection) GetTypeVersionByID(
    ctx context.Context, txn *kv.Txn, typeID descpb.ID, flags tree.ObjectLookupFlags,
) (*sqlbase.ImmutableTypeDescriptor, error)

GetTypeVersionByID is the equivalent of GetTableVersionByID but for accessing types.

func (*Collection) GetUncommittedDatabaseID Uses

func (tc *Collection) GetUncommittedDatabaseID(
    requestedDbName string, required bool,
) (c bool, res descpb.ID, err error)

GetUncommittedDatabaseID returns a database ID for the requested tablename if the requested tablename is for a database modified within the transaction affiliated with the LeaseCollection.

func (*Collection) GetUncommittedTableByID Uses

func (tc *Collection) GetUncommittedTableByID(id descpb.ID) *sqlbase.MutableTableDescriptor

GetUncommittedTableByID returns an uncommitted table by its ID.

func (*Collection) GetUncommittedTables Uses

func (tc *Collection) GetUncommittedTables() (tables []*sqlbase.ImmutableTableDescriptor)

GetUncommittedTables returns all the tables updated or created in the transaction.

func (*Collection) HasUncommittedTables Uses

func (tc *Collection) HasUncommittedTables() bool

HasUncommittedTables returns true if the Collection contains uncommitted tables.

func (*Collection) HasUncommittedTypes Uses

func (tc *Collection) HasUncommittedTypes() bool

HasUncommittedTypes returns true if the Collection contains uncommitted types.

func (*Collection) LeaseManager Uses

func (tc *Collection) LeaseManager() *lease.Manager

LeaseManager returns the lease.Manager.

func (*Collection) ReleaseAll Uses

func (tc *Collection) ReleaseAll(ctx context.Context)

ReleaseAll releases all state currently held by the Collection. ReleaseAll calls ReleaseLeases.

func (*Collection) ReleaseLeases Uses

func (tc *Collection) ReleaseLeases(ctx context.Context)

ReleaseLeases releases all leases. Errors are logged but ignored.

func (*Collection) ReleaseSpecifiedLeases Uses

func (tc *Collection) ReleaseSpecifiedLeases(ctx context.Context, descs []lease.IDVersion)

ReleaseSpecifiedLeases releases the leases for the descriptors with ids in the passed slice. Errors are logged but ignored.

func (*Collection) ResetDatabaseCache Uses

func (tc *Collection) ResetDatabaseCache(dbCache *database.Cache)

ResetDatabaseCache resets the table collection's database.Cache.

func (*Collection) ResolveSchema Uses

func (tc *Collection) ResolveSchema(
    ctx context.Context, txn *kv.Txn, dbID descpb.ID, schemaName string,
) (bool, sqlbase.ResolvedSchema, error)

ResolveSchema attempts to lookup the schema from the schemaCache if it exists, otherwise falling back to a database lookup.

func (*Collection) WaitForCacheToDropDatabases Uses

func (tc *Collection) WaitForCacheToDropDatabases(ctx context.Context)

WaitForCacheToDropDatabases waits until the database cache has been updated to properly reflect all dropped databases, so that future commands on the same gateway node observe the dropped databases.

type DBAction Uses

type DBAction bool

DBAction is an operation to an uncommitted database.

const (
    // DBCreated notes that the database has been created.
    DBCreated DBAction = false
    // DBDropped notes that the database has been dropped.
    DBDropped DBAction = true
)

type DatabaseCacheSubscriber Uses

type DatabaseCacheSubscriber interface {
    // WaitForCacheState takes a callback depending on the cache state and blocks
    // until the callback declares success. The callback is repeatedly called as
    // the cache is updated.
    WaitForCacheState(cond func(*database.Cache) bool)
}

DatabaseCacheSubscriber allows the connExecutor to wait for a callback.

type DistSQLTypeResolver Uses

type DistSQLTypeResolver struct {
    // contains filtered or unexported fields
}

DistSQLTypeResolver is a TypeResolver that accesses TypeDescriptors through a given descs.Collection and transaction.

func NewDistSQLTypeResolver Uses

func NewDistSQLTypeResolver(descs *Collection, txn *kv.Txn) *DistSQLTypeResolver

NewDistSQLTypeResolver creates a new DistSQLTypeResolver.

func (*DistSQLTypeResolver) GetTypeDescriptor Uses

func (dt *DistSQLTypeResolver) GetTypeDescriptor(
    ctx context.Context, id descpb.ID,
) (tree.TypeName, sqlbase.TypeDescriptor, error)

GetTypeDescriptor implements the sqlbase.TypeDescriptorResolver interface.

func (*DistSQLTypeResolver) HydrateTypeSlice Uses

func (dt *DistSQLTypeResolver) HydrateTypeSlice(ctx context.Context, typs []*types.T) error

HydrateTypeSlice installs metadata into a slice of types.T's.

func (*DistSQLTypeResolver) ResolveType Uses

func (dt *DistSQLTypeResolver) ResolveType(
    context.Context, *tree.UnresolvedObjectName,
) (*types.T, error)

ResolveType implements the tree.TypeReferenceResolver interface.

func (*DistSQLTypeResolver) ResolveTypeByOID Uses

func (dt *DistSQLTypeResolver) ResolveTypeByOID(
    ctx context.Context, oid oid.Oid,
) (*types.T, error)

ResolveTypeByOID implements the tree.TypeReferenceResolver interface.

type DistSQLTypeResolverFactory Uses

type DistSQLTypeResolverFactory struct {
    Descriptors *Collection
    CleanupFunc func(ctx context.Context)
}

DistSQLTypeResolverFactory is an object that constructs TypeResolver objects that are bound under a transaction. These TypeResolvers access descriptors through the descs.Collection and eventually the lease.Manager. It cannot be used concurrently, and neither can the constructed TypeResolvers. After the DistSQLTypeResolverFactory is finished being used, all descriptors need to be released from Descriptors. It is intended to be used to resolve type references during the initialization of DistSQL flows.

func (*DistSQLTypeResolverFactory) NewSemaContext Uses

func (df *DistSQLTypeResolverFactory) NewSemaContext(txn *kv.Txn) *tree.SemaContext

NewSemaContext creates a new SemaContext with a TypeResolver bound to the input transaction.

func (*DistSQLTypeResolverFactory) NewTypeResolver Uses

func (df *DistSQLTypeResolverFactory) NewTypeResolver(txn *kv.Txn) *DistSQLTypeResolver

NewTypeResolver creates a new TypeResolver that is bound under the input transaction. It returns a nil resolver if the factory itself is nil.

type ModifiedCollectionCopier Uses

type ModifiedCollectionCopier interface {
    CopyModifiedObjects(to *Collection)
}

ModifiedCollectionCopier is an interface used to copy modified schema elements to a new Collection.

type UncommittedDatabase Uses

type UncommittedDatabase struct {
    // contains filtered or unexported fields
}

UncommittedDatabase is a database that has been created/dropped within the current transaction using the Collection. A rename is a drop of the old name and creation of the new name.

Package descs imports 21 packages (graph) and is imported by 6 packages. Updated 2020-08-12. Refresh now. Tools for package owners.