Skip to content

Commit

Permalink
MB-41109 Use topologyMap to reduce iterations across localMeta.Topolo…
Browse files Browse the repository at this point in the history
…gies

Change-Id: I1a264432d05399dc28fa9383b9d4f5d38b739bce
  • Loading branch information
varunv-cb committed Sep 2, 2020
1 parent 20feea2 commit b2b76a5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions secondary/manager/request_handler.go
Expand Up @@ -533,6 +533,22 @@ func (m *requestHandlerContext) getIndexStatus(creds cbauth.Creds, t *target, ge
defnToHostMap[defnId] = append(defnToHostMap[defnId], hostAddr)
}

buildTopologyMapPerCollection := func(topologies []IndexTopology) map[string]map[string]map[string]*IndexTopology {
topoMap := make(map[string]map[string]map[string]*IndexTopology)
for _, topology := range topologies {
t := &topology
t.SetCollectionDefaults()
if _, ok := topoMap[t.Bucket]; !ok {
topoMap[t.Bucket] = make(map[string]map[string]*IndexTopology)
}
if _, ok := topoMap[t.Bucket][t.Scope]; !ok {
topoMap[t.Bucket][t.Scope] = make(map[string]*IndexTopology)
}
topoMap[t.Bucket][t.Scope][t.Collection] = t
}
return topoMap
}

for _, nid := range nids {

mgmtAddr, err := cinfo.GetServiceAddress(nid, "mgmt")
Expand Down Expand Up @@ -562,6 +578,7 @@ func (m *requestHandlerContext) getIndexStatus(creds cbauth.Creds, t *target, ge
continue
}

topoMap := buildTopologyMapPerCollection(localMeta.IndexTopologies)
if !latest {
stale = true
} else {
Expand Down Expand Up @@ -596,8 +613,7 @@ func (m *requestHandlerContext) getIndexStatus(creds cbauth.Creds, t *target, ge

mergeCounter(defn.DefnId, defn.NumReplica2)

if topology := findTopologyByCollection(localMeta.IndexTopologies,
defn.Bucket, defn.Scope, defn.Collection); topology != nil {
if topology, ok := topoMap[defn.Bucket][defn.Scope][defn.Collection]; ok && topology != nil {

instances := topology.GetIndexInstancesByDefn(defn.DefnId)
for _, instance := range instances {
Expand Down

0 comments on commit b2b76a5

Please sign in to comment.