| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| package schema |
|
|
| import ( |
| "context" |
|
|
| "github.com/cenkalti/backoff/v4" |
| "github.com/prometheus/client_golang/prometheus" |
| "github.com/weaviate/weaviate/cluster/types" |
| "github.com/weaviate/weaviate/cluster/utils" |
| "github.com/weaviate/weaviate/entities/models" |
| "github.com/weaviate/weaviate/entities/versioned" |
| "github.com/weaviate/weaviate/usecases/monitoring" |
| "github.com/weaviate/weaviate/usecases/sharding" |
| ) |
|
|
| |
| |
| |
| |
| type SchemaReader struct { |
| schema *schema |
| versionedSchemaReader VersionedSchemaReader |
| } |
|
|
| func NewSchemaReader(sc *schema, vsr VersionedSchemaReader) SchemaReader { |
| return SchemaReader{ |
| schema: sc, |
| versionedSchemaReader: vsr, |
| } |
| } |
|
|
| func NewSchemaReaderWithoutVersion(sc *schema) SchemaReader { |
| return SchemaReader{ |
| schema: sc, |
| versionedSchemaReader: VersionedSchemaReader{ |
| schema: sc, |
| WaitForUpdate: func(context.Context, uint64) error { return nil }, |
| }, |
| } |
| } |
|
|
| func (rs SchemaReader) States() map[string]types.ClassState { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("States")) |
| defer t.ObserveDuration() |
|
|
| return rs.schema.States() |
| } |
|
|
| func (rs SchemaReader) ClassInfo(class string) (ci ClassInfo) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ClassInfo")) |
| defer t.ObserveDuration() |
|
|
| res, _ := rs.ClassInfoWithVersion(context.TODO(), class, 0) |
| return res |
| } |
|
|
| |
| |
| func (rs SchemaReader) ClassEqual(name string) string { |
| x, _ := rs.schema.ClassEqual(name) |
| return x |
| } |
|
|
| func (rs SchemaReader) MultiTenancy(class string) models.MultiTenancyConfig { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("MultiTenancy")) |
| defer t.ObserveDuration() |
| res, _ := rs.MultiTenancyWithVersion(context.TODO(), class, 0) |
| return res |
| } |
|
|
| |
| func (rs SchemaReader) Read(class string, reader func(*models.Class, *sharding.State) error) error { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("Read")) |
| defer t.ObserveDuration() |
|
|
| return rs.retry(func(s *schema) error { |
| return s.Read(class, reader) |
| }) |
| } |
|
|
| func (rs SchemaReader) Shards(class string) ([]string, error) { |
| var shards []string |
| err := rs.Read(class, func(class *models.Class, state *sharding.State) error { |
| shards = state.AllPhysicalShards() |
| return nil |
| }) |
|
|
| return shards, err |
| } |
|
|
| func (rs SchemaReader) LocalShards(class string) ([]string, error) { |
| var shards []string |
| err := rs.Read(class, func(class *models.Class, state *sharding.State) error { |
| shards = state.AllLocalPhysicalShards() |
| return nil |
| }) |
| return shards, err |
| } |
|
|
| |
| |
| func (rs SchemaReader) ReadOnlyClass(class string) (cls *models.Class) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ReadOnlyClass")) |
| defer t.ObserveDuration() |
|
|
| res, _ := rs.ReadOnlyClassWithVersion(context.TODO(), class, 0) |
| return res |
| } |
|
|
| func (rs SchemaReader) GetAliasesForClass(class string) []*models.Alias { |
| return rs.schema.GetAliasesForClass(class) |
| } |
|
|
| |
| |
| func (rs SchemaReader) ReadOnlyVersionedClass(className string) versioned.Class { |
| class, version := rs.schema.ReadOnlyClass(className) |
| return versioned.Class{ |
| Class: class, |
| Version: version, |
| } |
| } |
|
|
| func (rs SchemaReader) metaClass(class string) (meta *metaClass) { |
| rs.retry(func(s *schema) error { |
| if meta = s.metaClass(class); meta == nil { |
| return ErrClassNotFound |
| } |
| return nil |
| }) |
| return |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (rs SchemaReader) ReadOnlySchema() models.Schema { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ReadOnlySchema")) |
| defer t.ObserveDuration() |
| return rs.schema.ReadOnlySchema() |
| } |
|
|
| func (rs SchemaReader) ResolveAlias(alias string) string { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ResolveAlias")) |
| defer t.ObserveDuration() |
| return rs.schema.ResolveAlias(alias) |
| } |
|
|
| func (rs SchemaReader) Aliases() map[string]string { |
| return rs.schema.getAliases("", "") |
| } |
|
|
| |
| func (rs SchemaReader) ShardOwner(class, shard string) (owner string, err error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ShardOwner")) |
| defer t.ObserveDuration() |
|
|
| res, err := rs.ShardOwnerWithVersion(context.TODO(), class, shard, 0) |
| return res, err |
| } |
|
|
| |
| func (rs SchemaReader) ShardFromUUID(class string, uuid []byte) (shard string) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ShardFromUUID")) |
| defer t.ObserveDuration() |
|
|
| res, _ := rs.ShardFromUUIDWithVersion(context.TODO(), class, uuid, 0) |
| return res |
| } |
|
|
| |
| func (rs SchemaReader) ShardReplicas(class, shard string) (nodes []string, err error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("ShardReplicas")) |
| defer t.ObserveDuration() |
|
|
| res, err := rs.ShardReplicasWithVersion(context.TODO(), class, shard, 0) |
| return res, err |
| } |
|
|
| |
| func (rs SchemaReader) TenantsShards(class string, tenants ...string) (map[string]string, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("TenantsShards")) |
| defer t.ObserveDuration() |
|
|
| return rs.TenantsShardsWithVersion(context.TODO(), 0, class, tenants...) |
| } |
|
|
| func (rs SchemaReader) GetShardsStatus(class, tenant string) (models.ShardStatusList, error) { |
| t := prometheus.NewTimer(monitoring.GetMetrics().SchemaReadsLocal.WithLabelValues("GetShardsStatus")) |
| defer t.ObserveDuration() |
|
|
| return rs.schema.GetShardsStatus(class, tenant) |
| } |
|
|
| func (rs SchemaReader) Len() int { return rs.schema.len() } |
|
|
| func (rs SchemaReader) retry(f func(*schema) error) error { |
| return backoff.Retry(func() error { |
| return f(rs.schema) |
| }, utils.NewBackoff()) |
| } |
|
|