Fix return too many nodeIDs (#23397)

See also: #23396

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
This commit is contained in:
XuanYang-cn 2023-04-20 13:50:31 +08:00 committed by GitHub
parent 4a6c2b78a7
commit d56771b7b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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)
}

View File

@ -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