schema

package
v1.25.31 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest = errors.New("bad request")

	ErrSchema = errors.New("updating schema")
)
View Source
var (
	ErrClassExists   = errors.New("class already exists")
	ErrClassNotFound = errors.New("class not found")
	ErrShardNotFound = errors.New("shard not found")
	ErrMTDisabled    = errors.New("multi-tenancy is not enabled")
)

Functions

func LegacySnapshot

func LegacySnapshot(nodeID string, m map[string]types.ClassState) (*raft.SnapshotMeta, io.ReadCloser, error)

LegacySnapshot returns a ready-to-use in-memory Raft snapshot based on the provided legacy schema

func MergeProps

func MergeProps(old, new []*models.Property) []*models.Property

MergeProps makes sure duplicates are not created by ignoring new props with the same names as old props. If property of nested type is present in both new and old slices, final property is created by merging new property into copy of old one

func NewSchema

func NewSchema(nodeID string, shardReader shardReader, reg prometheus.Registerer) *schema

Types

type ClassInfo

type ClassInfo struct {
	Exists            bool
	MultiTenancy      models.MultiTenancyConfig
	ReplicationFactor int
	Tenants           int
	Properties        int
	ClassVersion      uint64
	ShardVersion      uint64
}

func (*ClassInfo) Version

func (ci *ClassInfo) Version() uint64

type Indexer

type Indexer interface {
	AddClass(api.AddClassRequest) error
	UpdateClass(api.UpdateClassRequest) error
	DeleteClass(string) error
	AddProperty(class string, req api.AddPropertyRequest) error
	AddTenants(class string, req *api.AddTenantsRequest) error
	UpdateTenants(class string, req *api.UpdateTenantsRequest) error
	DeleteTenants(class string, req *api.DeleteTenantsRequest) error
	UpdateShardStatus(*api.UpdateShardStatusRequest) error
	GetShardsStatus(class, tenant string) (models.ShardStatusList, error)
	UpdateIndex(api.UpdateClassRequest) error

	TriggerSchemaUpdateCallbacks()

	// ReloadLocalDB reloads the local database using the latest schema.
	ReloadLocalDB(ctx context.Context, all []api.UpdateClassRequest) error

	// RestoreClassDir restores classes on the filesystem directly from the temporary class backup stored on disk.
	RestoreClassDir(class string) error
	Open(context.Context) error
	Close(context.Context) error
}

Indexer interface updates both the collection and its indices in the filesystem. This is distinct from updating metadata, which is handled through a different interface.

type LoadLegacySchema

type LoadLegacySchema func() (map[string]types.ClassState, error)

LoadLegacySchema returns the legacy schema

type Parser

type Parser interface {
	// ParseClassUpdate parses a class after unmarshaling by setting concrete types for the fields
	ParseClass(class *models.Class) error

	// ParseClass parses new updates by providing the current class data.
	ParseClassUpdate(class, update *models.Class) (*models.Class, error)
}

Parser parses concrete class fields after deserialization

type SaveLegacySchema

type SaveLegacySchema func(map[string]types.ClassState) error

SaveLegacySchema saves the RAFT schema representation to the legacy storage

type SchemaManager

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

func NewSchemaManager

func NewSchemaManager(nodeId string, db Indexer, parser Parser, reg prometheus.Registerer, log *logrus.Logger) *SchemaManager

func (*SchemaManager) AddClass

func (s *SchemaManager) AddClass(cmd *command.ApplyRequest, nodeID string, schemaOnly bool, enableSchemaCallback bool) error

func (*SchemaManager) AddProperty

func (s *SchemaManager) AddProperty(cmd *command.ApplyRequest, schemaOnly bool, enableSchemaCallback bool) error

func (*SchemaManager) AddTenants

func (s *SchemaManager) AddTenants(cmd *command.ApplyRequest, schemaOnly bool) error

func (*SchemaManager) Close

func (s *SchemaManager) Close(ctx context.Context) (err error)

func (*SchemaManager) DeleteClass

func (s *SchemaManager) DeleteClass(cmd *command.ApplyRequest, schemaOnly bool, enableSchemaCallback bool) error

func (*SchemaManager) DeleteTenants

func (s *SchemaManager) DeleteTenants(cmd *command.ApplyRequest, schemaOnly bool) error

func (*SchemaManager) Load

func (s *SchemaManager) Load(ctx context.Context, nodeID string) error

func (*SchemaManager) NewSchemaReader

func (s *SchemaManager) NewSchemaReader() SchemaReader

func (*SchemaManager) NewSchemaReaderWithWaitFunc

func (s *SchemaManager) NewSchemaReaderWithWaitFunc(f func(context.Context, uint64) error) SchemaReader

func (*SchemaManager) PreApplyFilter

func (s *SchemaManager) PreApplyFilter(req *command.ApplyRequest) error

func (*SchemaManager) QueryReadOnlyClasses

func (sm *SchemaManager) QueryReadOnlyClasses(req *cmd.QueryRequest) ([]byte, error)

func (*SchemaManager) QuerySchema

func (sm *SchemaManager) QuerySchema() ([]byte, error)

func (*SchemaManager) QueryShardOwner

func (sm *SchemaManager) QueryShardOwner(req *cmd.QueryRequest) ([]byte, error)

func (*SchemaManager) QueryShardingState

func (sm *SchemaManager) QueryShardingState(req *cmd.QueryRequest) ([]byte, error)

func (*SchemaManager) QueryTenants

func (sm *SchemaManager) QueryTenants(req *cmd.QueryRequest) ([]byte, error)

func (*SchemaManager) QueryTenantsShards

func (sm *SchemaManager) QueryTenantsShards(req *cmd.QueryRequest) ([]byte, error)

func (*SchemaManager) ReloadDBFromSchema

func (s *SchemaManager) ReloadDBFromSchema()

func (*SchemaManager) ReplaceStatesNodeName added in v1.25.12

func (s *SchemaManager) ReplaceStatesNodeName(new string)

ReplaceStatesNodeName it update the node name inside sharding states. WARNING: this shall be used in one node cluster environments only. because it will replace the shard node name if the node name got updated only if the replication factor is 1, otherwise it's no-op

func (*SchemaManager) Restore

func (s *SchemaManager) Restore(rc io.ReadCloser, parser Parser) error

func (*SchemaManager) RestoreClass

func (s *SchemaManager) RestoreClass(cmd *command.ApplyRequest, nodeID string, schemaOnly bool, enableSchemaCallback bool) error

func (*SchemaManager) SetIndexer

func (s *SchemaManager) SetIndexer(idx Indexer)

func (*SchemaManager) Snapshot

func (s *SchemaManager) Snapshot() raft.FSMSnapshot

func (*SchemaManager) UpdateClass

func (s *SchemaManager) UpdateClass(cmd *command.ApplyRequest, nodeID string, schemaOnly bool, enableSchemaCallback bool) error

UpdateClass modifies the vectors and inverted indexes associated with a class Other class properties are handled by separate functions

func (*SchemaManager) UpdateShardStatus

func (s *SchemaManager) UpdateShardStatus(cmd *command.ApplyRequest, schemaOnly bool) error

func (*SchemaManager) UpdateTenants

func (s *SchemaManager) UpdateTenants(cmd *command.ApplyRequest, schemaOnly bool) error

type SchemaReader

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

SchemaReader is used for retrying schema queries. It is a thin wrapper around the original schema, separating retry logic from the actual operation. Retry may be needed due to eventual consistency issues where updates might take some time to arrive at the follower.

func (SchemaReader) ClassEqual

func (rs SchemaReader) ClassEqual(name string) string

ClassEqual returns the name of an existing class with a similar name, and "" otherwise strings.EqualFold is used to compare classes

func (SchemaReader) ClassInfo

func (rs SchemaReader) ClassInfo(class string) (ci ClassInfo)

func (SchemaReader) ClassInfoWithVersion

func (rs SchemaReader) ClassInfoWithVersion(ctx context.Context, class string, version uint64) (ci ClassInfo, err error)

func (SchemaReader) CopyShardingState

func (rs SchemaReader) CopyShardingState(class string) (ss *sharding.State)

func (SchemaReader) CopyShardingStateWithVersion

func (rs SchemaReader) CopyShardingStateWithVersion(ctx context.Context, class string, version uint64) (ss *sharding.State, err error)

func (SchemaReader) GetShardsStatus

func (rs SchemaReader) GetShardsStatus(class, tenant string) (models.ShardStatusList, error)

func (SchemaReader) Len

func (rs SchemaReader) Len() int

func (SchemaReader) MultiTenancy

func (rs SchemaReader) MultiTenancy(class string) models.MultiTenancyConfig

func (SchemaReader) MultiTenancyWithVersion

func (rs SchemaReader) MultiTenancyWithVersion(ctx context.Context, class string, version uint64) (models.MultiTenancyConfig, error)

func (SchemaReader) Read

func (rs SchemaReader) Read(class string, reader func(*models.Class, *sharding.State) error) error

Read performs a read operation `reader` on the specified class and sharding state

func (SchemaReader) ReadOnlyClass

func (rs SchemaReader) ReadOnlyClass(class string) (cls *models.Class)

ReadOnlyClass returns a shallow copy of a class. The copy is read-only and should not be modified.

func (SchemaReader) ReadOnlyClassWithVersion

func (rs SchemaReader) ReadOnlyClassWithVersion(ctx context.Context, class string, version uint64) (cls *models.Class, err error)

ReadOnlyClass returns a shallow copy of a class. The copy is read-only and should not be modified.

func (SchemaReader) ReadOnlySchema

func (rs SchemaReader) ReadOnlySchema() models.Schema

ReadOnlySchema returns a read only schema Changing the schema outside this package might lead to undefined behavior.

it creates a shallow copy of existing classes

This function assumes that class attributes are being overwritten. The properties attribute is the only one that might vary in size; therefore, we perform a shallow copy of the existing properties. This implementation assumes that individual properties are overwritten rather than partially updated

func (SchemaReader) ShardFromUUID

func (rs SchemaReader) ShardFromUUID(class string, uuid []byte) (shard string)

ShardFromUUID returns shard name of the provided uuid

func (SchemaReader) ShardFromUUIDWithVersion

func (rs SchemaReader) ShardFromUUIDWithVersion(ctx context.Context, class string, uuid []byte, version uint64) (shard string, err error)

ShardFromUUID returns shard name of the provided uuid

func (SchemaReader) ShardOwner

func (rs SchemaReader) ShardOwner(class, shard string) (owner string, err error)

ShardOwner returns the node owner of the specified shard

func (SchemaReader) ShardOwnerWithVersion

func (rs SchemaReader) ShardOwnerWithVersion(ctx context.Context, class, shard string, version uint64) (owner string, err error)

ShardOwner returns the node owner of the specified shard

func (SchemaReader) ShardReplicas

func (rs SchemaReader) ShardReplicas(class, shard string) (nodes []string, err error)

ShardReplicas returns the replica nodes of a shard

func (SchemaReader) ShardReplicasWithVersion

func (rs SchemaReader) ShardReplicasWithVersion(ctx context.Context, class, shard string, version uint64) (nodes []string, err error)

ShardReplicas returns the replica nodes of a shard

func (SchemaReader) States

func (rs SchemaReader) States() map[string]types.ClassState

func (SchemaReader) TenantsShards

func (rs SchemaReader) TenantsShards(class string, tenants ...string) (map[string]string, error)

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

func (SchemaReader) TenantsShardsWithVersion

func (rs SchemaReader) TenantsShardsWithVersion(ctx context.Context, version uint64, class string, tenants ...string) (tenantShards map[string]string, err error)

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

func (SchemaReader) WaitForUpdate

func (rs SchemaReader) WaitForUpdate(ctx context.Context, version uint64) error

type VersionedSchemaReader

type VersionedSchemaReader struct {
	WaitForUpdate func(ctx context.Context, version uint64) error
	// contains filtered or unexported fields
}

VersionedSchemaReader is utilized to query the schema based on a specific update version. Serving as a thin wrapper around the original schema, it segregates waiting logic from the actual operation. It waits until it finds an update at least as up-to-date as the specified version. Note that updates may take some time to propagate to the follower, hence this process might take time.

func (VersionedSchemaReader) ClassEqual

func (s VersionedSchemaReader) ClassEqual(name string) string

ClassEqual returns the name of an existing class with a similar name, and "" otherwise strings.EqualFold is used to compare classes

func (VersionedSchemaReader) ClassInfo

func (s VersionedSchemaReader) ClassInfo(ctx context.Context,
	class string,
	v uint64,
) (ClassInfo, error)

func (VersionedSchemaReader) CopyShardingState

func (s VersionedSchemaReader) CopyShardingState(ctx context.Context,
	class string, v uint64,
) (*sharding.State, error)

func (VersionedSchemaReader) Len

func (s VersionedSchemaReader) Len() int

func (VersionedSchemaReader) MultiTenancy

func (s VersionedSchemaReader) MultiTenancy(ctx context.Context,
	class string,
	v uint64,
) (models.MultiTenancyConfig, error)

func (VersionedSchemaReader) Read

func (s VersionedSchemaReader) Read(ctx context.Context,
	class string, v uint64,
	reader func(*models.Class, *sharding.State) error,
) error

Read performs a read operation `reader` on the specified class and sharding state

func (VersionedSchemaReader) ReadOnlyClass

func (s VersionedSchemaReader) ReadOnlyClass(ctx context.Context,
	class string,
	v uint64,
) (*models.Class, error)

ReadOnlyClass returns a shallow copy of a class. The copy is read-only and should not be modified.

func (VersionedSchemaReader) ShardFromUUID

func (s VersionedSchemaReader) ShardFromUUID(ctx context.Context,
	class string, uuid []byte, v uint64,
) (string, error)

ShardFromUUID returns shard name of the provided uuid

func (VersionedSchemaReader) ShardOwner

func (s VersionedSchemaReader) ShardOwner(ctx context.Context,
	class, shard string,
	v uint64,
) (string, error)

ShardOwner returns the node owner of the specified shard

func (VersionedSchemaReader) ShardReplicas

func (s VersionedSchemaReader) ShardReplicas(
	ctx context.Context, class, shard string,
	v uint64,
) ([]string, error)

ShardReplicas returns the replica nodes of a shard

func (VersionedSchemaReader) TenantsShards

func (s VersionedSchemaReader) TenantsShards(ctx context.Context,
	v uint64, class string, tenants ...string,
) (map[string]string, uint64, error)

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

Jump to

Keyboard shortcuts

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