| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| package replication |
|
|
| import ( |
| "errors" |
| "fmt" |
|
|
| "github.com/weaviate/weaviate/cluster/proto/api" |
| "github.com/weaviate/weaviate/cluster/schema" |
| ) |
|
|
| var ( |
| ErrAlreadyExists = errors.New("already exists") |
| ErrNodeNotFound = errors.New("node not found") |
| ErrClassNotFound = errors.New("class not found") |
| ErrShardNotFound = errors.New("shard not found") |
| ) |
|
|
| |
| func ValidateReplicationReplicateShard(schemaReader schema.SchemaReader, c *api.ReplicationReplicateShardRequest) error { |
| if c.Uuid == "" { |
| return fmt.Errorf("uuid is required: %w", ErrBadRequest) |
| } |
| if c.SourceNode == c.TargetNode { |
| return fmt.Errorf("source and target node are the same: %w", ErrBadRequest) |
| } |
|
|
| classInfo := schemaReader.ClassInfo(c.SourceCollection) |
| |
| |
| if !classInfo.Exists { |
| return fmt.Errorf("collection %s does not exists: %w", c.SourceCollection, ErrClassNotFound) |
| } |
|
|
| |
| nodes, err := schemaReader.ShardReplicas(c.SourceCollection, c.SourceShard) |
| if err != nil { |
| return err |
| } |
| var foundSource bool |
| var foundTarget bool |
| for _, n := range nodes { |
| if n == c.SourceNode { |
| foundSource = true |
| } |
| if n == c.TargetNode { |
| foundTarget = true |
| } |
| } |
| if !foundSource { |
| return fmt.Errorf("could not find shard %s for collection %s on source node %s: %w", c.SourceShard, c.SourceCollection, c.SourceNode, ErrNodeNotFound) |
| } |
| if foundTarget { |
| return fmt.Errorf("shard %s already exist for collection %s on target node %s: %w", c.SourceShard, c.SourceCollection, c.SourceNode, ErrAlreadyExists) |
| } |
| return nil |
| } |
|
|