fix: check PreCreatedTopic first in shard number validation (#41274)

issue : https://github.com/milvus-io/milvus/issues/41271

Signed-off-by: Xiaowei Shi <shallwe.shih@gmail.com>
pull/41358/head
Xiaowei Shi 2025-04-16 17:38:34 +08:00 committed by GitHub
parent e46e3a1708
commit a6606ce9c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -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)
}

View File

@ -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},