From 2935e9f7672dafedee973893d56875edb8a655a2 Mon Sep 17 00:00:00 2001 From: wei liu Date: Wed, 17 May 2023 16:05:22 +0800 Subject: [PATCH] fix alter collection merge multi props policy (#24147) Signed-off-by: Wei Liu --- internal/rootcoord/alter_collection_task.go | 26 +++++++++- .../rootcoord/alter_collection_task_test.go | 48 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/internal/rootcoord/alter_collection_task.go b/internal/rootcoord/alter_collection_task.go index ae5d7e4d3..7c3d7fb7f 100644 --- a/internal/rootcoord/alter_collection_task.go +++ b/internal/rootcoord/alter_collection_task.go @@ -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 +} diff --git a/internal/rootcoord/alter_collection_task_test.go b/internal/rootcoord/alter_collection_task_test.go index 0a82d4f9a..19f280e0f 100644 --- a/internal/rootcoord/alter_collection_task_test.go +++ b/internal/rootcoord/alter_collection_task_test.go @@ -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", + }) + + }) } -- GitLab