schema

package
v1.18.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: BSD-3-Clause Imports: 26 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(s1, s2 *State) bool

Equal checks if both schemas are the same by first marshalling, then comparing their byte-representation

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 DeleteClassPayload

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

type InvertedConfigValidator

type InvertedConfigValidator func(in *models.InvertedIndexConfig) error

type Manager

type Manager struct {
	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 Repo,
	logger logrus.FieldLogger, authorizer authorizer, config config.Config,
	hnswConfigParser VectorConfigParser, vectorizerValidator VectorizerValidator,
	invertedConfigValidator InvertedConfigValidator,
	moduleConfig ModuleConfig, clusterState clusterState,
	txClient cluster.Client, 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) ClusterHealthScore

func (m *Manager) ClusterHealthScore() int

func (*Manager) DeleteClass

func (m *Manager) DeleteClass(ctx context.Context, principal *models.Principal, class string, force bool) 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) 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) IndexedInverted

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

func (*Manager) NodeName

func (m *Manager) NodeName() string

func (*Manager) Nodes

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

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,
) (resolved, unresolved []string, err error)

ResolveParentNodes resolves the hostname for each node a shard belongs to

If the hostname cannot be resolved for a given node, the name of the node is returned instead.

func (*Manager) RestoreClass

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

func (*Manager) ShardingState

func (m *Manager) ShardingState(className string) *sharding.State

func (*Manager) TxManager

func (s *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) UpdateMeta

func (m *Manager) UpdateMeta(ctx context.Context,
	atContext strfmt.URI, maintainer strfmt.Email, name string,
) error

UpdateMeta for object

func (*Manager) UpdateObject

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

UpdateObject which exists

func (*Manager) UpdateShardStatus

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

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 Repo

type Repo interface {
	SaveSchema(ctx context.Context, schema State) error

	// should return nil (and no error) to indicate that no remote schema had
	// been stored before
	LoadSchema(ctx context.Context) (*State, error)
}

Repo describes the requirements the schema manager has to a database to load and persist the schema state

type SchemaGetter

type SchemaGetter interface {
	GetSchemaSkipAuth() schema.Schema
	ShardingState(class string) *sharding.State
	Nodes() []string
	NodeName() string
	ClusterHealthScore() int
	ResolveParentNodes(string, string) ([]string, []string, error)
}

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

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 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