Documentation ¶
Index ¶
- Constants
- Variables
- func JSONSchemaEqual(s1, s2 []byte) (bool, error)
- type Database
- type DefaultNamespace
- type DictKeyEncoder
- func (d *DictKeyEncoder) DecodeIndexName(indexName []byte) uint32
- func (d *DictKeyEncoder) DecodeTableName(tableName []byte) (uint32, uint32, uint32)
- func (d *DictKeyEncoder) EncodeIndexName(idx *schema.Index) []byte
- func (d *DictKeyEncoder) EncodeKey(ns Namespace, db *Database, coll *schema.DefaultCollection, idx *schema.Index, ...) (keys.Key, error)
- func (d *DictKeyEncoder) EncodeTableName(ns Namespace, db *Database, coll *schema.DefaultCollection) []byte
- type Encoder
- type MetaVersion
- type Namespace
- type NamespaceType
- type Tenant
- func (tenant *Tenant) CreateCollection(ctx context.Context, tx transaction.Tx, dbObj *Database, ...) error
- func (tenant *Tenant) CreateDatabase(ctx context.Context, tx transaction.Tx, dbName string) error
- func (tenant *Tenant) DropCollection(ctx context.Context, tx transaction.Tx, db *Database, collectionName string) error
- func (tenant *Tenant) DropDatabase(ctx context.Context, tx transaction.Tx, dbName string) error
- func (tenant *Tenant) GetDatabase(ctx context.Context, tx transaction.Tx, dbName string) (*Database, error)
- func (tenant *Tenant) GetNamespace() Namespace
- func (tenant *Tenant) InvalidateDBCache(dbName string)
- func (tenant *Tenant) ListDatabases(ctx context.Context, tx transaction.Tx) []string
- func (tenant *Tenant) String() string
- type TenantManager
- type TenantNamespace
- type Version
Constants ¶
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 ¶
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 JSONSchemaEqual ¶
Types ¶
type Database ¶
Database is to manage the collections for this database. Check the Clone method before changing this struct.
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) ListCollection ¶
func (d *Database) ListCollection() []*schema.DefaultCollection
ListCollection returns the collection object of all the collections in this database.
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{}
func (*DictKeyEncoder) DecodeIndexName ¶
func (d *DictKeyEncoder) DecodeIndexName(indexName []byte) uint32
func (*DictKeyEncoder) DecodeTableName ¶
func (d *DictKeyEncoder) DecodeTableName(tableName []byte) (uint32, uint32, uint32)
func (*DictKeyEncoder) EncodeIndexName ¶
func (d *DictKeyEncoder) EncodeIndexName(idx *schema.Index) []byte
func (*DictKeyEncoder) EncodeKey ¶
func (d *DictKeyEncoder) EncodeKey(ns Namespace, db *Database, coll *schema.DefaultCollection, idx *schema.Index, idxParts []interface{}) (keys.Key, error)
func (*DictKeyEncoder) EncodeTableName ¶
func (d *DictKeyEncoder) EncodeTableName(ns Namespace, db *Database, coll *schema.DefaultCollection) []byte
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 // 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(ns Namespace, db *Database, coll *schema.DefaultCollection, idx *schema.Index, idxParts []interface{}) (keys.Key, error) DecodeTableName(tableName []byte) (uint32, uint32, uint32) DecodeIndexName(indexName []byte) uint32 }
Encoder is used to encode/decode values of the Key.
type MetaVersion ¶
type MetaVersion struct{}
MetaVersion 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 (*MetaVersion) Increment ¶
func (m *MetaVersion) Increment(ctx context.Context, tx transaction.Tx) error
Increment is used to increment the metadata version
func (*MetaVersion) Read ¶
func (m *MetaVersion) Read(ctx context.Context, tx transaction.Tx) (Version, error)
Read reads the latest metadata version
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 ¶
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 (*Tenant) CreateCollection ¶
func (tenant *Tenant) CreateCollection(ctx context.Context, tx transaction.Tx, dbObj *Database, schFactory *schema.Factory) error
CreateCollection is to create a collection inside tenant namespace.
func (*Tenant) CreateDatabase ¶
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 so it is better to rely on the GetDatabase call to reload this mapping.
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 ¶
DropDatabase is responsible for first dropping a dictionary encoding of the database and then adding a corresponding dropped encoding in the table.
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) InvalidateDBCache ¶
func (*Tenant) ListDatabases ¶
type TenantManager ¶
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, tx transaction.Tx, namespace Namespace) (*Tenant, 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) GetTenant ¶
func (m *TenantManager) GetTenant(namespace string) *Tenant
GetTenant returns tenants if exists in the tenant map or nil.
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 or in background. It is possible that reloading fails during start time then we rely on background thread to reload all the mapping.
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