void RoundRobinHostSelector::create_cache_entries()

in src/host_selector/round_robin_host_selector.cc [133:162]


void RoundRobinHostSelector::create_cache_entries(const std::vector<HostInfo>& hosts,
    const std::unordered_map<std::string, std::string>& props) {

    std::vector<HostInfo> hosts_with_cached_entry;
    hosts_with_cached_entry.reserve(round_robin_cache.Size());
    std::copy_if(hosts.begin(), hosts.end(), std::back_inserter(hosts_with_cached_entry), [this](const HostInfo& host) {
        return RoundRobinHostSelector::round_robin_cache.Find(host.GetHost());
    });

    // Update cache entries, else create new cache
    if (hosts_with_cached_entry.empty()) {
        std::shared_ptr<round_robin_property::RoundRobinClusterInfo> cluster_info = std::make_shared<round_robin_property::RoundRobinClusterInfo>();
        update_props_default_weight(cluster_info, props);
        update_props_host_weight(cluster_info, props);
        update_cache(hosts, cluster_info);
    } else {        
        std::string cluster_id_key = hosts_with_cached_entry.at(0).GetHost();
        std::shared_ptr<round_robin_property::RoundRobinClusterInfo> cluster_info = round_robin_cache.Get(cluster_id_key);
        if (check_prop_change(cluster_info->last_default_weight_str, round_robin_property::DEFAULT_WEIGHT_KEY, props)) {
            cluster_info->default_weight = 1;
            update_props_default_weight(cluster_info, props);
        }
        if (check_prop_change(cluster_info->last_host_weight_str, round_robin_property::HOST_WEIGHT_KEY, props)) {
            cluster_info->last_host = nullptr;
            cluster_info->weigth_counter = 0;
            update_props_host_weight(cluster_info, props);
        }
        update_cache(hosts, cluster_info);
    }
};