未验证 提交 2935e9f7 编写于 作者: W wei liu 提交者: GitHub

fix alter collection merge multi props policy (#24147)

Signed-off-by: NWei Liu <wei.liu@zilliz.com>
上级 eb9ef23c
......@@ -22,9 +22,11 @@ import (
"github.com/cockroachdb/errors"
"github.com/milvus-io/milvus/internal/metastore/model"
"github.com/milvus-io/milvus/pkg/log"
"go.uber.org/zap"
"github.com/milvus-io/milvus-proto/go-api/commonpb"
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
)
......@@ -55,7 +57,7 @@ func (a *alterCollectionTask) Execute(ctx context.Context) error {
}
newColl := oldColl.Clone()
newColl.Properties = a.Req.GetProperties()
updateCollectionProperties(newColl, a.Req.GetProperties())
ts := a.GetTs()
redoTask := newBaseRedoTask(a.core.stepExecutor)
......@@ -82,3 +84,25 @@ func (a *alterCollectionTask) Execute(ctx context.Context) error {
return redoTask.Execute(ctx)
}
func updateCollectionProperties(coll *model.Collection, updatedProps []*commonpb.KeyValuePair) {
props := make(map[string]string)
for _, prop := range coll.Properties {
props[prop.Key] = prop.Value
}
for _, prop := range updatedProps {
props[prop.Key] = prop.Value
}
propKV := make([]*commonpb.KeyValuePair, 0)
for key, value := range props {
propKV = append(propKV, &commonpb.KeyValuePair{
Key: key,
Value: value,
})
}
coll.Properties = propKV
}
......@@ -157,4 +157,52 @@ func Test_alterCollectionTask_Execute(t *testing.T) {
err := task.Execute(context.Background())
assert.NoError(t, err)
})
t.Run("test update collection props", func(t *testing.T) {
coll := &model.Collection{
Properties: []*commonpb.KeyValuePair{
{
Key: common.CollectionTTLConfigKey,
Value: "1",
},
},
}
updateProps1 := []*commonpb.KeyValuePair{
{
Key: common.CollectionAutoCompactionKey,
Value: "true",
},
}
updateCollectionProperties(coll, updateProps1)
assert.Contains(t, coll.Properties, &commonpb.KeyValuePair{
Key: common.CollectionTTLConfigKey,
Value: "1",
})
assert.Contains(t, coll.Properties, &commonpb.KeyValuePair{
Key: common.CollectionAutoCompactionKey,
Value: "true",
})
updateProps2 := []*commonpb.KeyValuePair{
{
Key: common.CollectionTTLConfigKey,
Value: "2",
},
}
updateCollectionProperties(coll, updateProps2)
assert.Contains(t, coll.Properties, &commonpb.KeyValuePair{
Key: common.CollectionTTLConfigKey,
Value: "2",
})
assert.Contains(t, coll.Properties, &commonpb.KeyValuePair{
Key: common.CollectionAutoCompactionKey,
Value: "true",
})
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册