Пример #1
0
void Session::on_remove(SharedRefPtr<Host> host) {
  load_balancing_policy_->on_remove(host);
  { // Lock hosts
    ScopedMutex l(&hosts_mutex_);
    hosts_.erase(host->address());
  }
  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->remove_pool_async(host->address(), true);
  }
}
Пример #2
0
bool BlacklistPolicy::is_valid_host(const SharedRefPtr<Host>& host) const {
  const std::string& host_address = host->address().to_string(false);
  for (ContactPointList::const_iterator it = hosts_.begin(),
                                                end = hosts_.end();
       it != end; ++it) {
    if (host_address.compare(*it) == 0) {
      return false;
    }
  }
  return true;
}
Пример #3
0
void Session::on_up(SharedRefPtr<Host> host) {
  host->set_up();

  if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
    return;
  }

  load_balancing_policy_->on_up(host);

  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->add_pool_async(host->address(), false);
  }
}
Пример #4
0
void Session::on_down(SharedRefPtr<Host> host) {
  host->set_down();
  load_balancing_policy_->on_down(host);

  bool cancel_reconnect = false;
  if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
    // This permanently removes a host from all IO workers by stopping
    // any attempt to reconnect to that host.
    cancel_reconnect = true;
  }
  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->remove_pool_async(host->address(), cancel_reconnect);
  }
}
Пример #5
0
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;
}
Пример #6
0
void Session::on_add(SharedRefPtr<Host> host, bool is_initial_connection) {
  host->set_up();

  if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
    return;
  }

  if (is_initial_connection) {
    pending_pool_count_ += io_workers_.size();
  } else {
    load_balancing_policy_->on_add(host);
  }

  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->add_pool_async(host->address(), is_initial_connection);
  }
}
Пример #7
0
SharedRefPtr<Host> TokenAwarePolicy::TokenAwareQueryPlan::compute_next()  {
  while (remaining_ > 0) {
    --remaining_;
    const SharedRefPtr<Host>& host((*replicas_)[index_++ % replicas_->size()]);
    if (host->is_up() && child_policy_->distance(host) == CASS_HOST_DISTANCE_LOCAL) {
      return host;
    }
  }

  SharedRefPtr<Host> host;
  while ((host = child_plan_->compute_next())) {
    if (!contains(replicas_, host->address()) ||
        child_policy_->distance(host) != CASS_HOST_DISTANCE_LOCAL) {
      return host;
    }
  }
  return SharedRefPtr<Host>();
}
Пример #8
0
void HostTargetingPolicy::on_down(const SharedRefPtr<Host>& host) {
  available_hosts_.erase(host->address());
  ChainedLoadBalancingPolicy::on_down(host);
}
Пример #9
0
void HostTargetingPolicy::on_up(const SharedRefPtr<Host>& host) {
  available_hosts_[host->address()] = host;
  ChainedLoadBalancingPolicy::on_up(host);
}