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

package database

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

Package database primarily provides the incoherent database cache and related interfaces.

TODO(ajwerner): Lease database descriptors like all other schema objects and eliminate this package.

Index

Package Files

database.go

type Cache Uses

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

Cache holds a cache from database name to database ID. It is populated as database IDs are requested and a new cache is created whenever the system config changes. As such, no attempt is made to limit its size which is naturally limited by the number of database descriptors in the system the periodic reset whenever the system config is gossiped.

func NewCache Uses

func NewCache(codec keys.SQLCodec, cfg *config.SystemConfig) *Cache

NewCache constructs a new Cache.

func (*Cache) Codec Uses

func (dc *Cache) Codec() keys.SQLCodec

Codec returns the cache's codec.

func (*Cache) GetCachedDatabaseID Uses

func (dc *Cache) GetCachedDatabaseID(name string) (descpb.ID, error)

GetCachedDatabaseID returns the ID of a database given its name from the cache. This method never goes to the store to resolve the name to id mapping. Returns InvalidID if the name to id mapping or the database descriptor are not in the cache.

func (*Cache) GetDatabaseDesc Uses

func (dc *Cache) GetDatabaseDesc(
    ctx context.Context,
    txnRunner func(context.Context, func(context.Context, *kv.Txn) error) error,
    name string,
    required bool,
) (*sqlbase.ImmutableDatabaseDescriptor, error)

GetDatabaseDesc returns the database descriptor given its name if it exists in the cache, otherwise falls back to KV operations.

func (*Cache) GetDatabaseDescByID Uses

func (dc *Cache) GetDatabaseDescByID(
    ctx context.Context, txn *kv.Txn, id descpb.ID,
) (*sqlbase.ImmutableDatabaseDescriptor, error)

GetDatabaseDescByID returns the database descriptor given its ID if it exists in the cache, otherwise falls back to KV operations.

func (*Cache) GetDatabaseID Uses

func (dc *Cache) GetDatabaseID(
    ctx context.Context,
    txnRunner func(context.Context, func(context.Context, *kv.Txn) error) error,
    name string,
    required bool,
) (descpb.ID, error)

GetDatabaseID returns the ID of a database given its name. It uses the descriptor cache if possible, otherwise falls back to KV operations.

Package database imports 13 packages (graph) and is imported by 2 packages. Updated 2020-08-12. Refresh now. Tools for package owners.