mirror of https://github.com/milvus-io/milvus.git
fix alter collection merge multi props policy (#24147)
Signed-off-by: Wei Liu <wei.liu@zilliz.com>pull/24151/head
parent
eb9ef23cca
commit
2935e9f767
|
@ -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",
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue