mirror of https://github.com/milvus-io/milvus.git
fix: Add index param duplication check (#39289)
Related to #39288 Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>pull/38403/head
parent
eb63334312
commit
82bdf9a6a8
|
@ -282,6 +282,15 @@ func (s *Server) CreateIndex(ctx context.Context, req *indexpb.CreateIndexReques
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateIndexParams(index *model.Index) error {
|
func ValidateIndexParams(index *model.Index) error {
|
||||||
|
if err := CheckDuplidateKey(index.IndexParams, "indexParams"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := CheckDuplidateKey(index.UserIndexParams, "userIndexParams"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := CheckDuplidateKey(index.TypeParams, "typeParams"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
indexType := GetIndexType(index.IndexParams)
|
indexType := GetIndexType(index.IndexParams)
|
||||||
indexParams := funcutil.KeyValuePair2Map(index.IndexParams)
|
indexParams := funcutil.KeyValuePair2Map(index.IndexParams)
|
||||||
userIndexParams := funcutil.KeyValuePair2Map(index.UserIndexParams)
|
userIndexParams := funcutil.KeyValuePair2Map(index.UserIndexParams)
|
||||||
|
@ -300,6 +309,17 @@ func ValidateIndexParams(index *model.Index) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckDuplidateKey(kvs []*commonpb.KeyValuePair, tag string) error {
|
||||||
|
keySet := typeutil.NewSet[string]()
|
||||||
|
for _, kv := range kvs {
|
||||||
|
if keySet.Contain(kv.GetKey()) {
|
||||||
|
return merr.WrapErrParameterInvalidMsg("duplicate %s key in %s params", kv.GetKey(), tag)
|
||||||
|
}
|
||||||
|
keySet.Insert(kv.GetKey())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateParams(index *model.Index, from []*commonpb.KeyValuePair, updates []*commonpb.KeyValuePair) []*commonpb.KeyValuePair {
|
func UpdateParams(index *model.Index, from []*commonpb.KeyValuePair, updates []*commonpb.KeyValuePair) []*commonpb.KeyValuePair {
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
for _, param := range from {
|
for _, param := range from {
|
||||||
|
|
|
@ -2510,4 +2510,55 @@ func TestValidateIndexParams(t *testing.T) {
|
||||||
err := ValidateIndexParams(index)
|
err := ValidateIndexParams(index)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("duplicated_index_params", func(t *testing.T) {
|
||||||
|
index := &model.Index{
|
||||||
|
IndexParams: []*commonpb.KeyValuePair{
|
||||||
|
{
|
||||||
|
Key: common.IndexTypeKey,
|
||||||
|
Value: indexparamcheck.AutoIndex,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: common.IndexTypeKey,
|
||||||
|
Value: indexparamcheck.AutoIndex,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := ValidateIndexParams(index)
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("duplicated_user_index_params", func(t *testing.T) {
|
||||||
|
index := &model.Index{
|
||||||
|
UserIndexParams: []*commonpb.KeyValuePair{
|
||||||
|
{
|
||||||
|
Key: common.IndexTypeKey,
|
||||||
|
Value: indexparamcheck.AutoIndex,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: common.IndexTypeKey,
|
||||||
|
Value: indexparamcheck.AutoIndex,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := ValidateIndexParams(index)
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("duplicated_user_index_params", func(t *testing.T) {
|
||||||
|
index := &model.Index{
|
||||||
|
TypeParams: []*commonpb.KeyValuePair{
|
||||||
|
{
|
||||||
|
Key: common.IndexTypeKey,
|
||||||
|
Value: indexparamcheck.AutoIndex,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: common.IndexTypeKey,
|
||||||
|
Value: indexparamcheck.AutoIndex,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := ValidateIndexParams(index)
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue