diff --git a/internal/proxy/meta_cache.go b/internal/proxy/meta_cache.go index bd8b20e0f895f..7a5dea1fd047d 100644 --- a/internal/proxy/meta_cache.go +++ b/internal/proxy/meta_cache.go @@ -496,8 +496,10 @@ func (m *MetaCache) update(ctx context.Context, database, collectionName string, partitionKeyIsolation: isolation, } - log.Info("meta update success", zap.String("database", database), zap.String("collectionName", collectionName), - zap.String("actual collection Name", collection.Schema.GetName()), zap.Int64("collectionID", collection.CollectionID)) + log.Ctx(ctx).Info("meta update success", zap.String("database", database), zap.String("collectionName", collectionName), + zap.String("actual collection Name", collection.Schema.GetName()), zap.Int64("collectionID", collection.CollectionID), + zap.Strings("partition", partitions.PartitionNames), + ) return m.collInfo[database][collectionName], nil } diff --git a/internal/rootcoord/alter_collection_task.go b/internal/rootcoord/alter_collection_task.go index 9d7381c7f5668..9a7bdd9ea04b5 100644 --- a/internal/rootcoord/alter_collection_task.go +++ b/internal/rootcoord/alter_collection_task.go @@ -126,10 +126,10 @@ func (a *alterCollectionTask) Execute(ctx context.Context) error { } func (a *alterCollectionTask) GetLockerKey() LockerKey { - collectionName := a.core.getRealCollectionName(a.ctx, a.Req.GetDbName(), a.Req.GetCollectionName()) + collection := a.core.getCollectionIDStr(a.ctx, a.Req.GetDbName(), a.Req.GetCollectionName(), a.Req.GetCollectionID()) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(a.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, true), + NewCollectionLockerKey(collection, true), ) } diff --git a/internal/rootcoord/create_partition_task.go b/internal/rootcoord/create_partition_task.go index 5a97449e54ac1..875ede9f3caa1 100644 --- a/internal/rootcoord/create_partition_task.go +++ b/internal/rootcoord/create_partition_task.go @@ -120,10 +120,10 @@ func (t *createPartitionTask) Execute(ctx context.Context) error { } func (t *createPartitionTask) GetLockerKey() LockerKey { - collectionName := t.core.getRealCollectionName(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName()) + collection := t.core.getCollectionIDStr(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName(), 0) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(t.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, true), + NewCollectionLockerKey(collection, true), ) } diff --git a/internal/rootcoord/describe_collection_task.go b/internal/rootcoord/describe_collection_task.go index cc49a6cef5b88..6a1ad02181a5c 100644 --- a/internal/rootcoord/describe_collection_task.go +++ b/internal/rootcoord/describe_collection_task.go @@ -55,10 +55,10 @@ func (t *describeCollectionTask) Execute(ctx context.Context) (err error) { } func (t *describeCollectionTask) GetLockerKey() LockerKey { - collectionName := t.core.getRealCollectionName(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName()) + collection := t.core.getCollectionIDStr(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName(), t.Req.GetCollectionID()) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(t.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, false), + NewCollectionLockerKey(collection, false), ) } diff --git a/internal/rootcoord/drop_alias_task.go b/internal/rootcoord/drop_alias_task.go index 4f9fcbfe644a9..f29026edd23e7 100644 --- a/internal/rootcoord/drop_alias_task.go +++ b/internal/rootcoord/drop_alias_task.go @@ -45,10 +45,10 @@ func (t *dropAliasTask) Execute(ctx context.Context) error { } func (t *dropAliasTask) GetLockerKey() LockerKey { - collectionName := t.core.getRealCollectionName(t.ctx, t.Req.GetDbName(), t.Req.GetAlias()) + collection := t.core.getCollectionIDStr(t.ctx, t.Req.GetDbName(), t.Req.GetAlias(), 0) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(t.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, true), + NewCollectionLockerKey(collection, true), ) } diff --git a/internal/rootcoord/drop_partition_task.go b/internal/rootcoord/drop_partition_task.go index bafdb347329be..0fa4f43da41f6 100644 --- a/internal/rootcoord/drop_partition_task.go +++ b/internal/rootcoord/drop_partition_task.go @@ -112,10 +112,10 @@ func (t *dropPartitionTask) Execute(ctx context.Context) error { } func (t *dropPartitionTask) GetLockerKey() LockerKey { - collectionName := t.core.getRealCollectionName(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName()) + collection := t.core.getCollectionIDStr(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName(), 0) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(t.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, true), + NewCollectionLockerKey(collection, true), ) } diff --git a/internal/rootcoord/has_partition_task.go b/internal/rootcoord/has_partition_task.go index 1e9f32da740b4..c4e1b47b603c9 100644 --- a/internal/rootcoord/has_partition_task.go +++ b/internal/rootcoord/has_partition_task.go @@ -59,10 +59,10 @@ func (t *hasPartitionTask) Execute(ctx context.Context) error { } func (t *hasPartitionTask) GetLockerKey() LockerKey { - collectionName := t.core.getRealCollectionName(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName()) + collection := t.core.getCollectionIDStr(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName(), 0) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(t.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, false), + NewCollectionLockerKey(collection, false), ) } diff --git a/internal/rootcoord/root_coord.go b/internal/rootcoord/root_coord.go index 90ff6fd7007e1..798eb1b2ec38a 100644 --- a/internal/rootcoord/root_coord.go +++ b/internal/rootcoord/root_coord.go @@ -21,6 +21,7 @@ import ( "fmt" "math/rand" "os" + "strconv" "strings" "sync" "time" @@ -1150,13 +1151,19 @@ func (c *Core) HasCollection(ctx context.Context, in *milvuspb.HasCollectionRequ return t.Rsp, nil } -// getRealCollectionName get origin collection name to avoid the alias name -func (c *Core) getRealCollectionName(ctx context.Context, db, collection string) string { - realName, err := c.meta.DescribeAlias(ctx, db, collection, 0) +// getCollectionIDStr get collectionID string to avoid the alias name +func (c *Core) getCollectionIDStr(ctx context.Context, db, collectionName string, collectionID int64) string { + // When neither the collection name nor the collectionID exists, no error is returned at this point. + // An error will be returned during the execution phase. + if collectionID != 0 { + return strconv.FormatInt(collectionID, 10) + } + + coll, err := c.meta.GetCollectionByName(ctx, db, collectionName, typeutil.MaxTimestamp) if err != nil { - return collection + return "-1" } - return realName + return strconv.FormatInt(coll.CollectionID, 10) } func (c *Core) describeCollection(ctx context.Context, in *milvuspb.DescribeCollectionRequest, allowUnavailable bool) (*model.Collection, error) { diff --git a/internal/rootcoord/show_partition_task.go b/internal/rootcoord/show_partition_task.go index f023c60f60016..51ca382cd6afb 100644 --- a/internal/rootcoord/show_partition_task.go +++ b/internal/rootcoord/show_partition_task.go @@ -69,10 +69,10 @@ func (t *showPartitionTask) Execute(ctx context.Context) error { } func (t *showPartitionTask) GetLockerKey() LockerKey { - collectionName := t.core.getRealCollectionName(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName()) + collection := t.core.getCollectionIDStr(t.ctx, t.Req.GetDbName(), t.Req.GetCollectionName(), t.Req.GetCollectionID()) return NewLockerKeyChain( NewClusterLockerKey(false), NewDatabaseLockerKey(t.Req.GetDbName(), false), - NewCollectionLockerKey(collectionName, false), + NewCollectionLockerKey(collection, false), ) } diff --git a/internal/rootcoord/task_test.go b/internal/rootcoord/task_test.go index cf03907d3dcfe..f2ee5d1bbe5c6 100644 --- a/internal/rootcoord/task_test.go +++ b/internal/rootcoord/task_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" + "github.com/milvus-io/milvus/internal/metastore/model" "github.com/milvus-io/milvus/internal/proto/rootcoordpb" mockrootcoord "github.com/milvus-io/milvus/internal/rootcoord/mocks" ) @@ -94,9 +95,12 @@ func TestGetLockerKey(t *testing.T) { }) t.Run("alter collection task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return s2, nil + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return &model.Collection{ + Name: s2, + CollectionID: 111, + }, nil }) c := &Core{ meta: metaMock, @@ -111,7 +115,25 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|bar-2-true") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-true") + }) + t.Run("alter collection task locker key by ID", func(t *testing.T) { + metaMock := mockrootcoord.NewIMetaTable(t) + c := &Core{ + meta: metaMock, + } + tt := &alterCollectionTask{ + baseTask: baseTask{ + core: c, + }, + Req: &milvuspb.AlterCollectionRequest{ + DbName: "foo", + CollectionName: "", + CollectionID: 111, + }, + } + key := tt.GetLockerKey() + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-true") }) t.Run("alter database task locker key", func(t *testing.T) { tt := &alterDatabaseTask{ @@ -160,9 +182,12 @@ func TestGetLockerKey(t *testing.T) { }) t.Run("create partition task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return "real" + s2, nil + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return &model.Collection{ + Name: "real" + s2, + CollectionID: 111, + }, nil }) c := &Core{ meta: metaMock, @@ -176,13 +201,13 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|realbar-2-true") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-true") }) t.Run("describe collection task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return "", errors.New("not found") + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return nil, errors.New("not found") }) c := &Core{ meta: metaMock, @@ -195,7 +220,23 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|bar-2-false") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|-1-2-false") + }) + t.Run("describe collection task locker key by ID", func(t *testing.T) { + metaMock := mockrootcoord.NewIMetaTable(t) + c := &Core{ + meta: metaMock, + } + tt := &describeCollectionTask{ + baseTask: baseTask{core: c}, + Req: &milvuspb.DescribeCollectionRequest{ + DbName: "foo", + CollectionName: "", + CollectionID: 111, + }, + } + key := tt.GetLockerKey() + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-false") }) t.Run("describe database task locker key", func(t *testing.T) { tt := &describeDBTask{ @@ -208,9 +249,12 @@ func TestGetLockerKey(t *testing.T) { }) t.Run("drop alias task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return "real" + s2, nil + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return &model.Collection{ + Name: "real" + s2, + CollectionID: 111, + }, nil }) c := &Core{ meta: metaMock, @@ -223,7 +267,7 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|realbar-2-true") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-true") }) t.Run("drop collection task locker key", func(t *testing.T) { tt := &dropCollectionTask{ @@ -246,9 +290,12 @@ func TestGetLockerKey(t *testing.T) { }) t.Run("drop partition task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return "real" + s2, nil + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return &model.Collection{ + Name: "real" + s2, + CollectionID: 111, + }, nil }) c := &Core{ meta: metaMock, @@ -262,7 +309,7 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|realbar-2-true") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-true") }) t.Run("has collection task locker key", func(t *testing.T) { tt := &hasCollectionTask{ @@ -276,9 +323,12 @@ func TestGetLockerKey(t *testing.T) { }) t.Run("has partition task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return "real" + s2, nil + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return &model.Collection{ + Name: "real" + s2, + CollectionID: 111, + }, nil }) c := &Core{ meta: metaMock, @@ -292,7 +342,7 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|realbar-2-false") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-false") }) t.Run("list db task locker key", func(t *testing.T) { tt := &listDatabaseTask{} @@ -321,9 +371,12 @@ func TestGetLockerKey(t *testing.T) { }) t.Run("show partition task locker key", func(t *testing.T) { metaMock := mockrootcoord.NewIMetaTable(t) - metaMock.EXPECT().DescribeAlias(mock.Anything, mock.Anything, mock.Anything, mock.Anything). - RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (string, error) { - return "real" + s2, nil + metaMock.EXPECT().GetCollectionByName(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, s string, s2 string, u uint64) (*model.Collection, error) { + return &model.Collection{ + Name: "real" + s2, + CollectionID: 111, + }, nil }) c := &Core{ meta: metaMock, @@ -336,6 +389,22 @@ func TestGetLockerKey(t *testing.T) { }, } key := tt.GetLockerKey() - assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|realbar-2-false") + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-false") + }) + t.Run("show partition task locker key by ID", func(t *testing.T) { + metaMock := mockrootcoord.NewIMetaTable(t) + c := &Core{ + meta: metaMock, + } + tt := &showPartitionTask{ + baseTask: baseTask{core: c}, + Req: &milvuspb.ShowPartitionsRequest{ + DbName: "foo", + CollectionName: "", + CollectionID: 111, + }, + } + key := tt.GetLockerKey() + assert.Equal(t, GetLockerKeyString(key), "$-0-false|foo-1-false|111-2-false") }) }