fix: [2.5] Add duplication param check for create index (#40254) (#40330)

Cherry-pick from master
pr: #40254 
Related to #40156

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/40359/head
congqixia 2025-03-05 10:10:01 +08:00 committed by GitHub
parent 34f2bc0a68
commit cc7d4ce399
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 0 deletions

View File

@ -173,7 +173,12 @@ func (cit *createIndexTask) parseIndexParams(ctx context.Context) error {
isVecIndex := typeutil.IsVectorType(cit.fieldSchema.DataType)
indexParamsMap := make(map[string]string)
keys := typeutil.NewSet[string]()
for _, kv := range cit.req.GetExtraParams() {
if keys.Contain(kv.GetKey()) {
return merr.WrapErrParameterInvalidMsg("duplicated index param (key=%s) (value=%s) found", kv.GetKey(), kv.GetValue())
}
keys.Insert(kv.GetKey())
if kv.Key == common.IndexParamsKey {
params, err := funcutil.JSONToMap(kv.Value)
if err != nil {

View File

@ -1097,6 +1097,40 @@ func Test_parseIndexParams(t *testing.T) {
// Out of range in json: param 'M' (3000) should be in range [2, 2048]
assert.Error(t, err)
})
t.Run("check_duplicated_extraparam", func(t *testing.T) {
cit := &createIndexTask{
Condition: nil,
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: "HNSW",
},
{
Key: common.MetricTypeKey,
Value: metric.L2,
},
{
Key: common.MetricTypeKey,
Value: metric.COSINE,
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldVector",
IsPrimaryKey: false,
DataType: schemapb.DataType_FloatVector,
TypeParams: []*commonpb.KeyValuePair{
{Key: common.DimKey, Value: "768"},
},
},
}
err := cit.parseIndexParams(context.TODO())
assert.Error(t, err)
})
}
func Test_wrapUserIndexParams(t *testing.T) {