void DCAwarePolicy::on_remove(const SharedRefPtr<Host>& host) { const std::string& dc = host->dc(); if (dc == local_dc_) { remove_host(local_dc_live_hosts_, host); } else { per_remote_dc_live_hosts_.remove_host_from_dc(host->dc(), host); } }
void DCAwarePolicy::init(const SharedRefPtr<Host>& connected_host, const HostMap& hosts) { if (local_dc_.empty() && !connected_host->dc().empty()) { LOG_INFO("Using '%s' for the local data center " "(if this is incorrect, please provide the correct data center)", connected_host->dc().c_str()); local_dc_ = connected_host->dc(); } for (HostMap::const_iterator i = hosts.begin(), end = hosts.end(); i != end; ++i) { on_add(i->second); } }
void DCAwarePolicy::on_add(const SharedRefPtr<Host>& host) { const std::string& dc = host->dc(); if (local_dc_.empty() && !dc.empty()) { LOG_INFO("Using '%s' for local data center " "(if this is incorrect, please provide the correct data center)", host->dc().c_str()); local_dc_ = dc; } if (dc == local_dc_) { local_dc_live_hosts_->push_back(host); } else { per_remote_dc_live_hosts_.add_host_to_dc(dc, host); } }
CassHostDistance DCAwarePolicy::distance(const SharedRefPtr<Host>& host) const { if (local_dc_.empty() || host->dc() == local_dc_) { return CASS_HOST_DISTANCE_LOCAL; } const CopyOnWriteHostVec& hosts = per_remote_dc_live_hosts_.get_hosts(host->dc()); size_t num_hosts = std::min(hosts->size(), used_hosts_per_remote_dc_); for (size_t i = 0; i < num_hosts; ++i) { if ((*hosts)[i]->address() == host->address()) { return CASS_HOST_DISTANCE_REMOTE; } } return CASS_HOST_DISTANCE_IGNORE; }
bool BlacklistDCPolicy::is_valid_host(const SharedRefPtr<Host>& host) const { const std::string& host_dc = host->dc(); for (DcList::const_iterator it = dcs_.begin(), end = dcs_.end(); it != end; ++it) { if (host_dc.compare(*it) == 0) { return false; } } return true; }