From 1c8f14eda4de0b79781c98931eeb5ab22f006ff7 Mon Sep 17 00:00:00 2001 From: jaime Date: Tue, 26 Nov 2024 16:10:36 +0800 Subject: [PATCH] enhance: the actual number of databases should equal the config value (#38009) pr: #38006 Signed-off-by: jaime --- internal/rootcoord/create_db_task.go | 2 +- internal/rootcoord/create_db_task_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/rootcoord/create_db_task.go b/internal/rootcoord/create_db_task.go index 35f1b67ddcf50..5db6dbeef3f9d 100644 --- a/internal/rootcoord/create_db_task.go +++ b/internal/rootcoord/create_db_task.go @@ -38,7 +38,7 @@ func (t *createDatabaseTask) Prepare(ctx context.Context) error { } cfgMaxDatabaseNum := Params.RootCoordCfg.MaxDatabaseNum.GetAsInt() - if len(dbs) > cfgMaxDatabaseNum { + if len(dbs) >= cfgMaxDatabaseNum { return merr.WrapErrDatabaseNumLimitExceeded(cfgMaxDatabaseNum) } diff --git a/internal/rootcoord/create_db_task_test.go b/internal/rootcoord/create_db_task_test.go index 06b61af593472..09fb9c5a2397c 100644 --- a/internal/rootcoord/create_db_task_test.go +++ b/internal/rootcoord/create_db_task_test.go @@ -28,6 +28,7 @@ import ( "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" "github.com/milvus-io/milvus/internal/metastore/model" mockrootcoord "github.com/milvus-io/milvus/internal/rootcoord/mocks" + "github.com/milvus-io/milvus/pkg/util/merr" "github.com/milvus-io/milvus/pkg/util/paramtable" ) @@ -51,9 +52,8 @@ func Test_CreateDBTask_Prepare(t *testing.T) { t.Run("check database number fail", func(t *testing.T) { meta := mockrootcoord.NewIMetaTable(t) cfgMaxDatabaseNum := Params.RootCoordCfg.MaxDatabaseNum.GetAsInt() - len := cfgMaxDatabaseNum + 1 - dbs := make([]*model.Database, 0, len) - for i := 0; i < len; i++ { + dbs := make([]*model.Database, 0, cfgMaxDatabaseNum) + for i := 0; i < cfgMaxDatabaseNum; i++ { dbs = append(dbs, model.NewDefaultDatabase()) } meta.On("ListDatabases", @@ -73,7 +73,7 @@ func Test_CreateDBTask_Prepare(t *testing.T) { }, } err := task.Prepare(context.Background()) - assert.Error(t, err) + assert.ErrorIs(t, err, merr.ErrDatabaseNumLimitExceeded) }) t.Run("ok", func(t *testing.T) {