From f2a2fd68081e680c3a4003fe8adcbe2f80a2b4bb Mon Sep 17 00:00:00 2001 From: Chun Han <116052805+MrPresent-Han@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:06:32 -0500 Subject: [PATCH] enhance: shallow copy search request for large nq cases(#37732) (#37749) related: #37732 Signed-off-by: MrPresent-Han Co-authored-by: MrPresent-Han --- internal/querynodev2/delegator/delegator.go | 47 ++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/internal/querynodev2/delegator/delegator.go b/internal/querynodev2/delegator/delegator.go index 7a75a14679..01e6f70c53 100644 --- a/internal/querynodev2/delegator/delegator.go +++ b/internal/querynodev2/delegator/delegator.go @@ -213,12 +213,49 @@ func (sd *shardDelegator) GetPartitionStatsVersions(ctx context.Context) map[int return partStatMap } +func (sd *shardDelegator) shallowCopySearchRequest(req *internalpb.SearchRequest, targetID int64) *internalpb.SearchRequest { + // Create a new SearchRequest with the same fields + nodeReq := &internalpb.SearchRequest{ + Base: &commonpb.MsgBase{TargetID: targetID}, + ReqID: req.ReqID, + DbID: req.DbID, + CollectionID: req.CollectionID, + PartitionIDs: req.PartitionIDs, // Shallow copy: Same underlying slice + Dsl: req.Dsl, + PlaceholderGroup: req.PlaceholderGroup, // Shallow copy: Same underlying byte slice + DslType: req.DslType, + SerializedExprPlan: req.SerializedExprPlan, // Shallow copy: Same underlying byte slice + OutputFieldsId: req.OutputFieldsId, // Shallow copy: Same underlying slice + MvccTimestamp: req.MvccTimestamp, + GuaranteeTimestamp: req.GuaranteeTimestamp, + TimeoutTimestamp: req.TimeoutTimestamp, + Nq: req.Nq, + Topk: req.Topk, + MetricType: req.MetricType, + IgnoreGrowing: req.IgnoreGrowing, + Username: req.Username, + SubReqs: req.SubReqs, // Shallow copy: Same underlying slice of pointers + IsAdvanced: req.IsAdvanced, + Offset: req.Offset, + ConsistencyLevel: req.ConsistencyLevel, + GroupByFieldId: req.GroupByFieldId, + GroupSize: req.GroupSize, + FieldId: req.FieldId, + IsTopkReduce: req.IsTopkReduce, + } + + return nodeReq +} + func (sd *shardDelegator) modifySearchRequest(req *querypb.SearchRequest, scope querypb.DataScope, segmentIDs []int64, targetID int64) *querypb.SearchRequest { - nodeReq := proto.Clone(req).(*querypb.SearchRequest) - nodeReq.Scope = scope - nodeReq.Req.Base.TargetID = targetID - nodeReq.SegmentIDs = segmentIDs - nodeReq.DmlChannels = []string{sd.vchannelName} + nodeReq := &querypb.SearchRequest{ + DmlChannels: []string{sd.vchannelName}, + SegmentIDs: segmentIDs, + Scope: scope, + Req: sd.shallowCopySearchRequest(req.GetReq(), targetID), + FromShardLeader: req.FromShardLeader, + TotalChannelNum: req.TotalChannelNum, + } return nodeReq }