metadata

package
v1.0.0-alpha.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultNamespaceName is for "default" namespace in the cluster which means all the databases created are under a single
	// namespace.
	// It is totally fine for a deployment to choose this and just have one namespace. The default assigned value for
	// this namespace is 1.
	DefaultNamespaceName string = "default_namespace"

	DefaultNamespaceId = uint32(1)
)

Variables

View Source
var (
	// VersionKey is the metadata version key whose value is returned to the clients in the transaction
	VersionKey = []byte{0xff, '/', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', 'V', 'e', 'r', 's', 'i', 'o', 'n'}
	// VersionValue is the value set when calling setVersionstampedValue, any value other than this is rejected.
	VersionValue = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
)

Functions

func IsSchemaEq

func IsSchemaEq(s1, s2 []byte) (bool, error)

func NewCollectionHolder

func NewCollectionHolder(id uint32, name string, collection *schema.DefaultCollection, idxNameToId map[string]uint32) *collectionHolder

Types

type Database

type Database struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Database is to manage the collections for this database. Check the Clone method before changing this struct.

func NewDatabase

func NewDatabase(id uint32, name string) *Database

func (*Database) Clone

func (d *Database) Clone() *Database

Clone is used to stage the database

func (*Database) GetCollection

func (d *Database) GetCollection(cname string) *schema.DefaultCollection

GetCollection returns the collection object, or null if the collection map contains no mapping for the database. At this point collection is fully formed and safe to use.

func (*Database) Id

func (d *Database) Id() uint32

Id returns the dictionary encoded value of this collection.

func (*Database) ListCollection

func (d *Database) ListCollection() []*schema.DefaultCollection

ListCollection returns the collection object of all the collections in this database.

func (*Database) Name

func (d *Database) Name() string

Name returns the database name.

type DefaultNamespace

type DefaultNamespace struct{}

DefaultNamespace is for "default" namespace in the cluster. This is useful when there is no need to logically group databases. All databases will be created under a single namespace. It is totally fine for a deployment to choose this and just have one namespace. The default assigned value for this namespace is 1.

func NewDefaultNamespace

func NewDefaultNamespace() *DefaultNamespace

func (*DefaultNamespace) Id

func (n *DefaultNamespace) Id() uint32

Id returns id assigned to the namespace

func (*DefaultNamespace) Name

func (n *DefaultNamespace) Name() string

type DictKeyEncoder

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

func (*DictKeyEncoder) DecodeIndexName

func (d *DictKeyEncoder) DecodeIndexName(indexName []byte) uint32

func (*DictKeyEncoder) DecodeTableName

func (d *DictKeyEncoder) DecodeTableName(tableName []byte) (string, string, string, bool)

func (*DictKeyEncoder) EncodeIndexName

func (d *DictKeyEncoder) EncodeIndexName(idx *schema.Index) []byte

func (*DictKeyEncoder) EncodeKey

func (d *DictKeyEncoder) EncodeKey(encodedTable []byte, idx *schema.Index, idxParts []interface{}) (keys.Key, error)

func (*DictKeyEncoder) EncodeTableName

func (d *DictKeyEncoder) EncodeTableName(ns Namespace, db *Database, coll *schema.DefaultCollection) ([]byte, error)

type Encoder

type Encoder interface {
	// EncodeTableName returns encoded bytes which are formed by combining namespace, database, and collection.
	EncodeTableName(ns Namespace, db *Database, coll *schema.DefaultCollection) ([]byte, error)
	// EncodeIndexName returns encoded bytes for the index name
	EncodeIndexName(idx *schema.Index) []byte
	// EncodeKey returns encoded bytes of the key which will be used to store the values in fdb. The Key return by this
	// method has two parts,
	//   - tableName: This is set with an encoding of namespace, database and collection id.
	//   - IndexParts: This has the index identifier and value(s) associated with a single or composite index. This is appended
	//	   to the table name to form the Key. The first element of this list is the dictionary encoding of index type key
	//	   information i.e. whether the index is pkey, etc. The remaining elements are values for this index.
	EncodeKey(encodedTable []byte, idx *schema.Index, idxParts []interface{}) (keys.Key, error)

	// DecodeTableName is used to decode the key stored in FDB and extract namespace name, database name and collection name.
	DecodeTableName(tableName []byte) (string, string, string, bool)
	DecodeIndexName(indexName []byte) uint32
}

Encoder is used to encode/decode values of the Key.

func NewEncoder

func NewEncoder(mgr *TenantManager) Encoder

NewEncoder creates Dictionary encoder to encode keys.

type Namespace

type Namespace interface {
	// Id for the namespace is used by the cluster to append as the first element in the key.
	Id() uint32
	// Name is the name used for the lookup.
	Name() string
}

A Namespace is a logical grouping of databases.

type NamespaceType

type NamespaceType string

type Tenant

type Tenant struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Tenant is a logical grouping of databases. The tenant is used to manage all the databases that belongs to this tenant and the corresponding collections for these databases. Operations performed on the tenant object are thread-safe.

func NewTenant

func NewTenant(namespace Namespace, encoder *encoding.DictionaryEncoder, schemaStore *encoding.SchemaSubspace, versionH *VersionHandler, currentVersion Version) *Tenant

func (*Tenant) CreateCollection

func (tenant *Tenant) CreateCollection(ctx context.Context, tx transaction.Tx, database *Database, schFactory *schema.Factory) error

CreateCollection is to create a collection inside tenant namespace.

func (*Tenant) CreateDatabase

func (tenant *Tenant) CreateDatabase(ctx context.Context, tx transaction.Tx, dbName string) (bool, error)

CreateDatabase is responsible for creating a dictionary encoding of the database. This method is not adding the entry to the tenant because the outer layer may still rollback the transaction. The query lifecycle is also bumping the metadata version so reloading happens at the next call when the tenant version is stale. This applies to the reloading mechanism on all the tigris workers. Returns "true" If the database already exists, else "false" and the error

func (*Tenant) DropCollection

func (tenant *Tenant) DropCollection(ctx context.Context, tx transaction.Tx, db *Database, collectionName string) error

DropCollection is to drop a collection and its associated indexes. It removes the "created" entry from the encoding subspace and adds a "dropped" entry for the same collection key.

func (*Tenant) DropDatabase

func (tenant *Tenant) DropDatabase(ctx context.Context, tx transaction.Tx, dbName string) (bool, error)

DropDatabase is responsible for first dropping a dictionary encoding of the database and then adding a corresponding dropped encoding in the table. Drop returns "false" if database doesn't exist so that caller can reason about.

func (*Tenant) GetDatabase

func (tenant *Tenant) GetDatabase(ctx context.Context, tx transaction.Tx, dbName string) (*Database, error)

GetDatabase returns the database object, or null if there is no database exist with the name passed in the param. This API is also responsible for reloading the tenant knowledge of the databases to ensure caller sees a consistent view of all the schemas. This is achieved by first checking the meta version and if it is changed then call reload.

func (*Tenant) GetNamespace

func (tenant *Tenant) GetNamespace() Namespace

func (*Tenant) InvalidateDBCache

func (tenant *Tenant) InvalidateDBCache(dbName string)

func (*Tenant) ListDatabases

func (tenant *Tenant) ListDatabases(_ context.Context, _ transaction.Tx) []string

func (*Tenant) ReloadUsingOutsideVersion

func (tenant *Tenant) ReloadUsingOutsideVersion(ctx context.Context, tx transaction.Tx, version Version, id string) error

func (*Tenant) ReloadUsingTxVersion

func (tenant *Tenant) ReloadUsingTxVersion(ctx context.Context, tx transaction.Tx, id string) error

func (*Tenant) String

func (tenant *Tenant) String() string

type TenantManager

type TenantManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TenantManager is to manage all the tenants ToDo: start a background thread to reload the mapping

func NewTenantManager

func NewTenantManager() *TenantManager

func (*TenantManager) CreateOrGetTenant

func (m *TenantManager) CreateOrGetTenant(ctx context.Context, txMgr *transaction.Manager, namespace Namespace) (tenant *Tenant, err error)

CreateOrGetTenant is a thread safe implementation of creating a new tenant. It returns the tenant if it already exists. This is mainly returning the tenant to avoid calling "Get" again after creating the tenant. This method is expensive as it reloads the existing tenants from the disk if it sees the tenant is not present in the cache.

func (*TenantManager) GetTableNameFromId

func (m *TenantManager) GetTableNameFromId(tenantId uint32, dbId uint32, collId uint32) (string, string, string, bool)

GetTableNameFromId returns tenant name, database name, collection name corresponding to their encoded ids.

func (*TenantManager) Reload

func (m *TenantManager) Reload(ctx context.Context, tx transaction.Tx) error

Reload reads all the namespaces exists in the disk and build the in-memory map of the manager to track the tenants. As this is an expensive call, the reloading happens during start time for now. It is possible that reloading fails during start time then we rely on lazily reloading cache during serving user requests.

type TenantNamespace

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

TenantNamespace is used when there is a finer isolation of databases is needed. The caller provides a unique name and unique id to this namespace which is used by the cluster to create a namespace.

func NewTenantNamespace

func NewTenantNamespace(name string, id uint32) *TenantNamespace

func (*TenantNamespace) Id

func (n *TenantNamespace) Id() uint32

Id returns assigned id for the namespace

func (*TenantNamespace) Name

func (n *TenantNamespace) Name() string

type Version

type Version []byte

type VersionHandler

type VersionHandler struct{}

VersionHandler is used to maintain a version for each schema change. Using this we can implement transactional DDL APIs. This will also be used to provide a strongly consistent Cache lookup on the schemas i.e. anytime version changes we know that a DDL operation is performed which means we can invalidate the cache and reload from the disk.

func (*VersionHandler) Increment

func (m *VersionHandler) Increment(ctx context.Context, tx transaction.Tx) error

Increment is used to increment the metadata version

func (*VersionHandler) Read

Read reads the latest metadata version

func (*VersionHandler) ReadInOwnTxn

func (m *VersionHandler) ReadInOwnTxn(ctx context.Context, txMgr *transaction.Manager) (version Version, err error)

ReadInOwnTxn creates a transaction and then read the version. This is mainly needed when a query is doing metadata changed in that case it is bumping the metadata version and that means we can't read the metadata version in the same transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL