| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| package schema |
|
|
| import ( |
| "context" |
|
|
| "github.com/prometheus/client_golang/prometheus" |
| "github.com/weaviate/weaviate/entities/models" |
| "github.com/weaviate/weaviate/usecases/monitoring" |
| "github.com/weaviate/weaviate/usecases/sharding" |
| ) |
|
|
| |
| |
| |
| |
| type VersionedSchemaReader struct { |
| schema *schema |
| WaitForUpdate func(ctx context.Context, version uint64) error |
| } |
|
|
| func (s VersionedSchemaReader) ClassInfo(ctx context.Context, |
| class string, |
| v uint64, |
| ) (ClassInfo, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("ClassInfo")) |
| defer t.ObserveDuration() |
|
|
| err := s.WaitForUpdate(ctx, v) |
| return s.schema.ClassInfo(class), err |
| } |
|
|
| func (s VersionedSchemaReader) MultiTenancy(ctx context.Context, |
| class string, |
| v uint64, |
| ) (models.MultiTenancyConfig, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("MultiTenancy")) |
| defer t.ObserveDuration() |
|
|
| if info := s.schema.ClassInfo(class); info.Exists { |
| return info.MultiTenancy, nil |
| } |
| err := s.WaitForUpdate(ctx, v) |
| return s.schema.MultiTenancy(class), err |
| } |
|
|
| |
| func (s VersionedSchemaReader) Read(ctx context.Context, |
| class string, v uint64, |
| reader func(*models.Class, *sharding.State) error, |
| ) error { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("Read")) |
| defer t.ObserveDuration() |
|
|
| if err := s.WaitForUpdate(ctx, v); err != nil { |
| return err |
| } |
|
|
| return s.schema.Read(class, reader) |
| } |
|
|
| |
| |
| func (s VersionedSchemaReader) ReadOnlyClass(ctx context.Context, |
| class string, |
| v uint64, |
| ) (*models.Class, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("ReadOnlyClass")) |
| defer t.ObserveDuration() |
|
|
| err := s.WaitForUpdate(ctx, v) |
| cls, _ := s.schema.ReadOnlyClass(class) |
| return cls, err |
| } |
|
|
| |
| func (s VersionedSchemaReader) ShardOwner(ctx context.Context, |
| class, shard string, |
| v uint64, |
| ) (string, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("ShardOwner")) |
| defer t.ObserveDuration() |
|
|
| err := s.WaitForUpdate(ctx, v) |
| owner, _, sErr := s.schema.ShardOwner(class, shard) |
| if sErr != nil && err == nil { |
| err = sErr |
| } |
| return owner, err |
| } |
|
|
| |
| func (s VersionedSchemaReader) ShardFromUUID(ctx context.Context, |
| class string, uuid []byte, v uint64, |
| ) (string, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("ShardFromUUID")) |
| defer t.ObserveDuration() |
|
|
| err := s.WaitForUpdate(ctx, v) |
| shard, _ := s.schema.ShardFromUUID(class, uuid) |
| return shard, err |
| } |
|
|
| |
| func (s VersionedSchemaReader) ShardReplicas( |
| ctx context.Context, class, shard string, |
| v uint64, |
| ) ([]string, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("ShardReplicas")) |
| defer t.ObserveDuration() |
|
|
| err := s.WaitForUpdate(ctx, v) |
| nodes, _, sErr := s.schema.ShardReplicas(class, shard) |
| if sErr != nil && err == nil { |
| err = sErr |
| } |
| return nodes, err |
| } |
|
|
| |
| func (s VersionedSchemaReader) TenantsShards(ctx context.Context, |
| v uint64, class string, tenants ...string, |
| ) (map[string]string, uint64, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaWaitForVersion.WithLabelValues("TenantsShards")) |
| defer t.ObserveDuration() |
|
|
| err := s.WaitForUpdate(ctx, v) |
| status, version := s.schema.TenantsShards(class, tenants...) |
| return status, version, err |
| } |
|
|
| func (s VersionedSchemaReader) Len() int { return s.schema.len() } |
|
|