From bdfb78e936667bb10142099f92c5153dede1c1dc Mon Sep 17 00:00:00 2001 From: Yusup Date: Wed, 22 Sep 2021 08:20:48 +0000 Subject: [PATCH] Add aliases to DescribeCollection (#8268) Signed-off-by: Yusup --- internal/rootcoord/meta_table.go | 12 +++++++ internal/rootcoord/meta_table_test.go | 2 ++ internal/rootcoord/root_coord_test.go | 47 ++++++++++++++++++--------- internal/rootcoord/task.go | 2 +- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/internal/rootcoord/meta_table.go b/internal/rootcoord/meta_table.go index 973e4fd01f..5eac69fc00 100644 --- a/internal/rootcoord/meta_table.go +++ b/internal/rootcoord/meta_table.go @@ -464,6 +464,18 @@ func (mt *metaTable) ListCollections(ts typeutil.Timestamp) (map[string]*pb.Coll return colls, nil } +func (mt *metaTable) ListAliases(collID typeutil.UniqueID) []string { + mt.ddLock.RLock() + defer mt.ddLock.RUnlock() + var aliases []string + for alias, cid := range mt.collAlias2ID { + if cid == collID { + aliases = append(aliases, alias) + } + } + return aliases +} + // ListCollectionVirtualChannels list virtual channel of all the collection func (mt *metaTable) ListCollectionVirtualChannels() []string { mt.ddLock.RLock() diff --git a/internal/rootcoord/meta_table_test.go b/internal/rootcoord/meta_table_test.go index 5533958e27..8c3a8b1299 100644 --- a/internal/rootcoord/meta_table_test.go +++ b/internal/rootcoord/meta_table_test.go @@ -275,6 +275,8 @@ func TestMetaTable(t *testing.T) { ts := ftso() err = mt.AddAlias("alias1", "testColl", ts, ddOp) assert.Nil(t, err) + aliases := mt.ListAliases(collID) + assert.Equal(t, aliases, []string{"alias1"}) }) t.Run("alter alias", func(t *testing.T) { diff --git a/internal/rootcoord/root_coord_test.go b/internal/rootcoord/root_coord_test.go index ee162d0f38..56b2982ad4 100644 --- a/internal/rootcoord/root_coord_test.go +++ b/internal/rootcoord/root_coord_test.go @@ -1813,6 +1813,23 @@ func TestRootCoord(t *testing.T) { assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode) }) + t.Run("describe collection2", func(t *testing.T) { + req := &milvuspb.DescribeCollectionRequest{ + Base: &commonpb.MsgBase{ + MsgType: commonpb.MsgType_DescribeCollection, + MsgID: 3013, + Timestamp: 3013, + SourceID: 3013, + }, + DbName: dbName, + CollectionName: collName, + } + rsp, err := core.DescribeCollection(ctx, req) + assert.Nil(t, err) + assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode) + assert.Equal(t, rsp.Aliases, []string{aliasName}) + }) + // temporarily create collName2 schema = schemapb.CollectionSchema{ Name: collName2, @@ -1822,9 +1839,9 @@ func TestRootCoord(t *testing.T) { req2 := &milvuspb.CreateCollectionRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_CreateCollection, - MsgID: 3013, - Timestamp: 3013, - SourceID: 3013, + MsgID: 3014, + Timestamp: 3014, + SourceID: 3014, }, DbName: dbName, CollectionName: collName2, @@ -1838,9 +1855,9 @@ func TestRootCoord(t *testing.T) { req := &milvuspb.AlterAliasRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_AlterAlias, - MsgID: 3014, - Timestamp: 3014, - SourceID: 3014, + MsgID: 3015, + Timestamp: 3015, + SourceID: 3015, }, CollectionName: collName2, Alias: aliasName, @@ -1854,9 +1871,9 @@ func TestRootCoord(t *testing.T) { req := &milvuspb.DropAliasRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_DropAlias, - MsgID: 3015, - Timestamp: 3015, - SourceID: 3015, + MsgID: 3016, + Timestamp: 3016, + SourceID: 3016, }, Alias: aliasName, } @@ -1868,9 +1885,9 @@ func TestRootCoord(t *testing.T) { status, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_DropCollection, - MsgID: 3016, - Timestamp: 3016, - SourceID: 3016, + MsgID: 3017, + Timestamp: 3017, + SourceID: 3017, }, DbName: dbName, CollectionName: collName, @@ -1881,9 +1898,9 @@ func TestRootCoord(t *testing.T) { status, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{ Base: &commonpb.MsgBase{ MsgType: commonpb.MsgType_DropCollection, - MsgID: 3017, - Timestamp: 3017, - SourceID: 3017, + MsgID: 3018, + Timestamp: 3018, + SourceID: 3018, }, DbName: dbName, CollectionName: collName2, diff --git a/internal/rootcoord/task.go b/internal/rootcoord/task.go index 131490fea2..f577cab9e2 100644 --- a/internal/rootcoord/task.go +++ b/internal/rootcoord/task.go @@ -384,7 +384,7 @@ func (t *DescribeCollectionReqTask) Execute(ctx context.Context) error { t.Rsp.CreatedTimestamp = collInfo.CreateTime createdPhysicalTime, _ := tsoutil.ParseHybridTs(collInfo.CreateTime) t.Rsp.CreatedUtcTimestamp = createdPhysicalTime - + t.Rsp.Aliases = t.core.MetaTable.ListAliases(collInfo.ID) return nil }