mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
fix: hit meta cache for collection aliases (#49513)
related: https://github.com/milvus-io/milvus/issues/49510 Signed-off-by: shaoting-huang <shaoting.huang@zilliz.com>
This commit is contained in:
@@ -432,6 +432,14 @@ func (m *MetaCache) getCollection(database, collectionName string, collectionID
|
||||
if collection, ok := db[collectionName]; ok {
|
||||
return collection, collection.isCollectionCached()
|
||||
}
|
||||
// update() stores alias requests under the real collection name.
|
||||
if aliasDB, ok := m.aliasInfo[database]; ok {
|
||||
if entry, ok := aliasDB[collectionName]; ok && entry.collectionName != "" {
|
||||
if collection, ok := db[entry.collectionName]; ok {
|
||||
return collection, collection.isCollectionCached()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false
|
||||
|
||||
@@ -94,7 +94,7 @@ func (m *MockMixCoordClientInterface) ShowPartitions(ctx context.Context, in *mi
|
||||
if m.Error {
|
||||
return nil, errors.New("mocked error")
|
||||
}
|
||||
if in.CollectionName == "collection1" || in.CollectionID == 1 {
|
||||
if in.CollectionName == "collection1" || in.CollectionName == "collection1_alias" || in.CollectionID == 1 {
|
||||
return &milvuspb.ShowPartitionsResponse{
|
||||
Status: merr.Success(),
|
||||
PartitionIDs: []typeutil.UniqueID{1, 2},
|
||||
@@ -137,7 +137,7 @@ func (m *MockMixCoordClientInterface) DescribeCollection(ctx context.Context, in
|
||||
return nil, errors.New("mocked error")
|
||||
}
|
||||
m.IncAccessCount()
|
||||
if in.CollectionName == "collection1" || in.CollectionID == 1 {
|
||||
if in.CollectionName == "collection1" || in.CollectionName == "collection1_alias" || in.CollectionID == 1 {
|
||||
return &milvuspb.DescribeCollectionResponse{
|
||||
Status: merr.Success(),
|
||||
CollectionID: typeutil.UniqueID(1),
|
||||
@@ -1016,6 +1016,36 @@ func TestMetaCache_GetCollection(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestMetaCache_GetCollectionByAliasHitsCache(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rootCoord := &MockMixCoordClientInterface{}
|
||||
|
||||
err := InitMetaCache(ctx, rootCoord)
|
||||
assert.NoError(t, err)
|
||||
|
||||
id, err := globalMetaCache.GetCollectionID(ctx, dbName, "collection1_alias")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, typeutil.UniqueID(1), id)
|
||||
assert.Equal(t, 1, rootCoord.GetAccessCount())
|
||||
|
||||
schema, err := globalMetaCache.GetCollectionSchema(ctx, dbName, "collection1_alias")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "collection1", schema.GetName())
|
||||
assert.Equal(t, 1, rootCoord.GetAccessCount())
|
||||
|
||||
info, err := globalMetaCache.GetCollectionInfo(ctx, dbName, "collection1_alias", 0)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, typeutil.UniqueID(1), info.collID)
|
||||
assert.Equal(t, 1, rootCoord.GetAccessCount())
|
||||
|
||||
metaCache := globalMetaCache.(*MetaCache)
|
||||
metaCache.mu.RLock()
|
||||
defer metaCache.mu.RUnlock()
|
||||
_, aliasCachedAsCollection := metaCache.collInfo[dbName]["collection1_alias"]
|
||||
assert.False(t, aliasCachedAsCollection)
|
||||
assert.Equal(t, "collection1", metaCache.aliasInfo[dbName]["collection1_alias"].collectionName)
|
||||
}
|
||||
|
||||
func TestMetaCache_GetBasicCollectionInfo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rootCoord := &MockMixCoordClientInterface{}
|
||||
|
||||
Reference in New Issue
Block a user