From a6606ce9c6864f61644e12d2eb8cc2b79d5f1244 Mon Sep 17 00:00:00 2001 From: Xiaowei Shi <45102896+xiaowshi@users.noreply.github.com> Date: Wed, 16 Apr 2025 17:38:34 +0800 Subject: [PATCH] fix: check PreCreatedTopic first in shard number validation (#41274) issue : https://github.com/milvus-io/milvus/issues/41271 Signed-off-by: Xiaowei Shi --- internal/rootcoord/create_collection_task.go | 7 ++++++- internal/rootcoord/create_collection_task_test.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/rootcoord/create_collection_task.go b/internal/rootcoord/create_collection_task.go index 32daf494fb..0adffde062 100644 --- a/internal/rootcoord/create_collection_task.go +++ b/internal/rootcoord/create_collection_task.go @@ -73,7 +73,12 @@ func (t *createCollectionTask) validate(ctx context.Context) error { // 1. check shard number shardsNum := t.Req.GetShardsNum() - cfgMaxShardNum := Params.RootCoordCfg.DmlChannelNum.GetAsInt32() + var cfgMaxShardNum int32 + if Params.CommonCfg.PreCreatedTopicEnabled.GetAsBool() { + cfgMaxShardNum = int32(len(Params.CommonCfg.TopicNames.GetAsStrings())) + } else { + cfgMaxShardNum = Params.RootCoordCfg.DmlChannelNum.GetAsInt32() + } if shardsNum > cfgMaxShardNum { return fmt.Errorf("shard num (%d) exceeds max configuration (%d)", shardsNum, cfgMaxShardNum) } diff --git a/internal/rootcoord/create_collection_task_test.go b/internal/rootcoord/create_collection_task_test.go index 8b5a1ec25a..046cb23467 100644 --- a/internal/rootcoord/create_collection_task_test.go +++ b/internal/rootcoord/create_collection_task_test.go @@ -99,7 +99,12 @@ func Test_createCollectionTask_validate(t *testing.T) { t.Run("shard num exceeds max configuration", func(t *testing.T) { // TODO: better to have a `Set` method for ParamItem. - cfgMaxShardNum := Params.RootCoordCfg.DmlChannelNum.GetAsInt32() + var cfgMaxShardNum int32 + if Params.CommonCfg.PreCreatedTopicEnabled.GetAsBool() { + cfgMaxShardNum = int32(len(Params.CommonCfg.TopicNames.GetAsStrings())) + } else { + cfgMaxShardNum = Params.RootCoordCfg.DmlChannelNum.GetAsInt32() + } task := createCollectionTask{ Req: &milvuspb.CreateCollectionRequest{ Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_CreateCollection},