From 663ec6f8226ababadfe61e4a50113401b241ee02 Mon Sep 17 00:00:00 2001 From: "yihao.dai" Date: Thu, 2 Jan 2025 20:54:47 +0800 Subject: [PATCH] enhance: [10kcp] Reducing the granularity of locks in the target manager (#38956) pr: https://github.com/milvus-io/milvus/pull/38566 Just for test, I'll remove the global mutex latter. Signed-off-by: bigsheeper --- internal/querycoordv2/meta/target_manager.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/querycoordv2/meta/target_manager.go b/internal/querycoordv2/meta/target_manager.go index 44ebef21afa1b..062a8758b22ab 100644 --- a/internal/querycoordv2/meta/target_manager.go +++ b/internal/querycoordv2/meta/target_manager.go @@ -152,8 +152,6 @@ func (mgr *TargetManager) UpdateCollectionNextTarget(collectionID int64) error { return err } - mgr.rwMutex.Lock() - defer mgr.rwMutex.Unlock() partitions := mgr.meta.GetPartitionsByCollection(collectionID) partitionIDs := lo.Map(partitions, func(partition *Partition, i int) int64 { return partition.PartitionID @@ -183,7 +181,7 @@ func (mgr *TargetManager) UpdateCollectionNextTarget(collectionID int64) error { } for _, infos := range channelInfos { - merged := mgr.mergeDmChannelInfo(infos) + merged := mergeDmChannelInfo(infos) dmChannels[merged.GetChannelName()] = merged } @@ -193,7 +191,11 @@ func (mgr *TargetManager) UpdateCollectionNextTarget(collectionID int64) error { } allocatedTarget := NewCollectionTarget(segments, dmChannels, partitionIDs) + + mgr.rwMutex.Lock() mgr.next.updateCollectionTarget(collectionID, allocatedTarget) + mgr.rwMutex.Unlock() + log.Debug("finish to update next targets for collection", zap.Int64("collectionID", collectionID), zap.Int64s("PartitionIDs", partitionIDs)) @@ -201,7 +203,7 @@ func (mgr *TargetManager) UpdateCollectionNextTarget(collectionID int64) error { return nil } -func (mgr *TargetManager) mergeDmChannelInfo(infos []*datapb.VchannelInfo) *DmChannel { +func mergeDmChannelInfo(infos []*datapb.VchannelInfo) *DmChannel { var dmChannel *DmChannel for _, info := range infos {