From 2531ebda270d0da8030b05f84b09f02b742cb59d Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 3 Jul 2025 14:32:45 +0800 Subject: [PATCH] fix: [2.5] Check field mmap property before apply collection level one (#43091) Cherry-pick from master pr: #43090 Related to #43089 --------- Signed-off-by: Congqi Xia --- internal/querycoordv2/task/executor.go | 1 + internal/querycoordv2/task/utils.go | 36 +++++++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/internal/querycoordv2/task/executor.go b/internal/querycoordv2/task/executor.go index 1c9f3ac52c..1ff9fc62e1 100644 --- a/internal/querycoordv2/task/executor.go +++ b/internal/querycoordv2/task/executor.go @@ -386,6 +386,7 @@ func (ex *Executor) subscribeChannel(task *ChannelTask, step int) error { task, action, collectionInfo.GetSchema(), + collectionInfo.GetProperties(), loadMeta, dmChannel, indexInfo, diff --git a/internal/querycoordv2/task/utils.go b/internal/querycoordv2/task/utils.go index 815a450b65..07bc0139ab 100644 --- a/internal/querycoordv2/task/utils.go +++ b/internal/querycoordv2/task/utils.go @@ -101,7 +101,7 @@ func GetTaskType(task Task) Type { return 0 } -func mergeCollectonProps(schemaProps []*commonpb.KeyValuePair, collectionProps []*commonpb.KeyValuePair) []*commonpb.KeyValuePair { +func mergeCollectionProps(schemaProps []*commonpb.KeyValuePair, collectionProps []*commonpb.KeyValuePair) []*commonpb.KeyValuePair { // Merge the collectionProps and schemaProps maps, giving priority to the values in schemaProps if there are duplicate keys. props := make(map[string]string) for _, p := range collectionProps { @@ -141,18 +141,8 @@ func packLoadSegmentRequest( if task.Source() == utils.LeaderChecker { loadScope = querypb.LoadScope_Delta } - // field mmap enabled if collection-level mmap enabled or the field mmap enabled - collectionMmapEnabled, exist := common.IsMmapDataEnabled(collectionProperties...) - for _, field := range schema.GetFields() { - if exist { - field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{ - Key: common.MmapEnabledKey, - Value: strconv.FormatBool(collectionMmapEnabled), - }) - } - } - schema.Properties = mergeCollectonProps(schema.Properties, collectionProperties) + schema = applyCollectionMmapSetting(schema, collectionProperties) return &querypb.LoadSegmentsRequest{ Base: commonpbutil.NewMsgBase( @@ -204,10 +194,12 @@ func packSubChannelRequest( task *ChannelTask, action Action, schema *schemapb.CollectionSchema, + collectionProperties []*commonpb.KeyValuePair, loadMeta *querypb.LoadMetaInfo, channel *meta.DmChannel, indexInfo []*indexpb.IndexInfo, ) *querypb.WatchDmChannelsRequest { + schema = applyCollectionMmapSetting(schema, collectionProperties) return &querypb.WatchDmChannelsRequest{ Base: commonpbutil.NewMsgBase( commonpbutil.WithMsgType(commonpb.MsgType_WatchDmChannels), @@ -265,3 +257,23 @@ func packUnsubDmChannelRequest(task *ChannelTask, action Action) *querypb.UnsubD ChannelName: task.Channel(), } } + +func applyCollectionMmapSetting(schema *schemapb.CollectionSchema, + collectionProperties []*commonpb.KeyValuePair, +) *schemapb.CollectionSchema { + schema = typeutil.Clone(schema) + schema.Properties = mergeCollectionProps(schema.Properties, collectionProperties) + // field mmap enabled if collection-level mmap enabled or the field mmap enabled + collectionMmapEnabled, exist := common.IsMmapDataEnabled(collectionProperties...) + for _, field := range schema.GetFields() { + if exist && + // field-level mmap setting has higher priority than collection-level mmap setting, skip if field-level mmap enabled + !common.FieldHasMmapKey(schema, field.GetFieldID()) { + field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{ + Key: common.MmapEnabledKey, + Value: strconv.FormatBool(collectionMmapEnabled), + }) + } + } + return schema +}