From 007fab183c02aa2688f65a78a3c5c441fb0b5d00 Mon Sep 17 00:00:00 2001 From: congqixia Date: Wed, 6 Mar 2024 19:33:00 +0800 Subject: [PATCH] enhance: Skip partition key name check if feature not enabled (#31067) Skip partition key naming & hash value pre process if collection schema does not have partition key The PR removes mislead warning when collection has no partition key Signed-off-by: Congqi Xia --- internal/proxy/meta_cache.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/proxy/meta_cache.go b/internal/proxy/meta_cache.go index 6bab9dbfee..f4bae21eb8 100644 --- a/internal/proxy/meta_cache.go +++ b/internal/proxy/meta_cache.go @@ -370,10 +370,11 @@ func (m *MetaCache) update(ctx context.Context, database, collectionName string, m.collInfo[database] = make(map[string]*collectionInfo) } + schemaInfo := newSchemaInfo(collection.Schema) m.collInfo[database][collectionName] = &collectionInfo{ collID: collection.CollectionID, - schema: newSchemaInfo(collection.Schema), - partInfo: parsePartitionsInfo(infos), + schema: schemaInfo, + partInfo: parsePartitionsInfo(infos, schemaInfo.hasPartitionKeyField), createdTimestamp: collection.CreatedTimestamp, createdUtcTimestamp: collection.CreatedUtcTimestamp, consistencyLevel: collection.ConsistencyLevel, @@ -653,7 +654,7 @@ func (m *MetaCache) showPartitions(ctx context.Context, dbName string, collectio // parsePartitionsInfo parse partitionInfo list to partitionInfos struct. // prepare all name to id & info map // try parse partition names to partitionKey index. -func parsePartitionsInfo(infos []*partitionInfo) *partitionInfos { +func parsePartitionsInfo(infos []*partitionInfo, hasPartitionKey bool) *partitionInfos { name2ID := lo.SliceToMap(infos, func(info *partitionInfo) (string, int64) { return info.name, info.partitionID }) @@ -667,6 +668,10 @@ func parsePartitionsInfo(infos []*partitionInfo) *partitionInfos { name2Info: name2Info, } + if !hasPartitionKey { + return result + } + // Make sure the order of the partition names got every time is the same partitionNames := make([]string, len(infos)) for _, info := range infos { @@ -717,10 +722,11 @@ func (m *MetaCache) RemovePartition(ctx context.Context, database, collectionNam defer m.mu.Unlock() var ok bool + var collInfo *collectionInfo db, dbOk := m.collInfo[database] if dbOk { - _, ok = db[collectionName] + collInfo, ok = db[collectionName] } if !ok { @@ -735,7 +741,7 @@ func (m *MetaCache) RemovePartition(ctx context.Context, database, collectionNam return info.name != partitionName }) - m.collInfo[database][collectionName].partInfo = parsePartitionsInfo(filteredInfos) + m.collInfo[database][collectionName].partInfo = parsePartitionsInfo(filteredInfos, collInfo.schema.hasPartitionKeyField) } // GetCredentialInfo returns the credential related to provided username