enhance: speed up GetByCollectionAndNode (#32232)

Related to https://github.com/milvus-io/milvus/issues/32165

Avoid iterating through all replicas/collections if possible. Iteration
is expensive when there are large number of replicas/collections.

Signed-off-by: yiwangdr <yiwangdr@gmail.com>
This commit is contained in:
yiwangdr 2024-04-16 19:23:25 -07:00 committed by GitHub
parent f0f2f11189
commit 7deda4d5e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -241,9 +241,12 @@ func (m *ReplicaManager) GetByCollectionAndNode(collectionID, nodeID typeutil.Un
m.rwmutex.RLock()
defer m.rwmutex.RUnlock()
for _, replica := range m.replicas {
if replica.GetCollectionID() == collectionID && replica.Contains(nodeID) {
return replica
if m.collIDToReplicaIDs[collectionID] != nil {
for replicaID := range m.collIDToReplicaIDs[collectionID] {
replica := m.replicas[replicaID]
if replica.Contains(nodeID) {
return replica
}
}
}