schema

package
v1.21.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// write-only
	AddClass    cluster.TransactionType = "add_class"
	AddProperty cluster.TransactionType = "add_property"

	DeleteClass cluster.TransactionType = "delete_class"
	UpdateClass cluster.TransactionType = "update_class"

	// read-only
	ReadSchema cluster.TransactionType = "read_schema"

	DefaultTxTTL = 60 * time.Second
)

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func Diff added in v1.17.4

func Diff(
	leftLabel string, left *State,
	rightLabel string, right *State,
) []string

Diff creates human-readable information about the difference in two schemas, returns a len=0 slice if schemas are identical

func Equal

func Equal(lhs, rhs *State) error

Equal compares two schema states for equality First the object classes are sorted, because they are unordered. Then we can make the comparison using DeepEqual

func UnmarshalTransaction

func UnmarshalTransaction(txType cluster.TransactionType,
	payload json.RawMessage,
) (interface{}, error)

Types

type AddClassPayload

type AddClassPayload struct {
	Class *models.Class   `json:"class"`
	State *sharding.State `json:"state"`
}

type AddPropertyPayload

type AddPropertyPayload struct {
	ClassName string           `json:"className"`
	Property  *models.Property `json:"property"`
}

type AddTenantsPayload added in v1.20.0

type AddTenantsPayload struct {
	Class   string         `json:"class_name"`
	Tenants []TenantCreate `json:"tenants"`
}

AddTenantsPayload allows for adding multiple tenants to a class

type ClassPayload added in v1.20.0

type ClassPayload struct {
	Name          string
	Metadata      []byte
	ShardingState []byte
	Shards        []KeyValuePair
	ReplaceShards bool
	Error         error
}

ClassPayload is used to serialize class updates

func CreateClassPayload added in v1.20.0

func CreateClassPayload(class *models.Class,
	shardingState *sharding.State,
) (pl ClassPayload, err error)

type DeleteClassPayload

type DeleteClassPayload struct {
	ClassName string `json:"className"`
}

type DeleteTenantsPayload added in v1.20.0

type DeleteTenantsPayload struct {
	Class   string   `json:"class_name"`
	Tenants []string `json:"tenants"`
}

DeleteTenantsPayload allows for removing multiple tenants from a class

type InvertedConfigValidator

type InvertedConfigValidator func(in *models.InvertedIndexConfig) error

type KeyValuePair added in v1.20.0

type KeyValuePair struct {
	Key   string
	Value []byte
}

KeyValuePair is used to serialize shards updates

type Manager

type Manager struct {
	Authorizer authorizer

	RestoreStatus sync.Map
	RestoreError  sync.Map
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager Manages schema changes at a use-case level, i.e. agnostic of underlying databases or storage providers

func NewManager

func NewManager(migrator migrate.Migrator, repo SchemaStore,
	logger logrus.FieldLogger, authorizer authorizer, config config.Config,
	hnswConfigParser VectorConfigParser, vectorizerValidator VectorizerValidator,
	invertedConfigValidator InvertedConfigValidator,
	moduleConfig ModuleConfig, clusterState clusterState,
	txClient cluster.Client, txPersistence cluster.Persistence,
	scaleoutManager scaleOut,
) (*Manager, error)

NewManager creates a new manager

func (*Manager) AddClass

func (m *Manager) AddClass(ctx context.Context, principal *models.Principal,
	class *models.Class,
) error

AddClass to the schema

func (*Manager) AddClassProperty

func (m *Manager) AddClassProperty(ctx context.Context, principal *models.Principal,
	class string, property *models.Property,
) error

AddClassProperty to an existing Class

func (*Manager) AddTenants added in v1.20.0

func (m *Manager) AddTenants(ctx context.Context,
	principal *models.Principal,
	class string,
	tenants []*models.Tenant,
) (created []*models.Tenant, err error)

AddTenants is used to add new tenants to a class Class must exist and has partitioning enabled

func (*Manager) ClusterHealthScore

func (m *Manager) ClusterHealthScore() int

func (*Manager) ClusterStatus added in v1.19.10

func (m *Manager) ClusterStatus(ctx context.Context) (*models.SchemaClusterStatus, error)

func (*Manager) CopyShardingState added in v1.20.0

func (s *Manager) CopyShardingState(className string) *sharding.State

func (*Manager) DeleteClass

func (m *Manager) DeleteClass(ctx context.Context, principal *models.Principal, class string) error

DeleteClass from the schema

func (*Manager) DeleteClassProperty

func (m *Manager) DeleteClassProperty(ctx context.Context, principal *models.Principal,
	class string, property string,
) error

DeleteClassProperty from existing Schema

func (*Manager) DeleteTenants added in v1.20.0

func (m *Manager) DeleteTenants(ctx context.Context, principal *models.Principal, class string, tenants []string) error

DeleteTenants is used to delete tenants of a class.

Class must exist and has partitioning enabled

func (*Manager) GetClass

func (m *Manager) GetClass(ctx context.Context, principal *models.Principal,
	name string,
) (*models.Class, error)

func (*Manager) GetSchema

func (m *Manager) GetSchema(principal *models.Principal) (schema.Schema, error)

GetSchema retrieves a locally cached copy of the schema

func (*Manager) GetSchemaSkipAuth

func (m *Manager) GetSchemaSkipAuth() schema.Schema

GetSchemaSkipAuth can never be used as a response to a user request as it could leak the schema to an unauthorized user, is intended to be used for non-user triggered processes, such as regular updates / maintenance / etc

func (*Manager) GetShardsStatus

func (m *Manager) GetShardsStatus(ctx context.Context, principal *models.Principal,
	className string,
) (models.ShardStatusList, error)

func (*Manager) GetTenants added in v1.20.0

func (m *Manager) GetTenants(ctx context.Context, principal *models.Principal, class string) ([]*models.Tenant, error)

GetTenants is used to get tenants of a class.

Class must exist and has partitioning enabled

func (*Manager) IndexedInverted

func (m *Manager) IndexedInverted(className, propertyName string) bool

func (*Manager) LockGuard added in v1.20.0

func (s *Manager) LockGuard(mutate func())

LockGuard provides convenient mechanism for owning mutex by function which mutates the state

func (*Manager) NodeName

func (m *Manager) NodeName() string

func (*Manager) Nodes

func (m *Manager) Nodes() []string

func (*Manager) RLockGuard added in v1.20.0

func (s *Manager) RLockGuard(reader func() error) error

RLockGuard provides convenient mechanism for owning mutex function which doesn't mutates the state

func (*Manager) RegisterSchemaUpdateCallback

func (m *Manager) RegisterSchemaUpdateCallback(callback func(updatedSchema schema.Schema))

RegisterSchemaUpdateCallback allows other usecases to register a primitive type update callback. The callbacks will be called any time we persist a schema upadate

func (*Manager) ResolveParentNodes added in v1.18.0

func (m *Manager) ResolveParentNodes(class, shardName string) (map[string]string, error)

ResolveParentNodes gets all replicas for a specific class shard and resolves their names

it returns map[node_name] node_address where node_address = "" if can't resolve node_name

func (*Manager) RestoreClass

func (m *Manager) RestoreClass(ctx context.Context, d *backup.ClassDescriptor) error

func (*Manager) ShardFromUUID added in v1.20.0

func (s *Manager) ShardFromUUID(class string, uuid []byte) string

ShardFromUUID returns shard name of the provided uuid

func (*Manager) ShardOwner added in v1.20.0

func (s *Manager) ShardOwner(class, shard string) (string, error)

ShardOwner returns the node owner of the specified shard

func (*Manager) ShardReplicas added in v1.20.0

func (s *Manager) ShardReplicas(class, shard string) ([]string, error)

ShardOwner returns the node owner of the specified shard

func (*Manager) Shutdown added in v1.21.3

func (m *Manager) Shutdown(ctx context.Context) error

func (*Manager) StartServing added in v1.21.3

func (m *Manager) StartServing(ctx context.Context) error

StartServing indicates that the schema manager is ready to accept incoming connections in cluster mode, i.e. it will accept opening transactions.

Some transactions are exempt, such as ReadSchema which is required for nodes to start up.

This method should be called when all backends, primarily the DB, are ready to serve.

func (*Manager) TenantShard added in v1.20.0

func (s *Manager) TenantShard(class, tenant string) (string, string)

TenantShard returns shard name for the provided tenant and its activity status

func (*Manager) TxManager

func (m *Manager) TxManager() *cluster.TxManager

func (*Manager) UpdateClass

func (m *Manager) UpdateClass(ctx context.Context, principal *models.Principal,
	className string, updated *models.Class,
) error

func (*Manager) UpdateShardStatus

func (m *Manager) UpdateShardStatus(ctx context.Context, principal *models.Principal,
	className, shardName, targetStatus string,
) error

func (*Manager) UpdateTenants added in v1.21.0

func (m *Manager) UpdateTenants(ctx context.Context, principal *models.Principal,
	class string, tenants []*models.Tenant,
) error

UpdateTenants is used to set activity status of tenants of a class.

Class must exist and has partitioning enabled

type ModuleConfig

type ModuleConfig interface {
	SetClassDefaults(class *models.Class)
	SetSinglePropertyDefaults(class *models.Class, prop *models.Property)
	ValidateClass(ctx context.Context, class *models.Class) error
}

type ReadSchemaPayload

type ReadSchemaPayload struct {
	Schema *State `json:"schema"`
}

type RefFinder

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

RefFinder is a helper that lists classes and their possible paths to to a desired target class.

For example if the target class is "car". It might list: - Person, drives, Car - Person, owns, Car - Person, friendsWith, Person, drives, Car etc.

It will stop at a preconfigured depth limit, to avoid infinite results, such as: - Person, friendsWith, Person, friendsWith, Person, ..., drives Car

func NewRefFinder

func NewRefFinder(getter schemaGetterForRefFinder, depthLimit int) *RefFinder

NewRefFinder with SchemaGetter and depth limit

func (*RefFinder) Find

func (r *RefFinder) Find(className libschema.ClassName) []filters.Path

type SchemaGetter

type SchemaGetter interface {
	GetSchemaSkipAuth() schema.Schema
	Nodes() []string
	NodeName() string
	ClusterHealthScore() int
	ResolveParentNodes(string, string) (map[string]string, error)

	CopyShardingState(class string) *sharding.State
	ShardOwner(class, shard string) (string, error)
	TenantShard(class, tenant string) (string, string)
	ShardFromUUID(class string, uuid []byte) string
	ShardReplicas(class, shard string) ([]string, error)
}

type SchemaStore added in v1.20.0

type SchemaStore interface {
	// Save saves the complete schema to the persistent storage
	Save(ctx context.Context, schema State) error

	// Load loads the complete schema from the persistent storage
	Load(context.Context) (State, error)

	// NewClass creates a new class if it doesn't exists, otherwise return an error
	NewClass(context.Context, ClassPayload) error

	// UpdateClass if it exists, otherwise return an error
	UpdateClass(context.Context, ClassPayload) error

	// DeleteClass deletes class
	DeleteClass(ctx context.Context, class string) error

	// NewShards creates new shards of an existing class
	NewShards(ctx context.Context, class string, shards []KeyValuePair) error

	// UpdateShards updates (replaces) shards of on existing class
	// Error is returned if class or shard does not exist
	UpdateShards(ctx context.Context, class string, shards []KeyValuePair) error

	// DeleteShards deletes shards from a class
	// If the class or a shard does not exist then nothing is done and a nil error is returned
	DeleteShards(ctx context.Context, class string, shards []string) error
}

SchemaStore is responsible for persisting the schema by providing support for both partial and complete schema updates

type State

type State struct {
	ObjectSchema  *models.Schema `json:"object"`
	ShardingState map[string]*sharding.State
}

State is a cached copy of the schema that can also be saved into a remote storage, as specified by Repo

func NewState added in v1.20.0

func NewState(nClasses int) State

NewState returns a new state with room for nClasses classes

type TenantCreate added in v1.21.0

type TenantCreate struct {
	Name   string   `json:"name"`
	Nodes  []string `json:"nodes"`
	Status string   `json:"status"`
}

TenantCreate represents properties of a specific tenant (physical shard)

type TenantUpdate added in v1.21.0

type TenantUpdate struct {
	Name   string `json:"name"`
	Status string `json:"status"`
}

type UpdateClassPayload

type UpdateClassPayload struct {
	ClassName string        `json:"className"`
	Class     *models.Class `json:"class"`

	// For now, the state cannot be updated yet, but this will be a requirement
	// in the future, for example, with dynamically changing replication, so we
	// should already make sure that state is part of the transaction payload
	State *sharding.State `json:"state"`
}

type UpdateTenantsPayload added in v1.21.0

type UpdateTenantsPayload struct {
	Class   string         `json:"class_name"`
	Tenants []TenantUpdate `json:"tenants"`
}

type VectorConfigParser

type VectorConfigParser func(in interface{}) (schema.VectorIndexConfig, error)

type VectorizerValidator

type VectorizerValidator interface {
	ValidateVectorizer(moduleName string) error
}

Directories

Path Synopsis
Package migrate provides a simple composer tool, which implements the Migrator interface and can take in any number of migrators which themselves have to implement the interface
Package migrate provides a simple composer tool, which implements the Migrator interface and can take in any number of migrators which themselves have to implement the interface

Jump to

Keyboard shortcuts

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