Skip to content

Commit

Permalink
enhance: Utilize coll2replica mapping when getting rg by collection (m…
Browse files Browse the repository at this point in the history
…ilvus-io#32892)

See also milvus-io#32165

In old `GetResourceGroupByCollection` implementation, it iterates all
replicas to match collection id, which is slow and CPU time consuming.
This PR make it utilize the coll2Replicas mapping by calling
`GetByCollection` and mapping replicas into resource group.

Signed-off-by: Congqi Xia <[email protected]>

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored and David Pichler committed May 10, 2024
1 parent 707d563 commit a63c2f3
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions internal/querycoordv2/meta/replica_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sync"

"github.com/cockroachdb/errors"
"github.com/samber/lo"
"go.uber.org/zap"

"github.com/milvus-io/milvus/internal/metastore"
Expand Down Expand Up @@ -406,15 +407,7 @@ func (m *ReplicaManager) RemoveNode(replicaID typeutil.UniqueID, nodes ...typeut
}

func (m *ReplicaManager) GetResourceGroupByCollection(collection typeutil.UniqueID) typeutil.Set[string] {
m.rwmutex.Lock()
defer m.rwmutex.Unlock()

ret := typeutil.NewSet[string]()
for _, r := range m.replicas {
if r.GetCollectionID() == collection {
ret.Insert(r.GetResourceGroup())
}
}

replicas := m.GetByCollection(collection)
ret := typeutil.NewSet(lo.Map(replicas, func(r *Replica, _ int) string { return r.GetResourceGroup() })...)
return ret
}

0 comments on commit a63c2f3

Please sign in to comment.