| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| package objects |
|
|
| import ( |
| "context" |
| "fmt" |
| "time" |
|
|
| "github.com/go-openapi/strfmt" |
| "github.com/google/uuid" |
| "github.com/sirupsen/logrus" |
|
|
| "github.com/weaviate/weaviate/entities/additional" |
| "github.com/weaviate/weaviate/entities/filters" |
| "github.com/weaviate/weaviate/entities/models" |
| "github.com/weaviate/weaviate/entities/modulecapabilities" |
| "github.com/weaviate/weaviate/entities/schema" |
| "github.com/weaviate/weaviate/entities/schema/crossref" |
| "github.com/weaviate/weaviate/entities/search" |
| "github.com/weaviate/weaviate/entities/versioned" |
| "github.com/weaviate/weaviate/usecases/auth/authorization" |
| "github.com/weaviate/weaviate/usecases/config" |
| "github.com/weaviate/weaviate/usecases/memwatch" |
| "github.com/weaviate/weaviate/usecases/objects/alias" |
| ) |
|
|
| type schemaManager interface { |
| AddClass(ctx context.Context, principal *models.Principal, class *models.Class) (*models.Class, uint64, error) |
| AddTenants(ctx context.Context, principal *models.Principal, class string, tenants []*models.Tenant) (uint64, error) |
| GetClass(ctx context.Context, principal *models.Principal, name string) (*models.Class, error) |
| |
| ReadOnlyClass(name string) *models.Class |
| |
| |
| AddClassProperty(ctx context.Context, principal *models.Principal, class *models.Class, className string, merge bool, prop ...*models.Property) (*models.Class, uint64, error) |
|
|
| |
| |
| |
|
|
| |
| GetConsistentClass(ctx context.Context, principal *models.Principal, |
| name string, consistency bool, |
| ) (*models.Class, uint64, error) |
|
|
| |
| GetCachedClass(ctx context.Context, principal *models.Principal, names ...string, |
| ) (map[string]versioned.Class, error) |
|
|
| GetCachedClassNoAuth(ctx context.Context, names ...string) (map[string]versioned.Class, error) |
|
|
| |
| WaitForUpdate(ctx context.Context, schemaVersion uint64) error |
|
|
| |
| GetConsistentSchema(ctx context.Context, principal *models.Principal, consistency bool) (schema.Schema, error) |
|
|
| |
| ResolveAlias(alias string) string |
| } |
|
|
| |
| |
| type Manager struct { |
| config *config.WeaviateConfig |
| schemaManager schemaManager |
| logger logrus.FieldLogger |
| authorizer authorization.Authorizer |
| vectorRepo VectorRepo |
| timeSource timeSource |
| modulesProvider ModulesProvider |
| autoSchemaManager *AutoSchemaManager |
| metrics objectsMetrics |
| allocChecker *memwatch.Monitor |
| } |
|
|
| type objectsMetrics interface { |
| BatchInc() |
| BatchDec() |
| BatchRefInc() |
| BatchRefDec() |
| BatchDeleteInc() |
| BatchDeleteDec() |
| AddObjectInc() |
| AddObjectDec() |
| UpdateObjectInc() |
| UpdateObjectDec() |
| MergeObjectInc() |
| MergeObjectDec() |
| DeleteObjectInc() |
| DeleteObjectDec() |
| GetObjectInc() |
| GetObjectDec() |
| HeadObjectInc() |
| HeadObjectDec() |
| AddReferenceInc() |
| AddReferenceDec() |
| UpdateReferenceInc() |
| UpdateReferenceDec() |
| DeleteReferenceInc() |
| DeleteReferenceDec() |
| AddUsageDimensions(className, queryType, operation string, dims int) |
| } |
|
|
| type timeSource interface { |
| Now() int64 |
| } |
|
|
| type VectorRepo interface { |
| PutObject(ctx context.Context, concept *models.Object, vector []float32, |
| vectors map[string][]float32, multiVectors map[string][][]float32, |
| repl *additional.ReplicationProperties, schemaVersion uint64) error |
| DeleteObject(ctx context.Context, className string, id strfmt.UUID, deletionTime time.Time, |
| repl *additional.ReplicationProperties, tenant string, schemaVersion uint64) error |
| |
| Object(ctx context.Context, class string, id strfmt.UUID, props search.SelectProperties, |
| additional additional.Properties, repl *additional.ReplicationProperties, |
| tenant string) (*search.Result, error) |
| |
| Exists(ctx context.Context, class string, id strfmt.UUID, |
| repl *additional.ReplicationProperties, tenant string) (bool, error) |
| ObjectByID(ctx context.Context, id strfmt.UUID, props search.SelectProperties, |
| additional additional.Properties, tenant string) (*search.Result, error) |
| ObjectSearch(ctx context.Context, offset, limit int, filters *filters.LocalFilter, |
| sort []filters.Sort, additional additional.Properties, tenant string) (search.Results, error) |
| AddReference(ctx context.Context, source *crossref.RefSource, |
| target *crossref.Ref, repl *additional.ReplicationProperties, tenant string, schemaVersion uint64) error |
| Merge(ctx context.Context, merge MergeDocument, repl *additional.ReplicationProperties, tenant string, schemaVersion uint64) error |
| Query(context.Context, *QueryInput) (search.Results, *Error) |
| } |
|
|
| type ModulesProvider interface { |
| GetObjectAdditionalExtend(ctx context.Context, in *search.Result, |
| moduleParams map[string]interface{}) (*search.Result, error) |
| ListObjectsAdditionalExtend(ctx context.Context, in search.Results, |
| moduleParams map[string]interface{}) (search.Results, error) |
| UsingRef2Vec(className string) bool |
| UpdateVector(ctx context.Context, object *models.Object, class *models.Class, repo modulecapabilities.FindObjectFn, |
| logger logrus.FieldLogger) error |
| BatchUpdateVector(ctx context.Context, class *models.Class, objects []*models.Object, |
| findObjectFn modulecapabilities.FindObjectFn, |
| logger logrus.FieldLogger) (map[int]error, error) |
| VectorizerName(className string) (string, error) |
| } |
|
|
| |
| func NewManager(schemaManager schemaManager, |
| config *config.WeaviateConfig, logger logrus.FieldLogger, |
| authorizer authorization.Authorizer, vectorRepo VectorRepo, |
| modulesProvider ModulesProvider, metrics objectsMetrics, allocChecker *memwatch.Monitor, |
| autoSchemaManager *AutoSchemaManager, |
| ) *Manager { |
| if allocChecker == nil { |
| allocChecker = memwatch.NewDummyMonitor() |
| } |
|
|
| return &Manager{ |
| config: config, |
| schemaManager: schemaManager, |
| logger: logger, |
| authorizer: authorizer, |
| vectorRepo: vectorRepo, |
| timeSource: defaultTimeSource{}, |
| modulesProvider: modulesProvider, |
| autoSchemaManager: autoSchemaManager, |
| metrics: metrics, |
| allocChecker: allocChecker, |
| } |
| } |
|
|
| |
| func (m *Manager) resolveAlias(class string) (className, aliasName string) { |
| return alias.ResolveAlias(m.schemaManager, class) |
| } |
|
|
| func generateUUID() (strfmt.UUID, error) { |
| id, err := uuid.NewRandom() |
| if err != nil { |
| return "", fmt.Errorf("could not generate uuid v4: %w", err) |
| } |
|
|
| return strfmt.UUID(id.String()), nil |
| } |
|
|
| type defaultTimeSource struct{} |
|
|
| func (ts defaultTimeSource) Now() int64 { |
| return time.Now().UnixNano() / int64(time.Millisecond) |
| } |
|
|