func findSolrNodeContents()

in controllers/util/solr_update_util.go [401:488]


func findSolrNodeContents(cluster solr_api.SolrClusterStatus, overseerLeader string, managedSolrNodeNames map[string]bool) (state NodeReplicaState) {
	state.NodeContents = make(map[string]*SolrNodeContents, 0)
	state.TotalShardReplicas = make(map[string]int, 0)
	state.ShardReplicasNotActive = make(map[string]int, 0)
	// Update the info for each "live" node.
	for _, nodeName := range cluster.LiveNodes {
		contents, hasValue := state.NodeContents[nodeName]
		delete(managedSolrNodeNames, nodeName)
		if !hasValue {
			contents = &SolrNodeContents{
				nodeName:               nodeName,
				leaders:                0,
				replicas:               0,
				totalReplicasPerShard:  map[string]int{},
				activeReplicasPerShard: map[string]int{},
				downReplicasPerShard:   map[string]int{},
				overseerLeader:         false,
				live:                   true,
			}
		} else {
			contents.live = true
		}
		state.NodeContents[nodeName] = contents
	}
	// Go through the state of each collection getting the count of replicas for each collection/shard living on each node
	for collectionName, collection := range cluster.Collections {
		for shardName, shard := range collection.Shards {
			uniqueShard := collectionName + "|" + shardName
			state.TotalShardReplicas[uniqueShard] = len(shard.Replicas)
			for _, replica := range shard.Replicas {
				contents, hasValue := state.NodeContents[replica.NodeName]
				if !hasValue {
					contents = &SolrNodeContents{
						nodeName:               replica.NodeName,
						leaders:                0,
						replicas:               0,
						totalReplicasPerShard:  map[string]int{},
						activeReplicasPerShard: map[string]int{},
						downReplicasPerShard:   map[string]int{},
						overseerLeader:         false,
						live:                   false,
					}
				}
				if replica.Leader {
					contents.leaders += 1
				}
				contents.replicas += 1
				contents.totalReplicasPerShard[uniqueShard] += 1

				// A replica can be considered "not active" if it's state is not "active" or the node it lives in is not "live".
				if !(replica.State == solr_api.ReplicaActive && contents.live) {
					state.ShardReplicasNotActive[uniqueShard] += 1
				}
				if replica.State == solr_api.ReplicaActive {
					contents.activeReplicasPerShard[uniqueShard] += 1
				}
				// Keep track of how many of the replicas of this shard are in a down state (down or recovery_failed)
				if replica.State == solr_api.ReplicaDown || replica.State == solr_api.ReplicaRecoveryFailed {
					contents.downReplicasPerShard[uniqueShard] += 1
				} else {
					contents.notDownReplicas += 1
				}

				state.NodeContents[replica.NodeName] = contents
			}
		}
	}
	// Update the info for the overseerLeader leader.
	if overseerLeader != "" {
		contents, hasValue := state.NodeContents[overseerLeader]
		if !hasValue {
			contents = &SolrNodeContents{
				nodeName:               overseerLeader,
				leaders:                0,
				totalReplicasPerShard:  map[string]int{},
				activeReplicasPerShard: map[string]int{},
				downReplicasPerShard:   map[string]int{},
				overseerLeader:         true,
				live:                   false,
			}
		} else {
			contents.overseerLeader = true
		}
		state.NodeContents[overseerLeader] = contents
	}
	state.AllManagedPodsLive = len(managedSolrNodeNames) == 0
	return state
}