From d56771b7b786e8b454a2848b1a53d9a4e815b497 Mon Sep 17 00:00:00 2001 From: XuanYang-cn Date: Thu, 20 Apr 2023 13:50:31 +0800 Subject: [PATCH] Fix return too many nodeIDs (#23397) See also: #23396 Signed-off-by: yangxuan --- internal/querycoordv2/handlers.go | 5 +++-- internal/querycoordv2/services_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/querycoordv2/handlers.go b/internal/querycoordv2/handlers.go index 1991fa2117..5e0fa55088 100644 --- a/internal/querycoordv2/handlers.go +++ b/internal/querycoordv2/handlers.go @@ -311,10 +311,10 @@ func (s *Server) tryGetNodesMetrics(ctx context.Context, req *milvuspb.GetMetric } func (s *Server) fillReplicaInfo(replica *meta.Replica, withShardNodes bool) (*milvuspb.ReplicaInfo, error) { + nodeIDs := typeutil.NewUniqueSet(replica.GetNodes()...) info := &milvuspb.ReplicaInfo{ ReplicaID: replica.GetID(), CollectionID: replica.GetCollectionID(), - NodeIds: replica.GetNodes(), ResourceGroupName: replica.GetResourceGroup(), NumOutboundNode: s.meta.GetOutgoingNodeNumByReplica(replica), } @@ -355,7 +355,8 @@ func (s *Server) fillReplicaInfo(replica *meta.Replica, withShardNodes bool) (*m } return 0, false }) - shard.NodeIds = append(shard.NodeIds, shardNodes...) + nodeIDs.Insert(shardNodes...) + shard.NodeIds = nodeIDs.Collect() } info.ShardReplicas = append(info.ShardReplicas, shard) } diff --git a/internal/querycoordv2/services_test.go b/internal/querycoordv2/services_test.go index 7c15a20bda..2c79b7699a 100644 --- a/internal/querycoordv2/services_test.go +++ b/internal/querycoordv2/services_test.go @@ -1373,6 +1373,15 @@ func (suite *ServiceSuite) TestGetReplicas() { suite.NoError(err) suite.Equal(commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode()) suite.EqualValues(suite.replicaNumber[collection], len(resp.Replicas)) + + // Test no dup nodeIDs in shardReplica + for _, replica := range resp.GetReplicas() { + suite.Equal(collection, replica.CollectionID) + for _, shardReplica := range replica.GetShardReplicas() { + gotNodeIDsSet := typeutil.NewUniqueSet(shardReplica.GetNodeIds()...) + suite.Equal(len(shardReplica.GetNodeIds()), gotNodeIDsSet.Len()) + } + } } // Test when server is not healthy