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

package catalogkv

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

Package catalogkv provides functions for interacting with the system catalog tables using the kv client.

Index

Package Files

catalogkv.go descriptorkind_string.go namespace.go physical_accessor.go test_utils.go

func ConditionalGetTableDescFromTxn Uses

func ConditionalGetTableDescFromTxn(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, expectation sqlbase.TableDescriptor,
) ([]byte, error)

ConditionalGetTableDescFromTxn validates that the supplied TableDescriptor matches the one currently stored in kv. This simulates a CPut and returns a ConditionFailedError on mismatch. We don't directly use CPut with protos because the marshaling is not guaranteed to be stable and also because it's sensitive to things like missing vs default values of fields.

func CountUserDescriptors Uses

func CountUserDescriptors(ctx context.Context, txn *kv.Txn, codec keys.SQLCodec) (int, error)

CountUserDescriptors returns the number of descriptors present that were created by the user (i.e. not present when the cluster started).

func GenerateUniqueDescID Uses

func GenerateUniqueDescID(ctx context.Context, db *kv.DB, codec keys.SQLCodec) (descpb.ID, error)

GenerateUniqueDescID returns the next available Descriptor ID and increments the counter. The incrementing is non-transactional, and the counter could be incremented multiple times because of retries.

func GetAllDatabaseDescriptorIDs Uses

func GetAllDatabaseDescriptorIDs(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec,
) ([]descpb.ID, error)

GetAllDatabaseDescriptorIDs looks up and returns all available database descriptor IDs.

func GetAllDescriptors Uses

func GetAllDescriptors(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec,
) ([]sqlbase.Descriptor, error)

GetAllDescriptors looks up and returns all available descriptors.

func GetAnyDescriptorByID Uses

func GetAnyDescriptorByID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID, mutable Mutability,
) (catalog.Descriptor, error)

GetAnyDescriptorByID is a wrapper around GetDescriptorByID which permits missing descriptors and does not restrict the requested kind.

func GetDatabaseDescByID Uses

func GetDatabaseDescByID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID,
) (*sqlbase.ImmutableDatabaseDescriptor, error)

GetDatabaseDescByID looks up the database descriptor given its ID, returning nil if the descriptor is not found. If you want the "not found" condition to return an error, use mustGetDatabaseDescByID() instead.

func GetDatabaseDescriptorsFromIDs Uses

func GetDatabaseDescriptorsFromIDs(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, ids []descpb.ID,
) ([]*sqlbase.ImmutableDatabaseDescriptor, error)

GetDatabaseDescriptorsFromIDs returns the database descriptors from an input set of database IDs. It will return an error if any one of the IDs is not a database. It attempts to perform this operation in a single request, rather than making a round trip for each ID.

func GetDatabaseID Uses

func GetDatabaseID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, name string, required bool,
) (descpb.ID, error)

GetDatabaseID resolves a database name into a database ID. Returns InvalidID on failure.

func GetDescriptorByID Uses

func GetDescriptorByID(
    ctx context.Context,
    txn *kv.Txn,
    codec keys.SQLCodec,
    id descpb.ID,
    mutable Mutability,
    kind DescriptorKind,
    required bool,
) (catalog.Descriptor, error)

GetDescriptorByID looks up the descriptor for `id`. The descriptor will be validated if the requested descriptor is Immutable.

TODO(ajwerner): Fix this odd behavior with validation which is used to hack around the fact that mutable descriptors are sometimes looked up while they are being mutated and in that period may be invalid with respect to the state of other descriptors in the database. Instead we ought to inject a higher level interface than a `txn` here for looking up other descriptors during validation. Ideally we'd have a handle to the transaction's descs.Collection and we'd maintain that when writing or retrieving descriptors which have been mutated we wouldn't reach back into the kv store.

func GetDescriptorID Uses

func GetDescriptorID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, plainKey sqlbase.DescriptorKey,
) (descpb.ID, error)

GetDescriptorID looks up the ID for plainKey. InvalidID is returned if the name cannot be resolved.

func LookupDatabaseID Uses

func LookupDatabaseID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, name string,
) (bool, descpb.ID, error)

LookupDatabaseID is a wrapper around LookupObjectID for databases.

func LookupObjectID Uses

func LookupObjectID(
    ctx context.Context,
    txn *kv.Txn,
    codec keys.SQLCodec,
    parentID descpb.ID,
    parentSchemaID descpb.ID,
    name string,
) (bool, descpb.ID, error)

LookupObjectID returns the ObjectID for the given (parentID, parentSchemaID, name) supplied. If cluster version < 20.1, the parentSchemaID is ignored.

func LookupPublicTableID Uses

func LookupPublicTableID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, parentID descpb.ID, name string,
) (bool, descpb.ID, error)

LookupPublicTableID is a wrapper around LookupObjectID for public tables.

func MakeDatabaseNameKey Uses

func MakeDatabaseNameKey(
    ctx context.Context, settings *cluster.Settings, name string,
) sqlbase.DescriptorKey

MakeDatabaseNameKey is a wrapper around MakeObjectNameKey for databases.

func MakeObjectNameKey Uses

func MakeObjectNameKey(
    ctx context.Context,
    settings *cluster.Settings,
    parentID descpb.ID,
    parentSchemaID descpb.ID,
    name string,
) sqlbase.DescriptorKey

MakeObjectNameKey returns a key in the system.namespace table for a given parentID and name, based on the cluster version. - If cluster version >= 20.1, the key is in the new system.namespace table. - If cluster version < 20.1, the key is in the deprecated system.namespace table. - The parentSchemaID field is ignored in < 20.1 clusters.

func MakePublicTableNameKey Uses

func MakePublicTableNameKey(
    ctx context.Context, settings *cluster.Settings, parentID descpb.ID, name string,
) sqlbase.DescriptorKey

MakePublicTableNameKey is a wrapper around MakeObjectNameKey for public tables.

func MustGetDatabaseDescByID Uses

func MustGetDatabaseDescByID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID,
) (*sqlbase.ImmutableDatabaseDescriptor, error)

MustGetDatabaseDescByID looks up the database descriptor given its ID, returning an error if the descriptor is not found.

func MustGetTableDescByID Uses

func MustGetTableDescByID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID,
) (*sqlbase.ImmutableTableDescriptor, error)

MustGetTableDescByID looks up the table descriptor given its ID, returning an error if the table is not found.

func RemoveDatabaseNamespaceEntry Uses

func RemoveDatabaseNamespaceEntry(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, name string, KVTrace bool,
) error

RemoveDatabaseNamespaceEntry is a wrapper around RemoveObjectNamespaceEntry for databases.

func RemoveObjectNamespaceEntry Uses

func RemoveObjectNamespaceEntry(
    ctx context.Context,
    txn *kv.Txn,
    codec keys.SQLCodec,
    parentID descpb.ID,
    parentSchemaID descpb.ID,
    name string,
    KVTrace bool,
) error

RemoveObjectNamespaceEntry removes entries from both the deprecated and new system.namespace table (if one exists).

func RemovePublicTableNamespaceEntry Uses

func RemovePublicTableNamespaceEntry(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, parentID descpb.ID, name string,
) error

RemovePublicTableNamespaceEntry is a wrapper around RemoveObjectNamespaceEntry for public tables.

func RemoveSchemaNamespaceEntry Uses

func RemoveSchemaNamespaceEntry(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, parentID descpb.ID, name string,
) error

RemoveSchemaNamespaceEntry is a wrapper around RemoveObjectNamespaceEntry for schemas.

func ResolveSchemaID Uses

func ResolveSchemaID(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, dbID descpb.ID, scName string,
) (bool, descpb.ID, error)

ResolveSchemaID resolves a schema's ID based on db and name.

func TestingGetImmutableTableDescriptor Uses

func TestingGetImmutableTableDescriptor(
    kvDB *kv.DB, codec keys.SQLCodec, database string, table string,
) *sqlbase.ImmutableTableDescriptor

TestingGetImmutableTableDescriptor retrieves an immutable table descriptor directly from the KV layer.

func TestingGetMutableExistingTableDescriptor Uses

func TestingGetMutableExistingTableDescriptor(
    kvDB *kv.DB, codec keys.SQLCodec, database string, table string,
) *sqlbase.MutableTableDescriptor

TestingGetMutableExistingTableDescriptor retrieves a MutableTableDescriptor directly from the KV layer.

func TestingGetTableDescriptor Uses

func TestingGetTableDescriptor(
    kvDB *kv.DB, codec keys.SQLCodec, database string, table string,
) *sqlbase.ImmutableTableDescriptor

TestingGetTableDescriptor retrieves a table descriptor directly from the KV layer.

TODO(ajwerner): Move this to catalogkv and/or question the very existence of this function. Consider renaming to TestingGetTableDescriptorByName or removing it altogether.

func TestingGetTypeDescriptor Uses

func TestingGetTypeDescriptor(
    kvDB *kv.DB, codec keys.SQLCodec, database string, object string,
) *sqlbase.ImmutableTypeDescriptor

TestingGetTypeDescriptor retrieves a type descriptor directly from the kv layer.

This function should be moved wherever TestingGetTableDescriptor is moved.

func WriteDescToBatch Uses

func WriteDescToBatch(
    ctx context.Context,
    kvTrace bool,
    s *cluster.Settings,
    b *kv.Batch,
    codec keys.SQLCodec,
    descID descpb.ID,
    desc sqlbase.Descriptor,
) (err error)

WriteDescToBatch adds a Put command writing a descriptor proto to the descriptors table. It writes the descriptor desc at the id descID. If kvTrace is enabled, it will log an event explaining the put that was performed.

func WriteNewDescToBatch Uses

func WriteNewDescToBatch(
    ctx context.Context,
    kvTrace bool,
    s *cluster.Settings,
    b *kv.Batch,
    codec keys.SQLCodec,
    tableID descpb.ID,
    desc sqlbase.Descriptor,
) (err error)

WriteNewDescToBatch adds a CPut command writing a descriptor proto to the descriptors table. It writes the descriptor desc at the id descID, asserting that there was no previous descriptor at that id present already. If kvTrace is enabled, it will log an event explaining the CPut that was performed.

type DescriptorKind Uses

type DescriptorKind int

DescriptorKind is used to indicate the desired kind of descriptor from GetDescriptorByID.

const (
    DatabaseDescriptorKind DescriptorKind = iota
    SchemaDescriptorKind
    TableDescriptorKind
    TypeDescriptorKind
    AnyDescriptorKind // permit any kind
)

List of DescriptorKind values.

func (DescriptorKind) String Uses

func (i DescriptorKind) String() string

type Mutability Uses

type Mutability bool

Mutability indicates whether the desired descriptor is mutable. This type aids readability.

const (
    Immutable Mutability = false
    Mutable   Mutability = true
)

Mutability values.

type UncachedPhysicalAccessor Uses

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

UncachedPhysicalAccessor implements direct access to sql object descriptors stored in system tables without any kind of caching.

func (UncachedPhysicalAccessor) GetDatabaseDesc Uses

func (a UncachedPhysicalAccessor) GetDatabaseDesc(
    ctx context.Context,
    txn *kv.Txn,
    codec keys.SQLCodec,
    name string,
    flags tree.DatabaseLookupFlags,
) (desc sqlbase.DatabaseDescriptor, err error)

GetDatabaseDesc implements the Accessor interface.

func (UncachedPhysicalAccessor) GetObjectDesc Uses

func (a UncachedPhysicalAccessor) GetObjectDesc(
    ctx context.Context,
    txn *kv.Txn,
    settings *cluster.Settings,
    codec keys.SQLCodec,
    db, scName, object string,
    flags tree.ObjectLookupFlags,
) (catalog.Descriptor, error)

GetObjectDesc implements the Accessor interface.

func (UncachedPhysicalAccessor) GetObjectNames Uses

func (a UncachedPhysicalAccessor) GetObjectNames(
    ctx context.Context,
    txn *kv.Txn,
    codec keys.SQLCodec,
    dbDesc sqlbase.DatabaseDescriptor,
    scName string,
    flags tree.DatabaseListFlags,
) (tree.TableNames, error)

GetObjectNames implements the Accessor interface.

func (UncachedPhysicalAccessor) GetSchema Uses

func (a UncachedPhysicalAccessor) GetSchema(
    ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, dbID descpb.ID, scName string,
) (bool, sqlbase.ResolvedSchema, error)

GetSchema implements the Accessor interface.

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